-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.py
84 lines (66 loc) · 2.26 KB
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from ast import arg
import sys
from codeshare import db_init
import pathlib
def create_app(directory):
"""
function that creates a new directory with the following files
__init__.py, dependencies.py, schemas.py, views.py,
models.py, urls.py
"""
path_obj = pathlib.Path() / "miscellaneous"
for objs in pathlib.Path("").iterdir():
if objs.name == directory:
print("directory already exists")
return
create_dir = pathlib.Path(directory)
create_dir.mkdir(parents=True, exist_ok=True)
for dummy_file in path_obj.iterdir():
if dummy_file.name == "Readme.md":
continue
file_name = dummy_file.name.replace(".txt", ".py")
path = create_dir / file_name
with path.open("w", encoding="utf-8") as f:
if file_name.startswith("urls"):
f.write(dummy_file.read_text().format(directory, directory, directory))
else:
f.write(dummy_file.read_text())
try:
first, main, *extra = sys.argv
except ValueError:
pass
def command_create_tables(*args):
db_init.create_tables(*args)
def createsuperuser(*args):
username = input("username: ")
password = input("password:")
db_init.create_super_user(username, password)
def createsuperuserauto(*args):
db_init.create_super_user("123", "123")
# first item of each list contains the function to be called
# second item contains info about the command
commands = {
"create_tables": [command_create_tables, "creates table on the database"],
"createsuperuser": [
createsuperuser,
"creates a super user by asking username and password",
],
"createsuperuserauto": [
createsuperuserauto,
"creates a superuser without asking username or password",
],
"create_app": [create_app, "creates an app to the current working directory"],
}
def manage_help():
print(
"""
Welcome to manage.py help down is the list of commands you can use
"""
)
for key, value in commands.items():
print(f"{key} | {value[1]}")
commands["help"] = [manage_help, "shows all the commands available"]
if values := commands.get(main):
values[0](*extra)
else:
print('no such command found run "help" for more')