def collect_directories(self, directories): """ Collects all the directories into a `set` object. If `self.recursive` is set to `True` this method will iterate through and return all of the directories and the subdirectories found from `directories` that are not blacklisted. if `self.recursive` is set to `False` this will return all the directories that are not balcklisted. `directories` may be either a single object or an iterable. Recommend passing in absolute paths instead of relative. `collect_directories` will attempt to convert `directories` to absolute paths if they are not already. """ directories = util.to_absolute_paths(directories) if not self.recursive: return self._remove_blacklisted(directories) recursive_dirs = set() for dir_ in directories: walk_iter = os.walk(dir_, followlinks=True) walk_iter = [w[0] for w in walk_iter] walk_iter = util.to_absolute_paths(walk_iter) walk_iter = self._remove_blacklisted(walk_iter) recursive_dirs.update(walk_iter) return recursive_dirs
def remove_blacklisted_filepaths(self, filepaths): """ Removes `filepaths` from blacklisted filepaths Recommend passing in absolute filepaths but method will attempt to convert to absolute filepaths based on current working directory. """ filepaths = util.to_absolute_paths(filepaths) black_paths = self.blacklisted_filepaths black_paths = util.remove_from_set(black_paths, filepaths)
def remove_plugin_filepaths(self, filepaths): """ Removes `filepaths` from `self.plugin_filepaths`. Recommend passing in absolute filepaths. Method will attempt to convert to absolute paths if not passed in. `filepaths` can be a single object or an iterable. """ filepaths = util.to_absolute_paths(filepaths) self.plugin_filepaths = util.remove_from_set(self.plugin_filepaths, filepaths)
def _remove_blacklisted(self, directories): """ Attempts to remove the blacklisted directories from `directories` and then returns whatever is left in the set. Called from the `collect_directories` method. """ directories = util.to_absolute_paths(directories) directories = util.remove_from_set(directories, self.blacklisted_directories) return directories
def remove_blacklisted_directories(self, directories): """ Attempts to remove the `directories` from the set of blacklisted directories. If a particular directory is not found in the set of blacklisted, method will continue on silently. `directories` may be a single instance or an iterable. Recommend passing in absolute paths. Method will try to convert to an absolute path if it is not already using the current working directory. """ directories = util.to_absolute_paths(directories) black_dirs = self.blacklisted_directories black_dirs = util.remove_from_set(black_dirs, directories)
def remove_directories(self, directories): """ Removes any `directories` from the set of plugin directories. `directories` may be a single object or an iterable. Recommend passing in all paths as absolute, but the method will attemmpt to convert all paths to absolute if they are not already based on the current working directory. """ directories = util.to_absolute_paths(directories) self.plugin_directories = util.remove_from_set(self.plugin_directories, directories)
def set_blacklisted_filepaths(self, filepaths, remove_from_stored=True): """ Sets internal blacklisted filepaths to filepaths. If `remove_from_stored` is `True`, any `filepaths` in `self.plugin_filepaths` will be automatically removed. Recommend passing in absolute filepaths but method will attempt to convert to absolute filepaths based on current working directory. """ filepaths = util.to_absolute_paths(filepaths) self.blacklisted_filepaths = filepaths if remove_from_stored: self.plugin_filepaths = util.remove_from_set( self.plugin_filepaths, filepaths)
def set_blacklisted_filepaths(self, filepaths, remove_from_stored=True): """ Sets internal blacklisted filepaths to filepaths. If `remove_from_stored` is `True`, any `filepaths` in `self.plugin_filepaths` will be automatically removed. Recommend passing in absolute filepaths but method will attempt to convert to absolute filepaths based on current working directory. """ filepaths = util.to_absolute_paths(filepaths) self.blacklisted_filepaths = filepaths if remove_from_stored: self.plugin_filepaths = util.remove_from_set(self.plugin_filepaths, filepaths)
def set_plugin_filepaths(self, filepaths, except_blacklisted=True): """ Sets `filepaths` to the `self.plugin_filepaths`. Recommend passing in absolute filepaths. Method will attempt to convert to absolute paths if they are not already. `filepaths` can be a single object or an iterable. If `except_blacklisted` is `True`, all `filepaths` that have been blacklisted will not be set. """ filepaths = util.to_absolute_paths(filepaths) if except_blacklisted: filepaths = util.remove_from_set(filepaths, self.blacklisted_filepaths) self.plugin_filepaths = filepaths
def add_directories(self, directories, except_blacklisted=True): """ Adds `directories` to the set of plugin directories. `directories` may be either a single object or a iterable. `directories` can be relative paths, but will be converted into absolute paths based on the current working directory. if `except_blacklisted` is `True` all `directories` in `self.blacklisted_directories` will be removed """ directories = util.to_absolute_paths(directories) if except_blacklisted: directories = self._remove_blacklisted(directories) self.plugin_directories.update(directories)
def set_directories(self, directories, except_blacklisted=True): """ Sets the plugin directories to `directories`. This will delete the previous state stored in `self.plugin_directories` in favor of the `directories` passed in. `directories` may be either a single object or an iterable. `directories` can contain relative paths but will be converted into absolute paths based on the current working directory. if `except_blacklisted` is `True` all `directories` in `self.blacklisted_directories` will be removed """ directories = util.to_absolute_paths(directories) if except_blacklisted: directories = self._remove_blacklisted(directories) self.plugin_directories = directories
def collect_filepaths(self, directories): """ Collects and returns every filepath from each directory in `directories` that is filtered through the `file_filters`. If no `file_filters` are present, passes every file in directory as a result. Always returns a `set` object `directories` can be a object or an iterable. Recommend using absolute paths. """ plugin_filepaths = set() directories = util.to_absolute_paths(directories) for directory in directories: filepaths = util.get_filepaths_from_dir(directory) filepaths = self._filter_filepaths(filepaths) plugin_filepaths.update(set(filepaths)) plugin_filepaths = self._remove_blacklisted(plugin_filepaths) return plugin_filepaths
def set_blacklisted_directories(self, directories, remove_from_stored_directories=True): """ Sets the `directories` to be blacklisted. Blacklisted directories will not be returned or searched recursively when calling `collect_directories`. This will replace the previously stored set of blacklisted paths. `directories` may be a single instance or an iterable. Recommend passing in absolute paths. Method will try to convert to absolute path based on current working directory. """ absolute_paths = util.to_absolute_paths(directories) self.blacklisted_directories = absolute_paths if remove_from_stored_directories: plug_dirs = self.plugin_directories plug_dirs = util.remove_from_set(plug_dirs, directories)
def add_blacklisted_directories(self, directories, remove_from_stored_directories=True): """ Adds `directories` to be blacklisted. Blacklisted directories will not be returned or searched recursively when calling the `collect_directories` method. `directories` may be a single instance or an iterable. Recommend passing in absolute paths, but method will try to convert to absolute paths based on the current working directory. If `remove_from_stored_directories` is true, all `directories` will be removed from `self.plugin_directories` """ absolute_paths = util.to_absolute_paths(directories) self.blacklisted_directories.update(absolute_paths) if remove_from_stored_directories: plug_dirs = self.plugin_directories plug_dirs = util.remove_from_set(plug_dirs, directories)