Check if system is configured
This commit is contained in:
parent
e7d9fcd1d5
commit
40c560f750
|
|
@ -1,7 +1,7 @@
|
|||
#!./venv/bin/python
|
||||
import argparse, os
|
||||
import app
|
||||
from utils import is_root
|
||||
from utils import is_root, check_system_configuration
|
||||
from templates import Languanges
|
||||
|
||||
from db.models import Environment, Snapshot
|
||||
|
|
@ -14,17 +14,17 @@ parser = argparse.ArgumentParser(prog="Danix", add_help=True)
|
|||
|
||||
usages = parser.add_argument_group("usages")
|
||||
|
||||
usages.add_argument("-l", "--list", action="store_true" , help="List all environments avaliable", required=False)
|
||||
usages.add_argument("-sl", "--snapshotlist", action="store_true", help="List all subsystems snapshots", required=False)
|
||||
usages.add_argument("-l" , "--list" , action="store_true" , help="List all environments avaliable", required=False)
|
||||
usages.add_argument("-sl", "--snapshotlist", action="store_true" , help="List all subsystems snapshots", required=False)
|
||||
|
||||
usages.add_argument("-S", "--start", help="Start system environment", required=False)
|
||||
usages.add_argument("-s", "--stop", help="Stop system environment", required=False)
|
||||
usages.add_argument("-r", "--rm", help="Remove system environment", required=False)
|
||||
usages.add_argument("-S", "--start" , help="Start system environment", required=False)
|
||||
usages.add_argument("-s", "--stop" , help="Stop system environment", required=False)
|
||||
usages.add_argument("-r", "--rm" , help="Remove system environment", required=False)
|
||||
usages.add_argument("-n", "--navigate", help="Navigate inside the environment", required=False)
|
||||
|
||||
usages.add_argument("-sr", "--snapshotremove", help="Remove snapshot", required=False)
|
||||
usages.add_argument("-sc", "--snapshotcreate", help="Create snapshot", required=False)
|
||||
usages.add_argument("-sb", "--snapshotback", help="Back snapshot", required=False)
|
||||
usages.add_argument("-sb", "--snapshotback" , help="Back snapshot", required=False)
|
||||
|
||||
usages.add_argument("-o", "--option", choices=["clike", "java", "python", "ruby", "lua", "go", "ada"], required=False)
|
||||
|
||||
|
|
@ -39,62 +39,65 @@ languanges_and_softwares = {
|
|||
"go" : Languanges.Go(),
|
||||
"ada" : Languanges.Ada()
|
||||
}
|
||||
if check_system_configuration():
|
||||
if args.option:
|
||||
|
||||
if args.option:
|
||||
name = input("Please enter environment name: ")
|
||||
languanges_and_softwares.get(args.option).install(name, args.option)
|
||||
|
||||
name = input("Please enter environment name: ")
|
||||
languanges_and_softwares.get(args.option).install(name, args.option)
|
||||
if args.navigate:
|
||||
Environment.navigate(args.navigate)
|
||||
|
||||
if args.navigate:
|
||||
Environment.navigate(args.navigate)
|
||||
if args.start:
|
||||
Environment.start_environment(args.start)
|
||||
|
||||
if args.start:
|
||||
Environment.start_environment(args.start)
|
||||
if args.rm:
|
||||
user_confirm = input("Type 'y' to continue: ")
|
||||
|
||||
if args.rm:
|
||||
user_confirm = input("Type 'y' to continue: ")
|
||||
if user_confirm == 'y':
|
||||
environments = str(args.rm).split(" ")
|
||||
|
||||
if user_confirm == 'y':
|
||||
environments = str(args.rm).split(" ")
|
||||
for environment in environments:
|
||||
Environment.rm_environment(environment)
|
||||
|
||||
for environment in environments:
|
||||
Environment.rm_environment(environment)
|
||||
exit(0)
|
||||
print("🔴 [Danix]: System abort!")
|
||||
|
||||
exit(0)
|
||||
print("[Danix]: System abort!")
|
||||
if args.stop:
|
||||
Environment.stop_environment(args.stop)
|
||||
|
||||
if args.stop:
|
||||
Environment.stop_environment(args.stop)
|
||||
if args.snapshotcreate:
|
||||
user_confirm = input("Type 'y' to continue: ")
|
||||
|
||||
if args.snapshotcreate:
|
||||
user_confirm = input("Type 'y' to continue: ")
|
||||
if user_confirm == 'y':
|
||||
Snapshot.create(args.snapshotcreate)
|
||||
print("🔴 [Danix]: System abort!")
|
||||
|
||||
if user_confirm == 'y':
|
||||
Snapshot.create(args.snapshotcreate)
|
||||
print("[Danix]: System abort!")
|
||||
if args.list:
|
||||
Environment.list_environments()
|
||||
|
||||
if args.list:
|
||||
Environment.list_environments()
|
||||
if args.snapshotlist:
|
||||
Snapshot.list_snapshots()
|
||||
|
||||
if args.snapshotlist:
|
||||
Snapshot.list_snapshots()
|
||||
if args.snapshotback:
|
||||
user_confirm = input("Type 'y' to continue: ")
|
||||
|
||||
if args.snapshotback:
|
||||
user_confirm = input("Type 'y' to continue: ")
|
||||
if user_confirm == 'y':
|
||||
Snapshot.back_snapshot(args.snapshotback)
|
||||
print("🔴 [Danix]: System abort!")
|
||||
|
||||
if user_confirm == 'y':
|
||||
Snapshot.back_snapshot(args.snapshotback)
|
||||
print("[Danix]: System abort!")
|
||||
if args.snapshotremove:
|
||||
user_confirm = input("Type y to continue: ")
|
||||
|
||||
if args.snapshotremove:
|
||||
user_confirm = input("Type y to continue: ")
|
||||
if user_confirm == 'y':
|
||||
|
||||
if user_confirm == 'y':
|
||||
snapshots = str(args.snapshotremove).split(" ")
|
||||
|
||||
snapshots = str(args.snapshotremove).split(" ")
|
||||
for snapshot in snapshots:
|
||||
Snapshot.rm_snapshot(snapshot)
|
||||
exit(0)
|
||||
|
||||
for snapshot in snapshots:
|
||||
Snapshot.rm_snapshot(snapshot)
|
||||
exit(0)
|
||||
|
||||
print("[Danix]: System abort!")
|
||||
print("🔴 [Danix]: System abort!")
|
||||
else:
|
||||
print("🔴 Danix system is not configured!")
|
||||
print("Plase run 'make config'")
|
||||
|
|
@ -19,6 +19,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||
env = environ.Env()
|
||||
|
||||
MAIN_DIR = f"{BASE_DIR}/danix"
|
||||
|
||||
environ.Env.read_env(os.path.join(MAIN_DIR, '.env'))
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
|
|
|
|||
|
|
@ -1,4 +1,26 @@
|
|||
import os
|
||||
from settings import MAIN_REPO, MAIN_DIR, BASE_DIR
|
||||
|
||||
def check_create_dir():
|
||||
mainrepo_resp = os.system(f"cd {MAIN_REPO} >/dev/null 2>&1")
|
||||
snapshot_resp = os.system(f" cd {MAIN_REPO}.snapshots >/dev/null 2>&1")
|
||||
|
||||
return True if mainrepo_resp == 0 and snapshot_resp == 0 else False
|
||||
|
||||
def check_create_db():
|
||||
return True if os.system(f"cat {MAIN_DIR}/db/db.sqlite3 >/dev/null 2>&1") == 0 else False
|
||||
|
||||
def check_create_dotenv():
|
||||
return True if os.system(f"cat {BASE_DIR}/danix/.env >/dev/null 2>&1") == 0 else False
|
||||
|
||||
@staticmethod
|
||||
def check_system_configuration():
|
||||
|
||||
check_dir_resp = check_create_dir()
|
||||
check_db_resp = check_create_db()
|
||||
check_env_resp = check_create_dotenv()
|
||||
|
||||
return check_dir_resp and check_db_resp and check_env_resp
|
||||
|
||||
@staticmethod
|
||||
def print_footer():
|
||||
|
|
|
|||
Loading…
Reference in New Issue