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.
ScanPoliciesManager
(exclude_dir_regexes=(), exclude_file_regexes=(), include_file_regexes=(), exclude_all_symlinks=False)[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 directeries.
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)[source]¶
-
should_exclude_file
(file_path)[source]¶ Given the full path of a file, decide if it should be excluded from the scan.
-
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.
-