From bbc5b85b81c4116d8c6ef13b248a1000ba457163 Mon Sep 17 00:00:00 2001 From: samuel-w Date: Mon, 18 Jan 2021 02:13:39 -0600 Subject: [PATCH] Allow only one profile with --create. By @samuel-w (#744) --- src/vorta/application.py | 33 +++++++++++++-------------------- src/vorta/utils.py | 3 +-- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/vorta/application.py b/src/vorta/application.py index 01d7b3ab..a74fbd01 100644 --- a/src/vorta/application.py +++ b/src/vorta/application.py @@ -2,7 +2,6 @@ import logging import os import sys import time -import ast from PyQt5 import QtCore from PyQt5.QtWidgets import QMessageBox @@ -50,7 +49,7 @@ class VortaApp(QtSingleApplication): sys.exit() elif args.profile: self.sendMessage(f"create {args.profile}") - print('Creating backups using existing Vorta instance.') + print('Creating backup using existing Vorta instance.') sys.exit() elif args.profile: sys.exit('Vorta must already be running for --create to work') @@ -78,22 +77,17 @@ class VortaApp(QtSingleApplication): self.set_borg_details_action() self.installEventFilter(self) - def create_backups_cmdline(self, profiles): - self.completedProfiles = [] - self.validProfiles = [] - for profile_name in profiles: - profile = BackupProfileModel.get_or_none(name=profile_name) - if profile is not None: - if profile.repo is None: - logger.warning(f"Add a repository to {profile_name}") - continue - self.validProfiles.append(profile_name) - # Wait a bit in case something is running - while BorgThread.is_running(): - time.sleep(0.1) - self.create_backup_action(profile_id=profile.id) - else: - logger.warning(f"Invalid profile name {profile_name}") + def create_backups_cmdline(self, profile_name): + profile = BackupProfileModel.get_or_none(name=profile_name) + if profile is not None: + if profile.repo is None: + logger.warning(f"Add a repository to {profile_name}") + # Wait a bit in case something is running + while BorgThread.is_running(): + time.sleep(0.1) + self.create_backup_action(profile_id=profile.id) + else: + logger.warning(f"Invalid profile name {profile_name}") def eventFilter(self, source, event): if event.type() == QtCore.QEvent.ApplicationPaletteChange and isinstance(source, MainWindow): @@ -144,11 +138,10 @@ class VortaApp(QtSingleApplication): self.open_main_window_action() elif message.startswith("create"): message = message[7:] # Remove create - profiles = ast.literal_eval(message) # Safely parse string array if BorgThread.is_running(): logger.warning("Cannot run while backups are already running") else: - self.create_backups_cmdline(profiles) + self.create_backups_cmdline(message) def set_borg_details_action(self): params = BorgVersionThread.prepare() diff --git a/src/vorta/utils.py b/src/vorta/utils.py index 308679b7..568cdfdd 100644 --- a/src/vorta/utils.py +++ b/src/vorta/utils.py @@ -240,9 +240,8 @@ def parse_args(): help="Fork to background and don't open window on startup.") parser.add_argument( '--create', - nargs='+', dest='profile', - help='Create a backup in the background using the given profile(s). ' + help='Create a backup in the background using the given profile. ' 'Vorta must already be running for this to work.') return parser.parse_known_args()[0]