pluginmanager.FileManager¶
-
class
pluginmanager.
FileManager
(file_filters=None, plugin_filepaths=None, blacklisted_filepaths=None)[source]¶ FileManager manages the file filter state and is responible for collecting filepaths from a set of directories and filtering the files through the filters. Without file filters, this class acts as a passthrough, collecting and returning every file in a given directory.
FileManager can also optionally manage the plugin filepath state through the use of the add/get/set plugin filepaths methods. Note that plugin interface is not automatically set up this way, although it is relatively trivial to do.
-
__init__
(file_filters=None, plugin_filepaths=None, blacklisted_filepaths=None)[source]¶ FileFilters are callable filters. Each filter must take in a set of filepaths and return back a set of filepaths. Each filter is applied independently to the set of filepaths and added to the return set. FileFilters can be a single object or an iterable
plugin_filepaths are known plugin filepaths that can be stored in FileManager. Note that filepaths stored in the plugin filepaths are NOT automatically added when calling the collect_filepaths method. Recommend using absolute paths. plugin_filepaths can be a single object or an interable.
blacklisted_filepaths are plugin filepaths that are not to be included in the collected filepaths. Recommend using absolute paths. blacklisted_filepaths can be a single object or an iterable.
Methods
__init__
([file_filters, plugin_filepaths, ...])FileFilters are callable filters. Each filter must take in a add_blacklisted_filepaths
(filepaths[, ...])Add filepaths to blacklisted filepaths. add_file_filters
(file_filters)Adds file_filters to the internal file filters. add_plugin_filepaths
(filepaths[, ...])Adds filepaths to the self.plugin_filepaths. collect_filepaths
(directories)Collects and returns every filepath from each directory in directories that is filtered through the file_filters. get_blacklisted_filepaths
()Returns the blacklisted filepaths as a set object. get_file_filters
([filter_function])Gets the file filters. get_plugin_filepaths
()returns the plugin filepaths tracked internally as a set object. remove_blacklisted_filepaths
(filepaths)Removes filepaths from blacklisted filepaths remove_file_filters
(file_filters)Removes the file_filters from the internal state. remove_plugin_filepaths
(filepaths)Removes filepaths from self.plugin_filepaths. set_blacklisted_filepaths
(filepaths[, ...])Sets internal blacklisted filepaths to filepaths. set_file_filters
(file_filters)Sets internal file filters to file_filters by tossing old state. set_plugin_filepaths
(filepaths[, ...])Sets filepaths to the self.plugin_filepaths. -
add_blacklisted_filepaths
(filepaths, remove_from_stored=True)[source]¶ Add filepaths to blacklisted filepaths. If remove_from_stored is True, any filepaths in 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.
-
add_file_filters
(file_filters)[source]¶ Adds file_filters to the internal file filters. file_filters can be single object or iterable.
-
add_plugin_filepaths
(filepaths, except_blacklisted=True)[source]¶ Adds 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 added.
-
collect_filepaths
(directories)[source]¶ 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.
-
get_file_filters
(filter_function=None)[source]¶ Gets the file filters. filter_function, can be a user defined filter. Should be callable and return a list.
-
remove_blacklisted_filepaths
(filepaths)[source]¶ Removes filepaths from blacklisted filepaths
Recommend passing in absolute filepaths but method will attempt to convert to absolute filepaths based on current working directory.
-
remove_file_filters
(file_filters)[source]¶ Removes the file_filters from the internal state. file_filters can be a single object or an iterable.
-
remove_plugin_filepaths
(filepaths)[source]¶ 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.
-
set_blacklisted_filepaths
(filepaths, remove_from_stored=True)[source]¶ 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.
-
set_file_filters
(file_filters)[source]¶ Sets internal file filters to file_filters by tossing old state. file_filters can be single object or iterable.
-
set_plugin_filepaths
(filepaths, except_blacklisted=True)[source]¶ 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.
-