forked from vikdevelop/SaveDesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsavedesktop
More file actions
69 lines (61 loc) · 3.21 KB
/
savedesktop
File metadata and controls
69 lines (61 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/python3
import os, sys, shutil, argparse
from pathlib import Path
from datetime import date
flatpak = os.path.exists("/.flatpak-info")
snap = os.environ.get('SNAP_NAME', '') == 'savedesktop'
# Cache directory
CACHE = f"{Path.home()}/.var/app/io.github.vikdevelop.SaveDesktop/cache/tmp" if flatpak else f"{os.getenv('SNAP_USER_COMMON')}/.cache/tmp" if snap else f"{Path.home()}/.cache/io.github.vikdevelop.SaveDesktop"
# Init dir for loading the Python scripts
init_dir = "/app" if flatpak else f"{os.getenv('SNAP')}/usr" if snap else f"{Path.home()}/.local/share/savedesktop/src"
sys.path.append(init_dir)
# Command-line arguments
parser = argparse.ArgumentParser()
parser.add_argument("--background", action="store_true", help="Start periodic saving")
parser.add_argument("--sync", action="store_true", help="Start synchronization")
parser.add_argument("--save-now", action="store_true", help="Save a configuration using UI parameters such as periodic saving folder, file name format and password for encryption.")
parser.add_argument("--save-without-archive", type=str, help="Save the configuration without an archive", dest="FOLDER_PATH")
parser.add_argument("--import-config", help="Import a configuration from a file (*.sd.zip or *.sd.tar.gz) or folder", type=str, dest="CFG_ARCHIVE_PATH")
cmd = parser.parse_args()
# Run Python scripts from the listed command-line arguments
if cmd.background: # start periodic saving
from periodic_saving import PeriodicBackups
pb = PeriodicBackups()
pb.run(None)
exit()
elif cmd.sync: # sync a desktop configuration
from synchronization import Syncing
exit()
elif cmd.save_now: # save a configuration using UI parameters
from periodic_saving import PeriodicBackups
pb = PeriodicBackups()
pb.run(now=True)
exit()
elif cmd.FOLDER_PATH: # save a configuration without an archive
folder_path = cmd.FOLDER_PATH
os.makedirs(f"{CACHE}/save_config", exist_ok=True)
os.chdir(f"{CACHE}/save_config")
os.system(f"python3 {init_dir}/config.py --save")
print(f"moving the configuration folder to the {folder_path} folder")
os.system(f"echo > {CACHE}/save_config/SELECT_THIS_FILE_TO_IMPORT_CFG && mv {CACHE}/save_config '{cmd.FOLDER_PATH}/configuration_{date.today()}'")
elif cmd.CFG_ARCHIVE_PATH: # import a configuration from a file, or folder
file_path = cmd.CFG_ARCHIVE_PATH
if not os.path.exists(file_path):
print(f"File not found: {file_path}")
exit(1)
shutil.rmtree(os.path.join(CACHE, "import_config"), ignore_errors=True)
os.makedirs(os.path.join(CACHE, "import_config"), exist_ok=True)
os.chdir(os.path.join(CACHE, "import_config"))
if file_path.endswith('.sd.zip'):
os.system(f"unzip {file_path}")
elif file_path.endswith('.sd.tar.gz'):
os.system(f"tar -xf {file_path}")
elif os.path.exists(f"{file_path}/.folder.sd"):
shutil.copytree(file_path, f"{CACHE}/import_config", dirs_exist_ok=True, ignore_dangling_symlinks=True)
else:
print("Unsupported file type. Use *.sd.zip, *.sd.tar.gz or folder which contains the \".folder.sd\" file.")
exit(1)
os.system(f"python3 {init_dir}/config.py --import_")
exit()
else: # show the app window
import main_window