def glob_get_normal_sf(self, glob_str, include): u"""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. """ assert isinstance(glob_str, str), \ u"The glob string " + glob_str.decode(sys.getfilesystemencoding(), u"ignore") + u" is not unicode" ignore_case = False if glob_str.lower().startswith(u"ignorecase:"): # Glob string starts with ignorecase, so remove that from the # string and change it to lowercase. glob_str = glob_str[len(u"ignorecase:"):].lower() ignore_case = True # Check to make sure prefix is ok, i.e. the glob string is within # the root folder being backed up file_prefix_selection = select_fn_from_glob(glob_str, include=1)(self.rootpath) if not file_prefix_selection: # file_prefix_selection == 1 (include) or 2 (scan) raise FilePrefixError(glob_str) return select_fn_from_glob(glob_str, include, ignore_case)
def glob_get_normal_sf(self, glob_str, include): u"""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. """ assert isinstance(glob_str, unicode), \ u"The glob string " + glob_str.decode(sys.getfilesystemencoding(), u"ignore") + u" is not unicode" ignore_case = False if glob_str.lower().startswith(u"ignorecase:"): # Glob string starts with ignorecase, so remove that from the # string and change it to lowercase. glob_str = glob_str[len(u"ignorecase:"):].lower() ignore_case = True # Check to make sure prefix is ok, i.e. the glob string is within # the root folder being backed up file_prefix_selection = select_fn_from_glob(glob_str, include=1)(self.rootpath) if not file_prefix_selection: # file_prefix_selection == 1 (include) or 2 (scan) raise FilePrefixError(glob_str + u" glob with " + self.rootpath.uc_name + u" path gives " + unicode(file_prefix_selection)) return select_fn_from_glob(glob_str, include, ignore_case)