Danix support new languanges
This commit is contained in:
parent
131693af0a
commit
e7d9fcd1d5
|
|
@ -1,8 +1,6 @@
|
|||
import uuid, os, settings, app
|
||||
import os, settings, app
|
||||
from sh import du
|
||||
from settings import MAIN_REPO
|
||||
from time import sleep
|
||||
|
||||
class Danix():
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -21,7 +19,7 @@ class Danix():
|
|||
else:
|
||||
return du(f'{MAIN_REPO}.snapshots/{snapshot_name}/{environment_name}.tar.gz','-ch').split('\n')[-2].split('\t')[0]
|
||||
except Exception:
|
||||
return "000M"
|
||||
return "00M"
|
||||
|
||||
@staticmethod
|
||||
def make_snapshot(filesystem_name, snapshot_name):
|
||||
|
|
@ -47,7 +45,7 @@ class Danix():
|
|||
return os.system(f"chroot {MAIN_REPO}{filesystem_uuid}/danixfs sh {MAIN_REPO}init.d/init.sh")
|
||||
|
||||
@staticmethod
|
||||
def build_environment(packages, filesystem_uuid):
|
||||
def build_environment(packages, config_comands, filesystem_uuid):
|
||||
filesystem = filesystem_uuid
|
||||
|
||||
os.system(f"mkdir /tmp/{filesystem}")
|
||||
|
|
@ -64,6 +62,8 @@ class Danix():
|
|||
for package in packages:
|
||||
os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs apk add {package}")
|
||||
|
||||
for command in config_comands:
|
||||
os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs {command}")
|
||||
|
||||
os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs apk add fish")
|
||||
os.system(f"chroot {MAIN_REPO}{filesystem}/danixfs apk add ruby")
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import settings
|
|||
from danixfs import Danix
|
||||
from datetime import datetime
|
||||
from settings import SNAPSHOT_LIMIT
|
||||
from utils import print_snapshot_list_header, print_footer, print_environment_list_header, is_unique_database_tuple, get_message, check_equal_sentence, check_not_equal_sentence
|
||||
from utils import get_size_in_mb_or_gb, print_snapshot_list_header, print_footer, print_environment_list_header, is_unique_database_tuple, get_message, check_equal_sentence, check_not_equal_sentence
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
def get_queryset_filtered(model, sub_attribute):
|
||||
|
|
@ -42,7 +42,7 @@ class Environment(models.Model):
|
|||
if not check_not_equal_sentence(resp, 0):
|
||||
|
||||
get_message(
|
||||
message=settings.ENV_GENERIC_ERROR,
|
||||
message=f"🔴 {settings.ENV_GENERIC_ERROR}",
|
||||
is_finishprogram=True,
|
||||
finish_status_code=1
|
||||
)
|
||||
|
|
@ -50,21 +50,21 @@ class Environment(models.Model):
|
|||
elif expression ^ (not environment_first.status):
|
||||
|
||||
get_message(
|
||||
message=settings.ENV_STOPPED_ERROR,
|
||||
message=f"🔴 {settings.ENV_STOPPED_ERROR}",
|
||||
is_finishprogram=True,
|
||||
finish_status_code=1
|
||||
)
|
||||
|
||||
else:
|
||||
get_message(
|
||||
message=settings.ENV_PATTERN_ERROR,
|
||||
message=f"🔴 {settings.ENV_PATTERN_ERROR}",
|
||||
is_finishprogram=True,
|
||||
finish_status_code=1
|
||||
)
|
||||
|
||||
except ValidationError:
|
||||
get_message(
|
||||
message=settings.ENV_PATTERN_ERROR,
|
||||
message=f"🔴 {settings.ENV_PATTERN_ERROR}",
|
||||
is_finishprogram=True,
|
||||
finish_status_code=1
|
||||
)
|
||||
|
|
@ -84,7 +84,7 @@ class Environment(models.Model):
|
|||
if check_equal_sentence(environment_count, 0):
|
||||
|
||||
get_message(
|
||||
message=settings.ENV_NOT_FOUND,
|
||||
message=f"🔴 {settings.ENV_NOT_FOUND}",
|
||||
is_finishprogram=True,
|
||||
finish_status_code=1
|
||||
)
|
||||
|
|
@ -93,21 +93,21 @@ class Environment(models.Model):
|
|||
environment.delete()
|
||||
|
||||
get_message(
|
||||
message=f"{settings.ENV_REMOVED} - {environment.filesystem_name}",
|
||||
message=f"🟢 {settings.ENV_REMOVED} - {environment.filesystem_name}",
|
||||
is_finishprogram=False,
|
||||
finish_status_code=-1
|
||||
)
|
||||
else:
|
||||
|
||||
get_message(
|
||||
message=settings.ENV_PATTERN_ERROR,
|
||||
message=f"🔴 {settings.ENV_PATTERN_ERROR}",
|
||||
is_finishprogram=True,
|
||||
finish_status_code=1
|
||||
)
|
||||
|
||||
except Exception:
|
||||
get_message(
|
||||
message=settings.ENV_NOT_FOUND,
|
||||
message=f"🔴 {settings.ENV_NOT_FOUND}",
|
||||
is_finishprogram=True,
|
||||
finish_status_code=1
|
||||
)
|
||||
|
|
@ -126,7 +126,7 @@ class Environment(models.Model):
|
|||
if check_equal_sentence(environment_counter, 0):
|
||||
|
||||
get_message(
|
||||
message=settings.ENV_NOT_FOUND,
|
||||
message=f"🔴 {settings.ENV_NOT_FOUND}",
|
||||
is_finishprogram=True,
|
||||
finish_status_code=1
|
||||
)
|
||||
|
|
@ -135,13 +135,13 @@ class Environment(models.Model):
|
|||
environment.save()
|
||||
|
||||
get_message(
|
||||
message=settings.ENV_STARTED,
|
||||
message=f"🟢 {settings.ENV_STARTED}",
|
||||
is_finishprogram=True,
|
||||
finish_status_code=1
|
||||
)
|
||||
else:
|
||||
get_message(
|
||||
message=settings.ENV_PATTERN_ERROR,
|
||||
message=f"🔴 {settings.ENV_PATTERN_ERROR}",
|
||||
is_finishprogram=True,
|
||||
finish_status_code=1
|
||||
)
|
||||
|
|
@ -164,16 +164,16 @@ class Environment(models.Model):
|
|||
|
||||
if check_equal_sentence(environment_counter, 0):
|
||||
|
||||
get_message(message=settings.ENV_NOT_FOUND, is_finishprogram=True, finish_status_code=1)
|
||||
get_message(message=f"🔴 {settings.ENV_NOT_FOUND}", is_finishprogram=True, finish_status_code=1)
|
||||
|
||||
environment.status = False
|
||||
environment.save()
|
||||
|
||||
get_message(message=settings.ENV_STOPPED, is_finishprogram=True, finish_status_code=1)
|
||||
get_message(message=f"🟢 {settings.ENV_STOPPED}", is_finishprogram=True, finish_status_code=1)
|
||||
|
||||
else:
|
||||
get_message(
|
||||
message=settings.ENV_PATTERN_ERROR,
|
||||
message=f"🔴 {settings.ENV_PATTERN_ERROR}",
|
||||
is_finishprogram=True,
|
||||
finish_status_code=1
|
||||
)
|
||||
|
|
@ -197,13 +197,7 @@ class Environment(models.Model):
|
|||
|
||||
size_str = str(Danix.get_size(environment.filesystem_name, None))
|
||||
|
||||
size = int(size_str.replace("M",""))
|
||||
size_str = size_str.replace("M","MB")
|
||||
|
||||
if size >= 1000:
|
||||
size_str = f"{round(size/1000, 1)}G"
|
||||
elif size <= 100:
|
||||
size_str = size_str + " "
|
||||
size_str = get_size_in_mb_or_gb(size_str)
|
||||
|
||||
print(f"| {name[0:11]}{(11-len(name)) * '.'} {template}{(6-len(template)) * ' '} {environment.created} {environment.filesystem_name} Alpine {status_icon} {size_str} |")
|
||||
|
||||
|
|
@ -238,22 +232,22 @@ class Snapshot(models.Model):
|
|||
|
||||
Snapshot.objects.get(snapshot_name=snapshot.snapshot_name).delete()
|
||||
|
||||
get_message(message=f"Snapshot removed successfully - {snapshot.snapshot_name}", is_finishprogram=False, finish_status_code=-1)
|
||||
get_message(message=f"🟢 Snapshot removed successfully - {snapshot.snapshot_name}", is_finishprogram=False, finish_status_code=-1)
|
||||
|
||||
else:
|
||||
get_message(message="Error: Snapshot can not remove", is_finishprogram=True, finish_status_code=1)
|
||||
get_message(message="🔴 Error: Snapshot can not remove", is_finishprogram=True, finish_status_code=1)
|
||||
else:
|
||||
get_message(message="Snapshot does not exist!", is_finishprogram=True, finish_status_code=1)
|
||||
get_message(message="🔴 Snapshot does not exist!", is_finishprogram=True, finish_status_code=1)
|
||||
|
||||
else:
|
||||
get_message(
|
||||
message=settings.ENV_PATTERN_ERROR,
|
||||
message=f"🔴 {settings.ENV_PATTERN_ERROR}",
|
||||
is_finishprogram=True,
|
||||
finish_status_code=1
|
||||
)
|
||||
|
||||
except ValidationError:
|
||||
get_message(message="Snapshot does not exist!", is_finishprogram=True, finish_status_code=1)
|
||||
get_message(message="🔴 Snapshot does not exist!", is_finishprogram=True, finish_status_code=1)
|
||||
|
||||
@staticmethod
|
||||
def back_snapshot(snapshot_name):
|
||||
|
|
@ -271,17 +265,17 @@ class Snapshot(models.Model):
|
|||
resp = Danix.back_snapshot(filesystem_name, snapshot.snapshot_name)
|
||||
|
||||
if check_equal_sentence(resp, 0):
|
||||
get_message(message="Snapshot roll back successfully!", is_finishprogram=True, finish_status_code=0)
|
||||
get_message(message="🟢 Snapshot roll back successfully!", is_finishprogram=True, finish_status_code=0)
|
||||
|
||||
get_message(message="Error: Snapshot can not back", is_finishprogram=True, finish_status_code=1)
|
||||
get_message(message="🔴 Error: Snapshot can not back", is_finishprogram=True, finish_status_code=1)
|
||||
|
||||
get_message(message="Error: Environment was removed!", is_finishprogram=True, finish_status_code=1)
|
||||
get_message(message="🔴 Error: Environment was removed!", is_finishprogram=True, finish_status_code=1)
|
||||
|
||||
get_message(message="Snapshot does not exist!", is_finishprogram=True, finish_status_code=1)
|
||||
get_message(message="🔴 Snapshot does not exist!", is_finishprogram=True, finish_status_code=1)
|
||||
|
||||
except ValidationError:
|
||||
|
||||
get_message(message="Snapshot does not exist!", is_finishprogram=True, finish_status_code=1)
|
||||
get_message(message="🔴 Snapshot does not exist!", is_finishprogram=True, finish_status_code=1)
|
||||
|
||||
@staticmethod
|
||||
def create(subsystem_name):
|
||||
|
|
@ -298,7 +292,7 @@ class Snapshot(models.Model):
|
|||
snapshots = Snapshot.objects.filter(environment_id=environment_id)
|
||||
|
||||
if snapshots.count() >= int(SNAPSHOT_LIMIT):
|
||||
get_message(message="Snapshot limit exceeded! Please remove 1 snapshot to continue!", is_finishprogram=True, finish_status_code=1)
|
||||
get_message(message="🟠 Snapshot limit exceeded! Please remove 1 snapshot to continue!", is_finishprogram=True, finish_status_code=1)
|
||||
else:
|
||||
|
||||
for snapshot in snapshots:
|
||||
|
|
@ -317,7 +311,7 @@ class Snapshot(models.Model):
|
|||
resp = Danix.make_snapshot(environment.filesystem_name, snapshot_name)
|
||||
|
||||
if check_equal_sentence(resp, 0):
|
||||
print("Snapshot created successfully")
|
||||
print("🟢 Snapshot created successfully")
|
||||
print(f"Snapshot name {snapshot_name}\n")
|
||||
print(f"======================================")
|
||||
print(f"Environment size: {Danix.get_size(environment.filesystem_name, None)}B")
|
||||
|
|
@ -327,7 +321,7 @@ class Snapshot(models.Model):
|
|||
else:
|
||||
|
||||
Snapshot.objects.get(snapshot_name=snapshot_name,environment_id=environment).delete()
|
||||
print("Snapshot create error!")
|
||||
print("🔴 Snapshot create error!")
|
||||
exit(1)
|
||||
else:
|
||||
|
||||
|
|
@ -338,7 +332,7 @@ class Snapshot(models.Model):
|
|||
)
|
||||
|
||||
except Exception:
|
||||
get_message(message="Snapshot create error: Environment does not exist!", is_finishprogram=True, finish_status_code=1)
|
||||
get_message(message="🔴 Snapshot create error: Environment does not exist!", is_finishprogram=True, finish_status_code=1)
|
||||
|
||||
@staticmethod
|
||||
def list_snapshots():
|
||||
|
|
@ -358,19 +352,12 @@ class Snapshot(models.Model):
|
|||
environment_name = Environment.objects.filter(id=snapshot.environment_id.id).first().filesystem_name
|
||||
size_str = str(Danix.get_size(environment_name, name))
|
||||
|
||||
size = int(size_str.replace("M",""))
|
||||
|
||||
size_str = size_str.replace("M","MB")
|
||||
|
||||
if size >= 1000:
|
||||
size_str = f"{round(size/1000, 1)}G"
|
||||
elif size <= 100:
|
||||
size_str = size_str + " "
|
||||
size_str = get_size_in_mb_or_gb(size_str)
|
||||
|
||||
else:
|
||||
|
||||
environment_name = f'Environment Removed 🔴{14*" "}'
|
||||
size = "---"
|
||||
size_str = "-----"
|
||||
|
||||
print(f"| {name} {environment_name} {snapshot.created} {lastsnapshot_icon} {size_str} |")
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ usages.add_argument("-sr", "--snapshotremove", help="Remove snapshot", requ
|
|||
usages.add_argument("-sc", "--snapshotcreate", help="Create snapshot", required=False)
|
||||
usages.add_argument("-sb", "--snapshotback", help="Back snapshot", required=False)
|
||||
|
||||
usages.add_argument("-o", "--option", choices=["clike", "java", "python", "ruby"], required=False)
|
||||
usages.add_argument("-o", "--option", choices=["clike", "java", "python", "ruby", "lua", "go", "ada"], required=False)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
|
@ -34,7 +34,10 @@ languanges_and_softwares = {
|
|||
"clike" : Languanges.CLike(),
|
||||
"java" : Languanges.Java(),
|
||||
"python" : Languanges.Python(),
|
||||
#"ruby" : Languanges.Ruby()
|
||||
"ruby" : Languanges.Ruby(),
|
||||
"lua" : Languanges.Lua(),
|
||||
"go" : Languanges.Go(),
|
||||
"ada" : Languanges.Ada()
|
||||
}
|
||||
|
||||
if args.option:
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class Essentials():
|
|||
class Template():
|
||||
|
||||
@staticmethod
|
||||
def install(packages, environment_name, template):
|
||||
def install(packages, environment_name, config_commands, template):
|
||||
|
||||
filesystem_name = uuid.uuid4()
|
||||
|
||||
|
|
@ -28,8 +28,7 @@ class Template():
|
|||
joined_packages = Template.menu(packages)
|
||||
|
||||
Environment.set_active(filesystem_name)
|
||||
Danix.build_environment(joined_packages, filesystem_name)
|
||||
|
||||
Danix.build_environment(joined_packages, config_commands, filesystem_name)
|
||||
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -42,12 +41,20 @@ class Template():
|
|||
|
||||
print('Select essentials packages:')
|
||||
print(f'Example: 1 2 to install {packages[0]}, {packages[1]}')
|
||||
|
||||
packages_selected = input()
|
||||
|
||||
list_selected_packages = []
|
||||
|
||||
for pos in packages_selected.split(" "):
|
||||
list_selected_packages.append(packages[int(pos)-1])
|
||||
try:
|
||||
|
||||
for pos in packages_selected.split(" "):
|
||||
list_selected_packages.append(packages[int(pos)-1])
|
||||
|
||||
except Exception:
|
||||
|
||||
print("🔴 Invalid option: Please select a valid menu option!\n")
|
||||
Template.languange_menu(packages)
|
||||
|
||||
return list_selected_packages
|
||||
|
||||
|
|
@ -69,8 +76,14 @@ class Template():
|
|||
|
||||
list_essentials_packages = []
|
||||
|
||||
for pos in essentials_packages_selected.split(" "):
|
||||
list_essentials_packages.append(essentials_packages[int(pos)-1])
|
||||
try:
|
||||
|
||||
for pos in essentials_packages_selected.split(" "):
|
||||
list_essentials_packages.append(essentials_packages[int(pos)-1])
|
||||
|
||||
except Exception:
|
||||
print("🔴 Invalid option: Please select a valid menu option!\n")
|
||||
Template.essentials_menu()
|
||||
|
||||
return list_essentials_packages
|
||||
|
||||
|
|
@ -81,22 +94,70 @@ class Template():
|
|||
class Languanges():
|
||||
class Python():
|
||||
|
||||
packages = ["python3", "py3-pip"]
|
||||
packages = ["python3 py3-pip", "python3"]
|
||||
config_commands = []
|
||||
|
||||
def install(self, environment_name, template):
|
||||
|
||||
Template.install(self.packages, environment_name, template)
|
||||
Template.install(self.packages, environment_name, self.config_commands, template)
|
||||
|
||||
class CLike():
|
||||
|
||||
packages = ["gcc", "g++", "clang", "rust cargo"]
|
||||
config_commands = []
|
||||
|
||||
def install(self, environment_name, template):
|
||||
Template.install(self.packages, environment_name, template)
|
||||
Template.install(self.packages, environment_name, self.config_commands, template)
|
||||
|
||||
class Java():
|
||||
|
||||
packages = ["openjdk8", "openjdk11", "openjdk17"]
|
||||
config_commands = []
|
||||
|
||||
def install(self, environment_name, template):
|
||||
Template.install(self.packages, environment_name, template)
|
||||
Template.install(self.packages, environment_name, self.config_commands,template)
|
||||
|
||||
class Ruby():
|
||||
packages = ["ruby", "ruby-full"]
|
||||
config_commands = []
|
||||
|
||||
def install(self, environment_name, template):
|
||||
Template.install(self.packages, environment_name, self.config_commands, template)
|
||||
|
||||
|
||||
class Lua():
|
||||
|
||||
packages = ["lua5.3", "lua5.2"]
|
||||
config_commands = []
|
||||
|
||||
def install(self, environment_name, template):
|
||||
|
||||
Template.install(self.packages, environment_name, self.config_commands, template)
|
||||
|
||||
class Ada():
|
||||
|
||||
packages = ["gcc gcc-gnat", "gcc", "gcc-gnat"]
|
||||
config_commands = []
|
||||
|
||||
def install(self, environment_name, template):
|
||||
|
||||
Template.install(self.packages, environment_name, self.config_commands, template)
|
||||
|
||||
|
||||
class Go():
|
||||
|
||||
packages = ["go", "musl-dev go"]
|
||||
config_commands = []
|
||||
|
||||
config_commands = [
|
||||
"export GOPATH=/root/go >/dev/null 2>&1",
|
||||
"export PATH=${GOPATH}/bin:/usr/local/go/bin:$PATH >/dev/null 2>&1",
|
||||
"export GOBIN=$GOROOT/bin >/dev/null 2>&1",
|
||||
"mkdir -p ${GOPATH}/src ${GOPATH}/bin >/dev/null 2>&1",
|
||||
"export GO111MODULE=on >/dev/null 2>&1",
|
||||
"export GOCACHE=/root/go/cache >/dev/null 2>&1"
|
||||
]
|
||||
|
||||
def install(self, environment_name, template):
|
||||
Template.install(self.packages, environment_name, self.config_commands, template)
|
||||
|
||||
|
|
@ -4,6 +4,24 @@ import os
|
|||
def print_footer():
|
||||
print("================================================================================================================================================")
|
||||
|
||||
@staticmethod
|
||||
def get_size_in_mb_or_gb(size_str):
|
||||
|
||||
try:
|
||||
|
||||
size = int(size_str.replace("M","").replace(",","."))
|
||||
|
||||
if size >= 1000:
|
||||
|
||||
return f"{round(size/1000, 1)}GB"
|
||||
elif size <= 100:
|
||||
|
||||
return size_str + "B "
|
||||
|
||||
except Exception:
|
||||
return size_str.replace(",",".") + "B"
|
||||
|
||||
return size_str + "B"
|
||||
|
||||
@staticmethod
|
||||
def print_snapshot_list_header():
|
||||
|
|
|
|||
Loading…
Reference in New Issue