Path Schema
pip install pathschema
How to use
from pathschema import validate
schema = 'YOUR SCHEMA HERE'
path_to_validate = './path'
with open('path/to/schema.pathschema', 'r') as f:
schema = f.read()
result = validate(path_to_validate, schema)
if(result.has_error()):
print('Invalid')
else:
print('Valid')
Syntax
| 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/ |
# |
Write a comment | # cool comment |
Command line
pathschema can be used directly in the command line.
python -m pathschema ./.pathschema 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.pathschema ./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/
Metadata
Release files for pathschema 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pathschema-0.2.1.tar.gz | 13.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pathschema-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.7 kB
Release files / pathschema-0.2.1.tar.gz
| Download URL | pathschema-0.2.1.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4ec45060b1c2288b40acb046f87470f546d50227cbd25d2bd9a851e4c2f8b349
|
|
BLAKE2b-256 checksum How to use checksums |
9a8474b6a4583b3a5e9c43491413396015369a6727c65c52689e5bf75f77b885
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / pathschema-0.2.1-py3-none-any.whl
| Download URL | pathschema-0.2.1-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a0e67ee5ba81df8d8486a6ade39f2a69464ba60cbb7f92690427161d930c743
|
|
BLAKE2b-256 checksum How to use checksums |
d35ac2c591389c57e1d207081e2f484ffb2c1f6c73366e00505ff8984d5c095c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|