Last active
March 12, 2017 10:10
-
-
Save swayson/ed6b7a8c0481cd266bebeccb787afb31 to your computer and use it in GitHub Desktop.
Simple python cli application to construct directories according to specifications.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import click | |
def read_file(filename): | |
with open(filename) as in_file: | |
for line in in_file: | |
if line.strip() != '': | |
yield line.strip() | |
@click.command() | |
@click.argument('template', type=click.Path(), required=True) | |
@click.argument('root', type=click.Path(), required=False) | |
def create(template, root): | |
""" Creates a directory structure according to a given template. | |
Parameters | |
---------- | |
template : string | |
filename of template file. template file is a text file | |
where each line represents a folder uses a relative path notation. | |
e.g. /path/to/somewhere | |
root : string | |
Path in which the folders will be created. If None provided, will use | |
current working directory. | |
Usage | |
----- | |
$ python standard_folders.py template.txt project/ | |
""" | |
print("Starting.") | |
if root is None: | |
root = os.getcwd() | |
print(root) | |
for item in read_file(template): | |
if not os.path.exists(item): | |
filename = os.path.join(root, item) | |
print("Making folder... {}".format(filename)) | |
os.makedirs(filename, mode=755) | |
print("Done.") | |
if __name__ == '__main__': | |
create() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
audio | |
audio/music | |
audio/meditation | |
audio/podcasts | |
audio/talks | |
video | |
video/movies | |
video/talks | |
video/lectures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment