Copy files and directories implemented
This commit is contained in:
parent
40c560f750
commit
4e8e8161c3
|
|
@ -3,6 +3,14 @@ from sh import du
|
|||
from settings import MAIN_REPO
|
||||
class Danix():
|
||||
|
||||
@staticmethod
|
||||
def copy(environent_is_first, filesystem_name, environment_dir, host_directory):
|
||||
|
||||
if environent_is_first:
|
||||
return os.system(f"cp -r {MAIN_REPO}{filesystem_name}/danixfs{environment_dir} {host_directory} >/dev/null 2>&1")
|
||||
else:
|
||||
return os.system(f"cp -r {host_directory} {MAIN_REPO}{filesystem_name}/danixfs{environment_dir} >/dev/null 2>&1")
|
||||
|
||||
@staticmethod
|
||||
def remove_snapshot(snapshot_name):
|
||||
return os.system(f"rm -r {MAIN_REPO}.snapshots/{snapshot_name} >/dev/null 2>&1")
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import settings
|
|||
from danixfs import Danix
|
||||
from datetime import datetime
|
||||
from settings import SNAPSHOT_LIMIT
|
||||
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 utils import separate, 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):
|
||||
|
|
@ -22,6 +22,34 @@ class Environment(models.Model):
|
|||
created = models.DateField(default=datetime.now())
|
||||
template = models.TextField(default="")
|
||||
|
||||
|
||||
@staticmethod
|
||||
def copy(path):
|
||||
|
||||
environent_is_first , environment_uuid, environment_dir, host_directory = separate(path)
|
||||
|
||||
if environment_uuid and environment_dir and host_directory:
|
||||
|
||||
environment = get_queryset_filtered(Environment, environment_uuid)
|
||||
filesystem_name = environment.first().filesystem_name
|
||||
|
||||
resp = Danix.copy(
|
||||
environent_is_first,
|
||||
filesystem_name,
|
||||
environment_dir,
|
||||
host_directory
|
||||
)
|
||||
|
||||
if check_equal_sentence(resp, 0):
|
||||
get_message("🟢 Elements copyed successfuly!", True, 0)
|
||||
else:
|
||||
get_message("🔴 Copy error!", True, 1)
|
||||
else:
|
||||
if environent_is_first:
|
||||
get_message(f"🔴 Syntax error or element exist in {host_directory}!", True, 1)
|
||||
else:
|
||||
get_message(f"🔴 Syntax error or path not exist in subsystem!", True, 1)
|
||||
|
||||
@staticmethod
|
||||
def navigate(filesystem_name):
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ usages.add_argument("-n", "--navigate", help="Navigate inside the en
|
|||
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("-c", "--copy" , help="Copy files and directories", required=False)
|
||||
|
||||
usages.add_argument("-o", "--option", choices=["clike", "java", "python", "ruby", "lua", "go", "ada"], required=False)
|
||||
|
||||
|
|
@ -98,6 +99,9 @@ if check_system_configuration():
|
|||
exit(0)
|
||||
|
||||
print("🔴 [Danix]: System abort!")
|
||||
|
||||
if args.copy:
|
||||
Environment.copy(args.copy)
|
||||
else:
|
||||
print("🔴 Danix system is not configured!")
|
||||
print("Plase run 'make config'")
|
||||
|
|
@ -1,6 +1,38 @@
|
|||
import os
|
||||
from settings import MAIN_REPO, MAIN_DIR, BASE_DIR
|
||||
|
||||
def separate(path):
|
||||
list_path = path.split(" ")
|
||||
|
||||
environment_path = None
|
||||
environment_uuid = None
|
||||
host_path = None
|
||||
environent_is_first = False
|
||||
|
||||
if len(list_path) >= 2:
|
||||
|
||||
if list_path[1]:
|
||||
if str(list_path[1]).__contains__(":"):
|
||||
|
||||
environment_uuid = list_path[1].split(":")[0]
|
||||
environment_path = list_path[1].split(":")[1]
|
||||
|
||||
else:
|
||||
host_path = list_path[1]
|
||||
|
||||
if list_path[0]:
|
||||
|
||||
if str(list_path[0]).__contains__(":"):
|
||||
|
||||
environent_is_first = True
|
||||
environment_uuid = list_path[0].split(":")[0]
|
||||
environment_path = list_path[0].split(":")[1]
|
||||
|
||||
else:
|
||||
host_path = list_path[0]
|
||||
|
||||
return environent_is_first, environment_uuid, environment_path, host_path
|
||||
|
||||
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")
|
||||
|
|
|
|||
Loading…
Reference in New Issue