Skip to main content

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.

Project description

PLEASE 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.dir, 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 their Dir, 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.prename, 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() and File.write() methods (and associated File.content property) which invokes the FormatHandler class to determine how to read from/write to the file based on its extension. FormatHandler uses the factory design pattern and can be extended at runtime to enable File to handle types of files that are not supported by default.

  • By default, recognized formats are the following:

    format class accepted/returned file extensions
    Pdf PyPDF2 pdf
    Tabular subtypes.Frame xlsx, csv
    Word docx.Document docx
    Image PIL.Image png, jpf, jpeg
    Audio pydub.AudioSegment mp3, wav, ogg, flv
    Video Moviepy.editor.edit mp4, mkv, avi, gif
    Compressed pathmagic.Dir zip, tar
    Link pathmagic.File or pathmagic.Dir lnk
    Serialized Any pkl
    Json Any json
    MarkUp subtypes.Markup html, xml
    Default subtypes.Str everything else

Installation

To install use pip:

$ pip install pathmagic

Or clone the repo:

$ git clone https://github.com/matthewgdv/pathmagic.git
$ python setup.py install

Usage

Detailed usage examples coming soon.

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Report Bugs

Report bugs at https://github.com/matthewgdv/pathmagic/issues

If you are reporting a bug, please include:

  • Your operating system name and version.
  • Any details about your local setup that might be helpful in troubleshooting.
  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with "bug" and "help wanted" is open to whoever wants to implement a fix for it.

Implement Features

Look through the GitHub issues for features. Anything tagged with "enhancement" and "help wanted" is open to whoever wants to implement it.

Write Documentation

The repository could always use more documentation, whether as part of the official docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/matthewgdv/pathmagic/issues.

If you are proposing a new feature:

  • Explain in detail how it would work.
  • Keep the scope as narrow as possible, to make it easier to implement.
  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Before you submit a pull request, check that it meets these guidelines:

  1. If the pull request adds functionality, it should include tests and the docs should be updated. Write docstrings for any functions that are part of the external API, and add the feature to the README.md.

  2. If the pull request fixes a bug, tests should be added proving that the bug has been fixed. However, no update to the docs is necessary for bugfixes.

  3. The pull request should work for the newest version of Python (currently 3.7). Older versions may incidentally work, but are not officially supported.

  4. Inline type hints should be used, with an emphasis on ensuring that introspection and autocompletion tools such as Jedi are able to understand the code wherever possible.

  5. PEP8 guidelines should be followed where possible, but deviations from it where it makes sense and improves legibility are encouraged. The following PEP8 error codes can be safely ignored: E121, E123, E126, E226, E24, E704, W503

  6. This repository intentionally disallows the PEP8 79-character limit. Therefore, any contributions adhering to this convention will be rejected. As a rule of thumb you should endeavor to stay under 200 characters except where going over preserves alignment, or where the line is mostly non-algorythmic code, such as extremely long strings or function calls.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pathmagic-0.3.4.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

pathmagic-0.3.4-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file pathmagic-0.3.4.tar.gz.

File metadata

  • Download URL: pathmagic-0.3.4.tar.gz
  • Upload date:
  • Size: 20.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for pathmagic-0.3.4.tar.gz
Algorithm Hash digest
SHA256 2fde0e73f9c074e425ab1489e33272ca351fde83536b7189f7fd66eb4f59a7e8
MD5 116ff6835ef8f7ac4d5fe632eac19aa5
BLAKE2b-256 5205f2875fd73b1459bf09bba34b23ac4d8e689c4d642becc84e55f124bb0e6c

See more details on using hashes here.

Provenance

File details

Details for the file pathmagic-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: pathmagic-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for pathmagic-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 aa315a6ab66929808ea199bc7069f36879ba830cb3310546a1ce96a05f99f263
MD5 e6e3dace7009d89287889ff9e969c1dc
BLAKE2b-256 c702b3d1e391586600e7e0d12a20b6e6547e28666048bd7cf262da5d9a0923de

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page