pip install pathschemafrompathschemaimportvalidateschema='YOUR SCHEMA HERE'path_to_validate='./path'withopen('path/to/schema.pathschema', 'r') asf:
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/ |
# | Write a comment | # cool comment |
pathschema can be used directly in the command line.
python -m pathschema ./.pathschema path/to/dir/to/validateArgument 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 errorsInstalling
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_*.pyCommand line without installing
python ./pathschema/ ./tests/experimentations/test_schema.pathschema ./tests/experimentations/test_directory_okExample:
assets/
textures/
*.gif
*.png
materials/
"(trans|solid)_.+\.mat"
+README.mdvideos/
*.mp4
*.flvThis structure would be valid.
videos/
robots.mp4
planets.flv
my-mix-tape.flvThis structure would be invalid. (.png and .jpg is not allowed)
videos/
office.png
robots.jpgassets/
...Any files and directories would be valid in the assets folder.
assets/
banner.png
backgrounds/
bg_black.png
bg_white.pngexample/
*/
*
+README.mdThis structure would be valid.
example/
things/
file.txt
README.md
morethings/
README.mdThis structure would be invalid. (Missing README.md)
example/
things/
file.txt
morethings/