-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_app.py
More file actions
40 lines (30 loc) · 1.22 KB
/
Copy pathcreate_app.py
File metadata and controls
40 lines (30 loc) · 1.22 KB
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
import os
import sys
# Define the base paths and file names
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
APP_DIRS = {
'repositories': 'repository.py',
'routers': 'router.py',
'schemas': 'schema.py'
}
def create_myapp_dirs(app_name):
for app_dir, file_name in APP_DIRS.items():
# Define the directory and file path
dir_path = os.path.join(BASE_DIR, 'app', app_dir, app_name)
file_path = os.path.join(dir_path, file_name)
# Create the directory if it doesn't exist
os.makedirs(dir_path, exist_ok=True)
# Create the __init__.py file to make it a Python package
init_file_path = os.path.join(dir_path, '__init__.py')
with open(init_file_path, 'w') as f:
f.write(f'# {app_name} package in {app_dir}\n')
# Create the main file (repository.py, router.py, schema.py)
with open(file_path, 'w') as f:
f.write(f'# {file_name} for {app_name} module in {app_dir}\n')
print(f"Packages and files for '{app_name}' created successfully.")
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: create_app.py <myapp_name>")
sys.exit(1)
app_name = sys.argv[1]
create_myapp_dirs(app_name)