Skip to content

Commit

Permalink
Format using black
Browse files Browse the repository at this point in the history
  • Loading branch information
davidomarf committed Oct 17, 2019
1 parent 93a2615 commit 16e780f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 45 deletions.
4 changes: 1 addition & 3 deletions ginpar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ def main():
_index_template = _jinja_env.get_template("index.html")
index = open("public/index.html", "w")
index.write(
_index_template.render(
sketches=map(lambda a: a["name"], sketches), site=_SITE
)
_index_template.render(sketches=map(lambda a: a["name"], sketches), site=_SITE)
)
index.close()

Expand Down
4 changes: 2 additions & 2 deletions ginpar/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"""
from . import main

if __name__ == '__main__':
main()
if __name__ == "__main__":
main()
3 changes: 2 additions & 1 deletion ginpar/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json


def read_config(path):
with open(path, "r") as f:
config = json.load(f)
return config
return config
81 changes: 42 additions & 39 deletions ginpar/tools/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@
from jinja2 import Environment, FileSystemLoader


_TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'templates')
_TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")

_THEMES_DIR = os.path.join(Path(os.path.dirname(os.path.abspath(__file__))).parent,
'themes')

_SKETCHES_DIR = os.path.join(Path(os.path.dirname(os.path.abspath(__file__))).parent,
'sketches')
_THEMES_DIR = os.path.join(
Path(os.path.dirname(os.path.abspath(__file__))).parent, "themes"
)

_jinja_env = Environment(
loader=FileSystemLoader(_TEMPLATES_DIR),
trim_blocks=True,
_SKETCHES_DIR = os.path.join(
Path(os.path.dirname(os.path.abspath(__file__))).parent, "sketches"
)

_jinja_env = Environment(loader=FileSystemLoader(_TEMPLATES_DIR), trim_blocks=True)


def argv_to_flag_dict(argv):
"""Take an arguments vector and convert it into a dictionary"""
Expand All @@ -32,77 +30,82 @@ def argv_to_flag_dict(argv):


def create_folder(folder):
print(f'Creating `{folder}`:', end='\n\t')
print(f"Creating `{folder}`:", end="\n\t")
try:
os.mkdir(folder)
except FileExistsError:
print(f'Failure. It already exists.')
print(f"Failure. It already exists.")
except:
print(f'Failure.')
print(f"Failure.")
else:
print(f'Sucess')
print(f"Sucess")


def init_config():
print('\nCreating `config.json` using template:', end = '\n\t')
print("\nCreating `config.json` using template:", end="\n\t")
try:
config = open('config.json', 'r')
config = open("config.json", "r")
except:
try:
config = open('config.json', 'w+')
config = open("config.json", "w+")
except:
print('Failure.')
print("Failure.")
else:
_template = _jinja_env.get_template('config.json.jinja2')
_template = _jinja_env.get_template("config.json.jinja2")
config.write(_template.render())
config.close()
print('Success.')
print("Success.")
else:
print("Failure. It already exists.")


def copy_folder(fr, to):
print(f'\nCopying `{to}` from `{fr}`:', end = '\n\t')
print(f"\nCopying `{to}` from `{fr}`:", end="\n\t")
try:
shutil.copytree(fr, to)
except FileExistsError:
print(f'Failure. It already exists.')
print(f"Failure. It already exists.")
else:
print(f'Success.')
print(f"Success.")


def try_remove(path):
if os.path.isdir(path):
print(f'`{path}` already exists. Attemping removal:', end = '\n\t')
print(f"`{path}` already exists. Attemping removal:", end="\n\t")
try:
shutil.rmtree(path)
except:
print(f'Failure. Restart or delete manually.')
print(f"Failure. Restart or delete manually.")
else:
print(f'Success.')
print(f"Success.")
elif os.path.isfile(path):
print(f'`{path}` already exists. Attemping removal:', end = '\n\t')
print(f"`{path}` already exists. Attemping removal:", end="\n\t")
try:
os.remove(path)
except:
print(f'Failure. Restart or delete manually.')
print(f"Failure. Restart or delete manually.")
else:
print(f'Success.')
print(f"Success.")
else:
print(f'`{path}` doesn\'t exist. Skipping.')
print(f"`{path}` doesn't exist. Skipping.")


def main():
flags = argv_to_flag_dict(sys.argv)

if "--force" in flags:
print("\n---\nForcing quickstart. This will replace existent directories and files.\n---\n")
try_remove('sketches')
try_remove('themes')
try_remove('config.json')
print(
"\n---\nForcing quickstart. This will replace existent directories and files.\n---\n"
)
try_remove("sketches")
try_remove("themes")
try_remove("config.json")

print("\n---\nInitializing the project with default values\n---\n")
copy_folder(_THEMES_DIR, 'themes')
copy_folder(_SKETCHES_DIR, 'sketches')
copy_folder(_THEMES_DIR, "themes")
copy_folder(_SKETCHES_DIR, "sketches")
init_config()


if __name__ == '__main__':
main()
if __name__ == "__main__":
main()

0 comments on commit 16e780f

Please sign in to comment.