Easily create filesytems. A shorthand for creating files and folders. Create directory trees with ease
Project description
tree (sharpshooter)
Shorthand templates for creating (or destroying) file-systems.
tree could be written for any language.
pip install sharpshooter
intro
To create a plain empty file just type a word i.e.
file
to create or access a dir use +
+dir
To create a file inside a dir use a 4 spaces (or tab)
+dir
file
putting it all together…
+dir
file
+plugins
+mail
+vendor
index.html
+something # this one will fail
file.py
file.py
Creating a tree
from sharpshooter import tree
tree('''
+dir
file
+plugins
+mail
+vendor
index.html
file.py
file2.py
''')
tree doesn't wait to be told. Your files are now there.
deleting a tree
tree can also remove dirs and files. You guessed it. With the the - minus symbol
tree = '''
+dir
+plugins
-mail
'''
tree will not ask twice. Your files are gone.
But be mindful this example would also 'create' the dir and plugins folders if they didn't exist. Because tree by nature creates by default.
To read info about a file or folder without creation use colon ':' to indicate read-only.
tree = '''
+:dir
+:plugins
-mail
'''
More on colons : later.
comments
use # to comment out a line or instruction. (warning. bug. DON'T leave a space before the comment. Lexer may interpret it as directory change. THIS should be fixed. add more tests before removing this warning.)
s = '''
+:dir
file# some ignored text here
+plugins
+mail
'''
read only
To read info about a file or folder, without creating any, use a colon ':'
You can then format the tree with an f-string to get the result which produces similir output as 'ls -al' on nix systems i.e.
test = tree('''
:README.md
''')
print(f"{test}")
# -rw-r--r-- byteface staff 2100 21 Sep 07:58 README.md
or for a directory...
test = tree('''
:venv
''')
print(f"{test}")
# drwxr-xr-x byteface staff 192 Mon Sep 20 10:18:44 2021 venv
Notice the little 'd' at the front lets you know it's a directory. Just like in a terminal.
you can safely change change order of colon and plus i.e. will still work.
tree('''
:+dont
:+make
:this
''')
but i prefer to use the colon right before the file or folder name .i.e.
tree('''
+:dont
+:make
:this
''')
up to you.
test mode
If you are feeling unsure. Try tree in test mode.
It will log what it would do to the console but won't actually create any files or folders.
You just have to past test=True to the tree function. i.e
mytree = '''
+somedir
+anotherdir
someotherfile.png
file.txt
file2.gif
'''
tree(mytree, test=True) # notice how we set test=True
Now you can check the console and if you feel confident set test=False and run the code again.
tilde
users home path is supported. (* TODO - not yet tested on pc)
s1 = """
:+~
test.png
+somedir
somescript.py
"""
tree(s1, test=True)
tree(s1, test=False)
Anything else?
- you can now have spaces in filenames.
To see planned features/goals see TODO.md
CLI
There's several commands you can pass to sharpshooter on the command line.
$ python3 -m sharpshooter --version # shows the current version. also uses -v
$ sharpshooter --file myconfig.tree # parses a .tree file and executes it. also uses -f
$ sharpshooter --test anotherconfig.tree # parses a .tree file in test mode. also uses -t
$ sharpshooter --create someconfigname # creates a helloworld.tree file. also uses -c
NOTES
I came up with the idea while mucking around with a lexer.
remember it executes from where your python thinks is the current dir. If you're unsure set it first. i.e.
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))
Contributing
If you think you can write a sharpshooter parser in another language then please do and i'll link to your repo.
To dev on this one locally just pull the repo and do...
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
python3 setup.py install # To install your version.
Or run and write some tests, there's a few to get started in the Makefile.
DISCLAIMER / known bugs
This is a work in progress. It creates and destroys files on your hard drive. So be careful.
DON'T leave trailing negative space on lines. I use space to change dirs.
Use 4 spaces not tabs. (I've not tested with tabs as my editor converts them to 4 spaces). will sort later.
When using a comment. Don't leave space before the # < note this one should be fixed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sharpshooter-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28b937f4cf73b389289de838a4f3e2d87a917709faf22de19d09b8456d7315d3 |
|
MD5 | 357b3f47a5b9f49187004226dcf12617 |
|
BLAKE2b-256 | c91b8d93a622216a8f8d81575c95e60fa9c836b5c095a8e7d3b919abd69ae56b |