Check if system is configured

This commit is contained in:
Vinicius Silva 2023-05-18 19:39:49 -03:00
parent e7d9fcd1d5
commit 40c560f750
3 changed files with 78 additions and 52 deletions

View File

@ -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
@ -39,7 +39,7 @@ 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: ") name = input("Please enter environment name: ")
@ -61,7 +61,7 @@ if args.rm:
Environment.rm_environment(environment) Environment.rm_environment(environment)
exit(0) exit(0)
print("[Danix]: System abort!") print("🔴 [Danix]: System abort!")
if args.stop: if args.stop:
Environment.stop_environment(args.stop) Environment.stop_environment(args.stop)
@ -71,7 +71,7 @@ if args.snapshotcreate:
if user_confirm == 'y': if user_confirm == 'y':
Snapshot.create(args.snapshotcreate) Snapshot.create(args.snapshotcreate)
print("[Danix]: System abort!") print("🔴 [Danix]: System abort!")
if args.list: if args.list:
Environment.list_environments() Environment.list_environments()
@ -84,7 +84,7 @@ if args.snapshotback:
if user_confirm == 'y': if user_confirm == 'y':
Snapshot.back_snapshot(args.snapshotback) Snapshot.back_snapshot(args.snapshotback)
print("[Danix]: System abort!") print("🔴 [Danix]: System abort!")
if args.snapshotremove: if args.snapshotremove:
user_confirm = input("Type y to continue: ") user_confirm = input("Type y to continue: ")
@ -97,4 +97,7 @@ if args.snapshotremove:
Snapshot.rm_snapshot(snapshot) Snapshot.rm_snapshot(snapshot)
exit(0) exit(0)
print("[Danix]: System abort!") print("🔴 [Danix]: System abort!")
else:
print("🔴 Danix system is not configured!")
print("Plase run 'make config'")

View File

@ -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

View File

@ -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():