b2sdk.sync.scan_policies
¶
-
class
b2sdk.sync.scan_policies.
RegexSet
(regex_iterable)[source]¶ Bases:
object
Hold a (possibly empty) set of regular expressions and know how to check whether a string matches any of them.
-
b2sdk.sync.scan_policies.
convert_dir_regex_to_dir_prefix_regex
(dir_regex)[source]¶ The patterns used to match directory names (and file names) are allowed to match a prefix of the name. This ‘feature’ was unintentional, but is being retained for compatibility.
This means that a regex that matches a directory name can’t be used directly to match against a file name and test whether the file should be excluded because it matches the directory.
The pattern ‘photos’ will match directory names ‘photos’ and ‘photos2’, and should exclude files ‘photos/kitten.jpg’, and ‘photos2/puppy.jpg’. It should not exclude ‘photos.txt’, because there is no directory name that matches.
On the other hand, the pattern ‘photos$’ should match ‘photos/kitten.jpg’, but not ‘photos2/puppy.jpg’, nor ‘photos.txt’
If the original regex is valid, there are only two cases to consider: either the regex ends in ‘$’ or does not.
- Parameters
dir_regex (str) – a regular expression string or literal
-
class
b2sdk.sync.scan_policies.
IntegerRange
(begin, end)[source]¶ Bases:
object
Hold a range of two integers. If the range value is None, it indicates that the value should be treated as -Inf (for begin) or +Inf (for end).
-
class
b2sdk.sync.scan_policies.
ScanPoliciesManager
(exclude_dir_regexes=(), exclude_file_regexes=(), include_file_regexes=(), exclude_all_symlinks=False, exclude_modified_before=None, exclude_modified_after=None)[source]¶ Bases:
object
Policy object used when scanning folders for syncing, used to decide which files to include in the list of files to be synced.
Code that scans through files should at least use should_exclude_file() to decide whether each file should be included; it will check include/exclude patterns for file names, as well as patterns for excluding directories.
Code that scans may optionally use should_exclude_directory() to test whether it can skip a directory completely and not bother listing the files and sub-directories in it.
-
__init__
(exclude_dir_regexes=(), exclude_file_regexes=(), include_file_regexes=(), exclude_all_symlinks=False, exclude_modified_before=None, exclude_modified_after=None)[source]¶ - Parameters
exclude_dir_regexes (tuple) – a tuple of regexes to exclude directories
exclude_file_regexes (tuple) – a tuple of regexes to exclude files
include_file_regexes (tuple) – a tuple of regexes to include files
exclude_all_symlinks (bool) – if True, exclude all symlinks
exclude_modified_before (int, optional) – optionally exclude file versions modified before (in millis)
exclude_modified_after (int, optional) – optionally exclude file versions modified after (in millis)
-
should_exclude_file
(file_path)[source]¶ Given the full path of a file, decide if it should be excluded from the scan.
-
should_exclude_file_version
(file_version)[source]¶ Given the modification time of a file version, decide if it should be excluded from the scan.
- Parameters
file_version – the file version object
- Type
b2sdk.v1.FileVersion
- Returns
True if excluded.
- Return type
-
should_exclude_directory
(dir_path)[source]¶ Given the full path of a directory, decide if all of the files in it should be excluded from the scan.
- Parameters
dir_path (str) – the path of the directory, relative to the root directory being scanned. The path will never end in ‘/’.
- Returns
True if excluded.
-