Skip to main content

file system tool extension

Project description

fstool

install using pip

python3 -m pip install fstool

Command line tool

python3 -m fstool -h

usage: __main__.py [-h] [-p PATH] [-c CONFIG] [-v] [-m] [-o] [-s START] [-e END]
{restructure}

format file directory files

positional arguments:
  {restructure}

optional arguments:
  -h, --help            show this help message and exit
  -p PATH, --path PATH  home path
  -c CONFIG, --config CONFIG
                        config file location. default is config.json
  -v, --verbose         increase output verbosity
  -m, --move            moves files instead of default copy
  -o, --overwrite       ovewrites the file if it exists
  -s START, --start START
                        start depth of file search
  -e END, --end END     end depth of file search

Documentation

Exposes three functions to the public

  • restructure
restructure(
    home: str,
    files: list,
    config: dict,
    *,
    move: bool = True,
    overwrite: bool = False,
    verbose: bool = False,
):

config is a dictionary of instructions on how to restructure the files, an example of which would be

{ 
   ".+\\.txt":{ 
      "dir":"aiml",
      "file":".+\\.txt"
   },
   "(.+)\\.properties":{ 
      "dir":"config",
      "file":"\\1.txt"
   }
}

This is inefficient to write so fstool comes with a built in parser (parse_config) so that the above json can be written as

{
    "aiml": [
        ".+\\.txt"
    ],
    "config": [{
        "old": "(.+)\\.properties",
        "new": "\\1.txt"
    }],
}

where the key is the directory and maps to a list of regex patterns or if you want to rename the file an object with keys new and old

old - file to move

new - file to be moved to

  • crawl
crawl(
        path: str,
        start_depth: int = 0,
        end_depth: int = -1,
        *,
        skip_permission_error: bool = True) -> tuple:
    iterates through directores starting with path

    :return: (files, dirs) from start_depth(inclusive) to end_depth(exclusive)

    default start_depth is 0
    default end_depth is -1 (till all paths exhausted)

    :param skip_permission_error: when true skips through all directores that requires elevated privilages

    *note: if start_depth equals end_depth lists will be empty

To default parameters left to it would iterate through all the subdirectories

depth 0

start_depth - 0

start_depth - 1

depth 1

start_depth - 1

start_depth - 2

etc

  • parse_config
parse_config(config: dict) -> dict:

Compiles input json to a more efficient version which can be used by the restructure function

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

fstool-0.1.8.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

fstool-0.1.8-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file fstool-0.1.8.tar.gz.

File metadata

  • Download URL: fstool-0.1.8.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for fstool-0.1.8.tar.gz
Algorithm Hash digest
SHA256 761f2755643c0e0ecf91e478996e769fc458421b562edeb2a6d4a048fe13a1f9
MD5 7fcd7e1f513c3f415e38220ba8106bc9
BLAKE2b-256 c36d8f691bfc5448324315c7ab8e5d5cfb9a8e1b308b1dd40445b37158745baf

See more details on using hashes here.

File details

Details for the file fstool-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: fstool-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for fstool-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 07ded01e50dbee924fff718493cfe0696f700434d3a3ebb6c9f1b126dfae5ac7
MD5 2107d02b3b98aea55ca7a9af47f45b0a
BLAKE2b-256 6c773df6ff7efb8811cc3f3c7db6a5c94dbdcf7f06fac4e00fcccfec7c61d6f9

See more details on using hashes here.

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