summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <dcariotti24@gmail.com>2020-04-09 21:34:08 +0200
committerSanto Cariotti <dcariotti24@gmail.com>2020-04-09 21:34:08 +0200
commit00cade9f5bd860fdc4e3cd3290c64ed3d88c168d (patch)
tree2fb847fba390ea2f89d7f2703a13282e5101753b
parent9e55ac09c2ce2ead1457f264face35c4cc36d99e (diff)
feat: init project command
-rwxr-xr-xbin/frest11
-rw-r--r--frest/manage/utils.py22
2 files changed, 32 insertions, 1 deletions
diff --git a/bin/frest b/bin/frest
index f41df68..c274ca5 100755
--- a/bin/frest
+++ b/bin/frest
@@ -1,14 +1,16 @@
#!/usr/bin/env python
import argparse
-from frest.manage.utils import logo, create_app
+from frest.manage.utils import logo, create_app, init_project
from frest.manage.utils import logging, logging_arg
import os
+import sys
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--startapp", "-s", type=str, help="create new app")
+ parser.add_argument("--init", "-", type=str, help="create new project")
args = parser.parse_args()
if args.startapp:
@@ -18,6 +20,13 @@ def main():
os.mkdir("scheme")
create_app(args.startapp)
+ elif args.init:
+ appname = args.init
+ if os.path.exists(appname):
+ logging("App already exists", 2, "\n")
+ sys.exit(1)
+
+ init_project(appname)
if __name__ == "__main__":
diff --git a/frest/manage/utils.py b/frest/manage/utils.py
index 347d3f8..a364ae9 100644
--- a/frest/manage/utils.py
+++ b/frest/manage/utils.py
@@ -226,3 +226,25 @@ def create_app(name):
logging_arg("Create {}... ", f"scheme/{name}/routes.py")
create_routes(name, fields)
logging("OK", 3, "\n")
+
+
+def init_project(name):
+ logging_arg("Create {}... ", f"{name}/")
+ os.mkdir(f"{name}")
+ logging("OK", 3, "\n")
+
+ path = f"{name}/__init__.py"
+ logging_arg("Create {}... ", path)
+ open(path, "w").close()
+ logging("OK", 3, "\n")
+
+ paths = ["app", "database", "mail", "wsgi"]
+ for path in paths:
+ logging_arg("Create {}... ", f"{name}/{path}.py")
+ with open(os.path.join(TEMPLATE_PATH, f"{path}.txt")) as f:
+ text = "".join(f.readlines())
+
+ with open(f"{name}/{path}.py", "w") as f:
+ f.write(text)
+
+ logging("OK", 3, "\n")