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: Iterable[Union[str, re.Pattern]] = (), exclude_file_regexes: Iterable[Union[str, re.Pattern]] = (), include_file_regexes: Iterable[Union[str, re.Pattern]] = (), exclude_all_symlinks: bool = False, exclude_modified_before: Optional[int] = None, exclude_modified_after: Optional[int] = None, exclude_uploaded_before: Optional[int] = None, exclude_uploaded_after: Optional[int] = 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: Iterable[Union[str, re.Pattern]] = (), exclude_file_regexes: Iterable[Union[str, re.Pattern]] = (), include_file_regexes: Iterable[Union[str, re.Pattern]] = (), exclude_all_symlinks: bool = False, exclude_modified_before: Optional[int] = None, exclude_modified_after: Optional[int] = None, exclude_uploaded_before: Optional[int] = None, exclude_uploaded_after: Optional[int] = None)[source]
- Parameters
exclude_dir_regexes – regexes to exclude directories
exclude_file_regexes – regexes to exclude files
include_file_regexes – regexes to include files
exclude_all_symlinks – if True, exclude all symlinks
exclude_modified_before – optionally exclude file versions (both local and b2) modified before (in millis)
exclude_modified_after – optionally exclude file versions (both local and b2) modified after (in millis)
exclude_uploaded_before – optionally exclude b2 file versions uploaded before (in millis)
exclude_uploaded_after – optionally exclude b2 file versions uploaded after (in millis)
The regex matching priority for a given path is: 1) the path is always excluded if it’s dir matches exclude_dir_regexes, if not then 2) the path is always included if it matches include_file_regexes, if not then 3) the path is excluded if it matches exclude_file_regexes, if not then 4) the path is included
- should_exclude_local_path(local_path: b2sdk.sync.path.LocalSyncPath)[source]
Whether a local path should be excluded from the Sync or not.
This method assumes that the directory holding the path_ has already been checked for exclusion.
- should_exclude_b2_file_version(file_version: b2sdk.file_version.FileVersion, relative_path: str)[source]
Whether a b2 file version should be excluded from the Sync or not.
This method assumes that the directory holding the path_ has already been checked for exclusion.