Check if system is configured
This commit is contained in:
parent
e7d9fcd1d5
commit
40c560f750
107
danix/main.py
107
danix/main.py
|
|
@ -1,7 +1,7 @@
|
||||||
#!./venv/bin/python
|
#!./venv/bin/python
|
||||||
import argparse, os
|
import argparse, os
|
||||||
import app
|
import app
|
||||||
from utils import is_root
|
from utils import is_root, check_system_configuration
|
||||||
from templates import Languanges
|
from templates import Languanges
|
||||||
|
|
||||||
from db.models import Environment, Snapshot
|
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 = parser.add_argument_group("usages")
|
||||||
|
|
||||||
usages.add_argument("-l", "--list", action="store_true" , help="List all environments avaliable", 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("-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", "--start" , help="Start system environment", required=False)
|
||||||
usages.add_argument("-s", "--stop", help="Stop 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("-r", "--rm" , help="Remove system environment", required=False)
|
||||||
usages.add_argument("-n", "--navigate", help="Navigate inside the 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("-sr", "--snapshotremove", help="Remove snapshot", required=False)
|
||||||
usages.add_argument("-sc", "--snapshotcreate", help="Create 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)
|
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(),
|
"go" : Languanges.Go(),
|
||||||
"ada" : Languanges.Ada()
|
"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: ")
|
if args.navigate:
|
||||||
languanges_and_softwares.get(args.option).install(name, args.option)
|
Environment.navigate(args.navigate)
|
||||||
|
|
||||||
if args.navigate:
|
if args.start:
|
||||||
Environment.navigate(args.navigate)
|
Environment.start_environment(args.start)
|
||||||
|
|
||||||
if args.start:
|
if args.rm:
|
||||||
Environment.start_environment(args.start)
|
user_confirm = input("Type 'y' to continue: ")
|
||||||
|
|
||||||
if args.rm:
|
if user_confirm == 'y':
|
||||||
user_confirm = input("Type 'y' to continue: ")
|
environments = str(args.rm).split(" ")
|
||||||
|
|
||||||
if user_confirm == 'y':
|
|
||||||
environments = str(args.rm).split(" ")
|
|
||||||
|
|
||||||
for environment in environments:
|
|
||||||
Environment.rm_environment(environment)
|
|
||||||
|
|
||||||
exit(0)
|
|
||||||
print("[Danix]: System abort!")
|
|
||||||
|
|
||||||
if args.stop:
|
for environment in environments:
|
||||||
Environment.stop_environment(args.stop)
|
Environment.rm_environment(environment)
|
||||||
|
|
||||||
if args.snapshotcreate:
|
exit(0)
|
||||||
user_confirm = input("Type 'y' to continue: ")
|
print("🔴 [Danix]: System abort!")
|
||||||
|
|
||||||
if user_confirm == 'y':
|
if args.stop:
|
||||||
Snapshot.create(args.snapshotcreate)
|
Environment.stop_environment(args.stop)
|
||||||
print("[Danix]: System abort!")
|
|
||||||
|
|
||||||
if args.list:
|
|
||||||
Environment.list_environments()
|
|
||||||
|
|
||||||
if args.snapshotlist:
|
if args.snapshotcreate:
|
||||||
Snapshot.list_snapshots()
|
user_confirm = input("Type 'y' to continue: ")
|
||||||
|
|
||||||
if args.snapshotback:
|
if user_confirm == 'y':
|
||||||
user_confirm = input("Type 'y' to continue: ")
|
Snapshot.create(args.snapshotcreate)
|
||||||
|
print("🔴 [Danix]: System abort!")
|
||||||
|
|
||||||
if user_confirm == 'y':
|
if args.list:
|
||||||
Snapshot.back_snapshot(args.snapshotback)
|
Environment.list_environments()
|
||||||
print("[Danix]: System abort!")
|
|
||||||
|
|
||||||
if args.snapshotremove:
|
if args.snapshotlist:
|
||||||
user_confirm = input("Type y to continue: ")
|
Snapshot.list_snapshots()
|
||||||
|
|
||||||
if user_confirm == 'y':
|
|
||||||
|
|
||||||
snapshots = str(args.snapshotremove).split(" ")
|
if args.snapshotback:
|
||||||
|
user_confirm = input("Type 'y' to continue: ")
|
||||||
for snapshot in snapshots:
|
|
||||||
Snapshot.rm_snapshot(snapshot)
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
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 user_confirm == 'y':
|
||||||
|
|
||||||
|
snapshots = str(args.snapshotremove).split(" ")
|
||||||
|
|
||||||
|
for snapshot in snapshots:
|
||||||
|
Snapshot.rm_snapshot(snapshot)
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
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()
|
env = environ.Env()
|
||||||
|
|
||||||
MAIN_DIR = f"{BASE_DIR}/danix"
|
MAIN_DIR = f"{BASE_DIR}/danix"
|
||||||
|
|
||||||
environ.Env.read_env(os.path.join(MAIN_DIR, '.env'))
|
environ.Env.read_env(os.path.join(MAIN_DIR, '.env'))
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,26 @@
|
||||||
import os
|
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
|
@staticmethod
|
||||||
def print_footer():
|
def print_footer():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue