duplicity.selection module¶
-
class
duplicity.selection.
Select
(path)[source]¶ Iterate appropriate Paths in given directory
This class acts as an iterator on account of its next() method. Basically, it just goes through all the files in a directory in order (depth-first) and subjects each file to a bunch of tests (selection functions) in order. The first test that includes or excludes the file means that the file gets included (iterated) or excluded. The default is include, so with no tests we would just iterate all the files in the directory in order.
The one complication to this is that sometimes we don’t know whether or not to include a directory until we examine its contents. For instance, if we want to include all the **.py files. If /home/ben/foo.py exists, we should also include /home and /home/ben, but if these directories contain no **.py files, they shouldn’t be included. For this reason, a test may not include or exclude a directory, but merely “scan” it. If later a file in the directory gets included, so does the directory.
As mentioned above, each test takes the form of a selection function. The selection function takes a path, and returns:
None - means the test has nothing to say about the related file 0 - the file is excluded by the test 1 - the file is included 2 - the test says the file (must be directory) should be scanned
Also, a selection function f has a variable f.exclude which should be true iff f could potentially exclude some file. This is used to signal an error if the last function only includes, which would be redundant and presumably isn’t what the user intends.
-
Iterate
(path)[source]¶ Return iterator yielding paths in path
This function looks a bit more complicated than it needs to be because it avoids extra recursion (and no extra function calls for non-directory files) while still doing the “directory scanning” bit.
-
ParseArgs
(argtuples, filelists)[source]¶ Create selection functions based on list of tuples
The tuples are created when the initial commandline arguments are read. They have the form (option string, additional argument) except for the filelist tuples, which should be (option-string, (additional argument, filelist_fp)).
-
add_selection_func
(sel_func, add_to_start=None)[source]¶ Add another selection function at the end or beginning
-
exclude_older_get_sf
(date)[source]¶ Return selection function based on files older than modification date
-
filelist_globbing_get_sfs
(filelist_fp, inc_default, list_name)[source]¶ Return list of selection functions by reading fileobj
filelist_fp should be an open file object inc_default is true iff this is an include list list_name is just the name of the list, used for logging See the man page on –[include/exclude]-globbing-filelist
-
filelist_sanitise_line
(line, include_default)[source]¶ Sanitises lines of both normal and globbing filelists, returning (line, include) and line=None if blank/comment
The aim is to parse filelists in a consistent way, prior to the interpretation of globbing statements. The function removes whitespace, comment lines and processes modifiers (leading +/-) and quotes.
-
glob_get_normal_sf
(glob_str, include)[source]¶ Return selection function based on glob_str
The basic idea is to turn glob_str into a regular expression, and just use the normal regular expression. There is a complication because the selection function should return ‘2’ (scan) for directories which may contain a file which matches the glob_str. So we break up the glob string into parts, and any file which matches an initial sequence of glob parts gets scanned.
Thanks to Donovan Baarda who provided some code which did some things similar to this.
-
glob_re
= <_sre.SRE_Pattern object>¶
-
other_filesystems_get_sf
(include)[source]¶ Return selection function matching files on other filesystems
-