Skip to content

Commit 1277457

Browse files
committed
Fix a bug with saving/importing cfg in CLI
1 parent acf6d9e commit 1277457

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

src/savedesktop.in

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import argparse
2626
import signal
2727
import locale
2828
import gettext
29+
from datetime import date
2930

3031
VERSION = '@VERSION@'
3132
pkgdatadir = '@pkgdatadir@'
@@ -46,7 +47,7 @@ parser = argparse.ArgumentParser()
4647
parser.add_argument("--background", action="store_true", help="Start periodic saving")
4748
parser.add_argument("--sync", action="store_true", help="Start synchronization")
4849
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.")
49-
parser.add_argument("--save-without-archive", type=str, help="Save the configuration without an archive", dest="FOLDER_PATH")
50+
parser.add_argument("--save-without-archive", type=str, help="Save the configuration without creating an archive", dest="FOLDER_PATH")
5051
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")
5152
cmd = parser.parse_args()
5253

@@ -62,22 +63,16 @@ elif cmd.save_now: # save a configuration using UI parameters
6263
pb = PeriodicBackups()
6364
pb.run(now=True)
6465
elif cmd.FOLDER_PATH: # save a configuration without an archive
65-
folder_path = cmd.FOLDER_PATH
66-
os.makedirs(f"{CACHE}/save_config", exist_ok=True)
67-
os.chdir(f"{CACHE}/save_config")
68-
os.system(f"python3 {init_dir}/config.py --save")
69-
print(f"moving the configuration folder to the {folder_path} folder")
70-
os.system(f"echo > {CACHE}/save_config/SELECT_THIS_FILE_TO_IMPORT_CFG && mv {CACHE}/save_config '{cmd.FOLDER_PATH}/configuration_{date.today()}'")
66+
archive_mode = "--create"
67+
archive_name = f"{cmd.FOLDER_PATH}/Configuration-{date.today()}"
68+
69+
os.makedirs(archive_name, exist_ok=True)
70+
subprocess.run([sys.executable, "-m", "savedesktop.core.archive", archive_mode, archive_name], env={**os.environ, "PYTHONPATH": f"{pkgdatadir}"})
7171
elif cmd.CFG_ARCHIVE_PATH: # import a configuration from a file, or folder
72-
file_path = cmd.CFG_ARCHIVE_PATH
7372
if not os.path.exists(file_path):
7473
print(f"File not found: {file_path}")
7574
exit(1)
7675

77-
shutil.rmtree(os.path.join(CACHE, "import_config"), ignore_errors=True)
78-
os.makedirs(os.path.join(CACHE, "import_config"), exist_ok=True)
79-
os.chdir(os.path.join(CACHE, "import_config"))
80-
8176
if file_path.endswith('.sd.zip'):
8277
os.system(f"unzip {file_path}")
8378
elif file_path.endswith('.sd.tar.gz'):
@@ -88,7 +83,9 @@ elif cmd.CFG_ARCHIVE_PATH: # import a configuration from a file, or folder
8883
print("Unsupported file type. Use *.sd.zip, *.sd.tar.gz or folder which contains the \".folder.sd\" file.")
8984
exit(1)
9085

91-
subprocess.run([sys.executable, "-m", "savedesktop.core.config", "--import_"], check=True, env={**os.environ, "PYTHONPATH": "/app/share/savedesktop"})
86+
archive_mode = "--unpack"
87+
archive_name = f"{cmd.CFG_ARCHIVE_PATH}"
88+
subprocess.run([sys.executable, "-m", "savedesktop.core.archive", archive_mode, archive_name], env={**os.environ, "PYTHONPATH": f"{pkgdatadir}"})
9289
else: # show the app window
9390
import gi
9491

0 commit comments

Comments
 (0)