
    SOg#                     &    S SK Jr   " S S\5      rg)    )utilc                       \ rS rSrSr   SS jrS rSS jrSS jrS r	S	 r
S
 rS rS rSS jrSS jrSS jrS rS rS rS rSrg)FileManager   a  
`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.
Nc                     Uc  / nUc
  [        5       nUc
  [        5       n[        R                  " U5      U l        [        R                  nU" U5      U l        U" U5      U l        g)a  
`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.
N)setr   return_listfile_filtersto_absolute_pathsplugin_filepathsblacklisted_filepaths)selfr
   r   r   to_abs_pathss        _/Users/admin/workspace/ai/Jarvis/env/lib/python3.13/site-packages/pluginmanager/file_manager.py__init__FileManager.__init__   se    . L#"u ($'E! ,,\:-- ,-= >%12G%H"    c                     [        5       n[        R                  " U5      nU HD  n[        R                  " U5      nU R	                  U5      nUR                  [        U5      5        MF     U R                  U5      nU$ )a2  
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.
)r   r   r   get_filepaths_from_dir_filter_filepathsupdate_remove_blacklisted)r   directoriesr   	directory	filepathss        r   collect_filepathsFileManager.collect_filepaths5   sr     5,,[9$I33I>I..y9I##C	N3 %
  334DEr   c                     [         R                  " U5      nU(       a!  [         R                  " UU R                  5      nU R                  R                  U5        g)a:  
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.
N)r   r   remove_from_setr   r   r   r   r   except_blacklisteds      r   add_plugin_filepaths FileManager.add_plugin_filepathsK   sI     **95	,,Y-1-G-GII 	$$Y/r   c                     [         R                  " U5      nU(       a!  [         R                  " UU R                  5      nXl        g)a9  
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.
N)r   r   r   r   r   r    s      r   set_plugin_filepaths FileManager.set_plugin_filepaths]   s;     **95	,,Y-1-G-GII !*r   c                 |    [         R                  " U5      n[         R                  " U R                  U5      U l        g)z
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.
N)r   r   r   r   r   r   s     r   remove_plugin_filepaths#FileManager.remove_plugin_filepathso   s3     **95	 $ 4 4T5J5J5>!@r   c                     U R                   $ )zD
returns the plugin filepaths tracked internally as a `set` object.
)r   r   s    r   get_plugin_filepaths FileManager.get_plugin_filepaths{   s     $$$r   c                 <    [         R                  " U5      nXl        g)zu
Sets internal file filters to `file_filters` by tossing old state.
`file_filters` can be single object or iterable.
N)r   r	   r
   r   r
   s     r   set_file_filtersFileManager.set_file_filters   s    
 ''5(r   c                 f    [         R                  " U5      nU R                  R                  U5        g)zd
Adds `file_filters` to the internal file filters.
`file_filters` can be single object or iterable.
N)r   r	   r
   extendr0   s     r   add_file_filtersFileManager.add_file_filters   s(    
 ''5  .r   c                 P    [         R                  " U R                  U5      U l        g)zk
Removes the `file_filters` from the internal state.
`file_filters` can be a single object or an iterable.
N)r   remove_from_listr
   r0   s     r   remove_file_filtersFileManager.remove_file_filters   s#    
 !11$2C2C2>@r   c                 D    Uc  U R                   $ U" U R                   5      $ )zo
Gets the file filters.
`filter_function`, can be a user defined filter. Should be callable
and return a list.
)r
   )r   filter_functions     r   get_file_filtersFileManager.get_file_filters   s'     "$$$"4#4#455r   c                     [         R                  " U5      nU R                  R                  U5        U(       a'  [         R                  " U R
                  U5      U l        gg)a  
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.
N)r   r   r   r   r   r   r   r   remove_from_storeds      r   add_blacklisted_filepaths%FileManager.add_blacklisted_filepaths   sO     **95	"")))4$($8$89N9N9B%DD! r   c                     [         R                  " U5      nXl        U(       a'  [         R                  " U R                  U5      U l        gg)a&  
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.
N)r   r   r   r   r   r@   s      r   set_blacklisted_filepaths%FileManager.set_blacklisted_filepaths   sA     **95	%."$($8$89N9N9B%DD! r   c                 t    [         R                  " U5      nU R                  n[         R                  " X!5      ng)z
Removes `filepaths` from blacklisted filepaths

Recommend passing in absolute filepaths but method will attempt
to convert to absolute filepaths based on current working directory.
N)r   r   r   r   )r   r   black_pathss      r   remove_blacklisted_filepaths(FileManager.remove_blacklisted_filepaths   s/     **95	00**;Br   c                     U R                   $ )z4
Returns the blacklisted filepaths as a set object.
)r   r,   s    r   get_blacklisted_filepaths%FileManager.get_blacklisted_filepaths   s     )))r   c                 F    [         R                  " XR                  5      nU$ )zN
internal helper method to remove the blacklisted filepaths
from `filepaths`.
)r   r   r   r(   s     r   r   FileManager._remove_blacklisted   s     
 ((4N4NO	r   c                     U R                   (       a8  [        5       nU R                    H  nU" U5      nUR                  U5        M     U$ UnU$ )zo
helps iterate through all the file parsers
each filter is applied individually to the
same set of `filepaths`
)r
   r   r   )r   r   r   file_filterplugin_pathss        r   r   FileManager._filter_filepaths   sS     "u#00*95 ''5  1    )r   )r   r
   r   )NNN)T)N)__name__
__module____qualname____firstlineno____doc__r   r   r"   r%   r)   r-   r1   r5   r9   r=   rB   rE   rI   rL   r   r   __static_attributes__ r   r   r   r      si    
 #"&'+#IJ ,0$*$
@%)/@	6DD	C* r   r   N)pluginmanagerr   objectr   rZ   r   r   <module>r]      s    e & e r   