FsQuass is a filesystem query and traversing library, a pythonic jQuery for filesystem.
Still work in progress.
Bases: set
Files set. Is a set of File and Dir instances with traversal methods. Besides the methods inherited from set, it has some methods and properties specific to file systems.
nodes can be a string or an iterable. of File and Dir instances.
If nodes is a string, it’s treated differently depending on what it starts with:
A space is treated like in CSS, a recursive search for descendants. E.g.
Fs('/home/user tests/__init__.py')
will
Note: Recursive scans can be expensive. If you
Filters items_list by patten.
Filtering a set of paths is equal to an intersection of the set and of a set found by pattern:
dirs = Fs('/home/siberiano;/home;/tmp;/tmp/siberiano')
dirs.filter('siberiano') == dirs & Fs('/').find('. siberiano')
Searches by pattern inside the set items. Returns a new Fs instance. E.g. if we have a set fs of these paths:
/home/user/
/root
fs.find('.bashrc') will probably output:
/home/user/.bashrc
/root/.bashrc
If you need to find multiple paths, separate them with semicolon:
Fs('/home/siberiano').find('.bashrc;Work/project/templates base.haml')
Will search for .bashrc file in my homefolder (but not deeper) and inside ~/Work/project/templates will recursively search for base.haml files.
To avoid accidental scanning of the entire filesystem, recursive search is made harder. Use dot and space in the beginning if you need it anyway:
# scan the entire filesystem for 'siberiano'
Fs('/').find('. siberiano')
# scans for files & directories named 'project' inside Work
Fs('/home/siberiano/Work').find('. project')
Makes a hard link to all the set members in target folder.
Optional name_callback should work like this:
def name_callback(source, target):
# source & target are Fs instances with 1 member each
return source, target
Returns a set of parents of all the items, e.g. for
/home/user/.bashrc
/home/user/.hgrc
/tmp/test
/tmp
parents will be
/home/user
/tmp
/
Finds all the siblings of the files in set, filtered by pattern. The result will not include any files of the original set.
Makes a symbolic link in target folder like Fs.linkTo()
Bases: fsquass.__init__.File
Directory. Returns its directories and files in children() method.
Is iterable:
Can check if contains another File or Dir:
>>> Dir('/home') in Dir('/') True >>> Dir('/tmp') in Dir('/home') False
Lists the directory and returns Fs of the files, filtered by pattern.
Bases: object
A file or a directory. Contains self.path, and if an object with the same absolute path is instantiated, an existing item is returned. If full_path is unaccessible, EnvironmentError is raised.
Returns an Fs of child nodes. Makes sense in Dir only, but put here for compatibility.