Allow only one profile with --create. By @samuel-w (#744)

This commit is contained in:
samuel-w 2021-01-18 02:13:39 -06:00 committed by GitHub
parent dae35bf4c7
commit bbc5b85b81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 22 deletions

View File

@ -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,16 +77,11 @@ 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:
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}")
continue
self.validProfiles.append(profile_name)
# Wait a bit in case something is running
while BorgThread.is_running():
time.sleep(0.1)
@ -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()

View File

@ -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]