barman.fs module#

class barman.fs.LocalLibPathDeletionCommand(path)View on GitHub#

Bases: PathDeletionCommand

__init__(path)View on GitHub#
Parameters:

path – str

_abc_impl = <_abc._abc_data object>#
delete()View on GitHub#

Will delete the actual path

class barman.fs.PathDeletionCommandView on GitHub#

Bases: object

Stand-alone object that will execute delete operation on a self contained path

_abc_impl = <_abc._abc_data object>#
abstract delete()View on GitHub#

Will delete the actual path

class barman.fs.UnixCommandPathDeletionCommand(path, unix_command)View on GitHub#

Bases: PathDeletionCommand

__init__(path, unix_command)View on GitHub#
Parameters:
  • path

  • UnixLocalCommand (unix_command)

_abc_impl = <_abc._abc_data object>#
delete()View on GitHub#

Will delete the actual path

class barman.fs.UnixLocalCommand(path=None)View on GitHub#

Bases: object

This class is a wrapper for local calls for file system operations

__init__(path=None)View on GitHub#
check_directory_exists(dir_path)View on GitHub#

Check for the existence of a directory in path. if the directory exists returns true. if the directory does not exists returns false. if exists a file and is not a directory raises an exception

:param dir_path full path for the directory

check_write_permission(dir_path)View on GitHub#

check write permission for barman on a given path. Creates a hidden file using touch, then remove the file. returns true if the file is written and removed without problems raise exception if the creation fails. raise exception if the removal fails.

:param dir_path full dir_path for the directory to check

cmd(cmd_name, args=[])View on GitHub#

Execute a command string, escaping it, if necessary

create_dir_if_not_exists(dir_path, mode=None)View on GitHub#

This method recursively creates a directory if not exists

If the path exists and is not a directory raise an exception.

Parameters:
  • dir_path (str) – full path for the directory

  • str|None (mode) – Specify the mode to use for creation. Not used if the directory already exists.

Returns bool:

False if the directory already exists True if the directory is created.

Create a symlink pointing to src named dst. Check src exists, if so, checks that destination does not exists. if src is an invalid folder, raises an exception. if dst already exists, raises an exception. if ln -s command fails raises an exception

:param src full path to the source of the symlink :param dst full path for the destination of the symlink

delete_if_exists(path)View on GitHub#

This method check for the existence of a path. If it exists, then is removed using a rm -fr command, and returns True. If the command fails an exception is raised. If the path does not exists returns False

:param path the full path for the directory

exists(path, dereference=True)View on GitHub#

Check for the existence of a path.

Parameters:
  • path (str) – full path to check

  • dereference (bool) – whether dereference symlinks, defaults to True

Return bool:

if the file exists or not.

findmnt(device)View on GitHub#

Retrieve the mount point and mount options for the provided device.

Parameters:

device (str) – The device for which the mount point and options should be found.

Return type:

List[str|None, str|None]

Returns:

The mount point and the mount options of the specified device or [None, None] if the device could not be found by findmnt.

get_file_content(path)View on GitHub#

Retrieve the content of a file If the file doesn’t exist or isn’t readable, it raises an exception.

Parameters:

path (str) – full path to the file to read

get_file_mode(path)View on GitHub#

Should check that :param dir_path: :param mode: :return: mode

get_last_output()View on GitHub#

Return the output and the error strings from the last executed command

Return type:

tuple[str,str]

get_system_info()View on GitHub#

Gather important system information for ‘barman diagnose’ command

is_osx()View on GitHub#

Identify whether is is a Linux or Darwin system :return: True is it is osx os

list_dir_content(dir_path, options=[])View on GitHub#

List the contents of a given directory.

Parameters:
  • dir_path (str) – the path where we want the ls to be executed

  • options (list[str]) – a string containing the options for the ls command

Return str:

the ls cmd output

move(source_path, dest_path)View on GitHub#

Move a file from source_path to dest_path.

Parameters:
  • source_path (str) – full path to the source file.

  • dest_path (str) – full path to the destination file.

Returns bool:

True if the move completed successfully, False otherwise.

ping()View on GitHub#

‘Ping’ the server executing the true command.

Return int:

the true cmd result

validate_file_mode(path, mode)View on GitHub#

Validate the file or dir has the expected mode. Raises an exception otherwise. :param path: str :param mode: str (700, 750, …) :return:

class barman.fs.UnixRemoteCommand(ssh_command, ssh_options=None, path=None)View on GitHub#

Bases: UnixLocalCommand

This class is a wrapper for remote calls for file system operations

__init__(ssh_command, ssh_options=None, path=None)View on GitHub#

Uses the same commands as the UnixLocalCommand but the constructor is overridden and a remote shell is initialized using the ssh_command provided by the user

Parameters:
  • ssh_command (str) – the ssh command provided by the user

  • ssh_options (list[str]) – the options to be passed to SSH

  • path (str) – the path to be used if provided, otherwise the PATH environment variable will be used

barman.fs._match_path(rules, path, is_dir)View on GitHub#

Determine if a certain list of rules match a filesystem entry.

The rule-checking algorithm also handles rsync-like anchoring of rules prefixed with ‘/’. If the rule is not anchored then it match every file whose suffix matches the rule.

That means that a rule like ‘a/b’, will match ‘a/b’ and ‘x/a/b’ too. A rule like ‘/a/b’ will match ‘a/b’ but not ‘x/a/b’.

If a rule ends with a slash (i.e. ‘a/b/’) if will be used only if the passed path is a directory.

This function implements the basic wildcards. For more information about that, consult the documentation of the “translate_to_regexp” function.

Parameters:
  • rules (list[str]) – match

  • path – the path of the entity to match

  • is_dir – True if the entity is a directory

Return bool:

barman.fs._translate_to_regexp(pattern)View on GitHub#

Translate a shell PATTERN to a regular expression.

These wildcard characters you to use:

  • “?” to match every character

  • “*” to match zero or more characters, excluding “/”

  • “**” to match zero or more characters, including “/”

There is no way to quote meta-characters. This implementation is based on the one in the Python fnmatch module

Parameters:

pattern (str) – A string containing wildcards

barman.fs._wildcard_match_path(path, pattern)View on GitHub#

Check if the proposed shell pattern match the path passed.

Parameters:
Rtype bool:

True if it match, False otherwise

barman.fs.path_allowed(exclude, include, path, is_dir)View on GitHub#

Filter files based on include/exclude lists.

The rules are evaluated in steps:

  1. if there are include rules and the proposed path match them, it is immediately accepted.

  2. if there are exclude rules and the proposed path match them, it is immediately rejected.

  3. the path is accepted.

Look at the documentation for the “evaluate_path_matching_rules” function for more information about the syntax of the rules.

Parameters:
  • exclude (list[str]|None) – The list of rules composing the exclude list

  • include (list[str]|None) – The list of rules composing the include list

  • path (str) – The patch to patch

  • is_dir (bool) – True is the passed path is a directory

Return bool:

True is the patch is accepted, False otherwise

barman.fs.unix_command_factory(remote_command=None, path=None)View on GitHub#

Function in charge of instantiating a Unix Command.

Parameters:
  • remote_command

  • path

Returns:

UnixLocalCommand