def list(self, include=None, exclude=None, recursive=False, visitors=None, # pysvn.list() only #peg_revision=pysvn.Revision( pysvn.opt_revision_kind.unspecified ), #revision=pysvn.Revision( pysvn.opt_revision_kind.head ), #dirent_fields=pysvn.SVN_DIRENT_ALL, # pysvn.dirent_fields #fetch_locks=False, # depth=None # depth is one of the pysvn.depth enums. **kwargs): peg_revision=None revision=None dirent_fields=None fetch_locks=False # TODO enable these commented arguments # pysvn.Client.list() "Returns a list with a tuple of information for each file in the given path at the provided revision." try: entries_list = self.client.list( self.path, #peg_revision=peg_revision, #revision=revision, recurse=recursive) #dirent_fields=dirent_fields, #fetch_locks=fetch_locks ) #depth=depth ) except Exception as e: log.error('Could not list SVN repository contents.') log.info('Possible solutions:') log.info(' - If behind a proxy, set environment variable') log.info(' HTTP_PROXY=http://USERNAME:PASSWORD@HOST:PORT') raise e # Compile filter patterns (include_patterns, exclude_patterns) = base.compile_filters(include, exclude) # Iterate over entries_list and apply include and exclude root_url = self.client.root_url_from_path( url_or_path=self.path ) accepted_paths = [] for (pysvn_list, pysvn_lock) in entries_list: abs_path = root_url + pysvn_list.repos_path # os.path.relpath seems to work on URLs rel_path = os.path.relpath(abs_path, start=root_url) path = SvnPath(abs_path) path['abs_path'] = abs_path path['rel_path'] = rel_path # SVN only path['repos_path'] = pysvn_list.repos_path # Apply filter(s) if base.accept_path(path, include_patterns, exclude_patterns): accepted_paths.append(path) return accepted_paths
def list(self, include=['.*'], exclude=[], visitors=[], recursive=True, files=True, dirs=True, **visitor_kwargs): """ TODO What if self.path is a file? Arguments --------- files: include files in list? dirs: include dirs in list? include: regular expression(s) indicating which paths to include exclude: regular expression(s) indicating which paths to exclude. Overrides include. visitors: list of callables to apply to each path that will be returned. **visitor_kwargs: kwargs passed directly to visitors """ # Pull in defaults if visitors and not len(visitors): visitors = self.visitors log.debug('Visitors: {}'.format(visitors)) (include_patterns, exclude_patterns) = base.compile_filters(include, exclude) """ # Make lists of include and exclude patterns include_patterns = [] exclude_patterns = [] if type(include) == str: include = [include] for include_regex in include: # HACK Windows compatability include_regex = include_regex.replace('/', r'[\\/]') include_patterns.append(re.compile(include_regex)) if type(exclude) == str: exclude = [exclude] for exclude_regex in exclude: # HACK Windows compatability exclude_regex = exclude_regex.replace('/', r'[\\/]') exclude_patterns.append(re.compile(exclude_regex)) log.debug('Include regexes: {}'.format(include)) log.debug('Exclude regexes: {}'.format(exclude)) """ # Decide which path generator to use if os.path.isfile(self.path): path_generator = echo_path_generator elif recursive: path_generator = os_walk_path_generator else: path_generator = os_listdir_path_generator for path in path_generator(self.path, files=files, dirs=dirs): filename = os.path.basename(path) abs_path = os.path.abspath(path) rel_path = os.path.relpath(abs_path, start=self.path) abs_dirpath = os.path.dirname(abs_path) # Apply filter(s) if not base.accept_path(path, include_patterns, exclude_patterns): continue """ if not include_patterns or not len(include_patterns) or len([True for p in include_patterns if p.search(rel_path)]): # An include regex matched relative path log.debug('Including path: {}'.format(path)) else: # log.debug('Skipping path: {}'.format(path)) continue if len([True for p in exclude_patterns if p.search(rel_path)]): # An exclude regex matched relative path, so don't yield file log.debug('Excluding path: {}'.format(path)) continue """ file_dict = path.Path(path=path, root=self, filename=filename, abs_dirpath=abs_dirpath, abs_path=abs_path, rel_path=rel_path) # Possibly apply visitors for visitor in visitors: kwargs = dict() kwargs.update(file_dict) kwargs.update(visitor_kwargs) file_dict.update(visitor(**kwargs)) yield file_dict