Skip to main content

Standardize and plan out a file structure!

Project description

Path Schema

PyPi Version PyPI Python Version License MIT

pip install pathschema

How to use

from pathschema import validate

schema = ''

path_to_validate = './path'

with open('path/to/schema.txt', 'r') as f:
	schema = f.read()

result = validate(path_to_validate, schema)

if(result.has_error()):
	print('Invalid')
else:
	print('Valid')
Symbol Description Example
/ Slashes at the end of the name marks this path as a folder root/
"" Quotes adds regex validation to the file name "file[0-9]{3}"
""/ Quotes with a slash adds regex validation to the folder name "folder[0-9]{3}"/
* Unix style pattern matching for files *.txt
*/ Unix style pattern matching for folders log_*/
... Allows any (and nested) files and folder ...
+ A + at the start makes the file or folder required +required_file.txt
- A - at the start makes the file or folder forbidden -forbidden_folder/

Command line

pathschema can be used directly in the command line.

python -m pathschema path/to/schema.txt path/to/dir/to/validate

Argument details:

usage: __main__.py [-h] [--errors-only] schema directory

Validate a directory against a schema

positional arguments:
  schema         Path to schema file
  directory      Path to directory to validate

options:
  -h, --help     show this help message and exit
  --errors-only  Only show errors

Development

Installing

python -m pip install -r ./requirements.txt
python -m build
python -m pip install -e .

Running tests

python -m unittest discover -v -s ./tests -p test_*.py

Command line without installing

python ./pathschema/ ./tests/experimentations/test_schema.txt ./tests/experimentations/test_directory_ok

Example Schema Definition

Example:

assets/
	textures/
		*.gif
		*.png
	materials/
		"(trans|solid)_.+\.mat"
	+README.md

Only allows .mp4 or .flv in the videos folder

videos/
	*.mp4
	*.flv

This structure would be valid.

videos/
	robots.mp4
	planets.flv
	my-mix-tape.flv

This structure would be invalid. (.png and .jpg is not allowed)

videos/
	office.png
	robots.jpg

Any files and folder allowed in the assets folder

assets/
	...

Any files and directories would be valid in the assets folder.

assets/
	banner.png
	backgrounds/
		bg_black.png
		bg_white.png

Must have a README.md file

example/
	*/
		*
		+README.md

This structure would be valid.

example/
	things/
		file.txt
		README.md
	morethings/
		README.md

This structure would be invalid. (Missing README.md)

example/
	things/
		file.txt
	morethings/

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

pathschema-0.1.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

pathschema-0.1.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file pathschema-0.1.0.tar.gz.

File metadata

  • Download URL: pathschema-0.1.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for pathschema-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8dd0bd98d890965078d7fdd4c8400dbf4a96e9a8f6e7c0c05c9fa55427d997a8
MD5 c7fd450b0a24af420aacde8fb9ec3469
BLAKE2b-256 39fb5d9971b4f1754ed63095ccd7213462e7c4aae703da46a46f4b1db3410e4d

See more details on using hashes here.

File details

Details for the file pathschema-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pathschema-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for pathschema-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2bf7288612b57c3f00c50bd9867dfa1842676ae49e8a0c16e887652c740bee50
MD5 12d5cce6d67e77bdd5f4fe150654fa7b
BLAKE2b-256 5bc147c016b942957892285a6ba9e3bf6853602e711b89e1651d56e6a2897d72

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