Provides ORM path classes (File and Dir), which automatically emit file system IO operations upon having their attributes modified. File objects allow for easy content manipulation of many forms of files.
Likely abandoned. No release or commit for years (last release over 5 years ago).
pip install pathmagicPLEASE NOTE:
This library is currently still under development. The API will likely undergo significant changes that may break any code you write with it. The documentation will fall out of sync with the updates regularly until development slows down. Use it at your own risk.
Overview
Pathmagic implements two classes, File and Dir, to represent mapped file system obects in a manner similar to database ORMs like sqlalchemy. These objects have properties which
perform file system operations when set, and implement many useful methods to abstract away nearly all file system I/O to a much higher degree than os.path or pathlib.
The Dir class
- Properties that perform rename and move operations when set (
Dir.path,Dir.parent,Dir.name) - Two accessor objects (
Dir.files,Dir.dirs) which allow iteration over their respective collections, item access, membership tests, and more - Two specialized accessor objects (
Dir.d,Dir.f), which dynamically populate themselves with snake_cased attributes that represent the files/folders in theirDir, such that the filesystem tree can be traversed purely through attribute access - Methods to create new files/dirs, copy/move self to another path/dir, delete self or content, and join self to a relative path
- Recursively walk the tree downwards, comparing own tree to a parallel filesystem tree
- Recursively seek files or dirs down the directory tree with inclusions/exclusions based on valid extensions and regex patterns matching name, path, and content.
- Compress self into a zipfile
- Visualize tree to arbitrary depth with an ascii representation
- Initialize from homepath, desktop, or package
The File class
-
Properties that perform rename and move operations when set (
File.path,File.dir,File.name,File.stem,File.extension) -
Methods to copy/move self to another path/dir or delete self
-
Initialize from script entry point (in traditional interpreter), and from a package resource
-
File.read()andFile.write()methods (and associatedFile.contentproperty) which invokes theFormatHandlerclass to determine how to read from/write to the file based on its extension. uses the factory design pattern and can be extended at runtime to enable to handle types of files that are not supported by default.