Skip to content

Commit

Permalink
Import/export settings (or bootstrap with default config). By @phihos (
Browse files Browse the repository at this point in the history
  • Loading branch information
phihos authored Jun 5, 2021
1 parent 0862c82 commit 5192bd1
Show file tree
Hide file tree
Showing 17 changed files with 834 additions and 28 deletions.
26 changes: 24 additions & 2 deletions src/vorta/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from vorta.borg.create import BorgCreateThread
from vorta.borg.version import BorgVersionThread
from vorta.borg.break_lock import BorgBreakThread
from vorta.config import TEMP_DIR
from vorta.config import TEMP_DIR, PROFILE_BOOTSTRAP_FILE
from vorta.i18n import init_translations, translate
from vorta.models import BackupProfileModel, SettingsModel, cleanup_db
from vorta.qt_single_application import QtSingleApplication
Expand All @@ -19,6 +19,7 @@
from vorta.utils import borg_compat, parse_args
from vorta.views.main_window import MainWindow
from vorta.notifications import VortaNotifications
from vorta.profile_export import ProfileExport

logger = logging.getLogger(__name__)

Expand All @@ -40,7 +41,6 @@ class VortaApp(QtSingleApplication):
backup_progress_event = QtCore.pyqtSignal(str)

def __init__(self, args_raw, single_app=False):

super().__init__(APP_ID, args_raw)
args = parse_args()
if self.isRunning():
Expand All @@ -61,6 +61,9 @@ def __init__(self, args_raw, single_app=False):
self.scheduler = VortaScheduler(self)
self.setApplicationName("Vorta")

# Import profile from ~/.vorta-init.json or add empty "Default" profile.
self.bootstrap_profile()

# Prepare tray and main window
self.tray = TrayMenu(self)
self.main_window = MainWindow(self)
Expand Down Expand Up @@ -246,3 +249,22 @@ def break_lock(self, profile):
return
thread = BorgBreakThread(params['cmd'], params, parent=self)
thread.start()

def bootstrap_profile(self, bootstrap_file=PROFILE_BOOTSTRAP_FILE):
"""
Make sure there is at least one profile when first starting Vorta.
Will either import a profile placed in ~/.vorta-init.json
or add an empty "Default" profile.
"""
if bootstrap_file.is_file():
profile_export = ProfileExport.from_json(bootstrap_file)
profile = profile_export.to_db(overwrite_profile=True, overwrite_settings=True)
bootstrap_file.unlink()
notifier = VortaNotifications.pick()
notifier.deliver(self.tr('Profile import successful!'),
self.tr('Profile {} imported.').format(profile.name),
level='info')
logger.info('Profile {} imported.'.format(profile.name))
if BackupProfileModel.select().count() == 0:
default_profile = BackupProfileModel(name='Default')
default_profile.save()
54 changes: 54 additions & 0 deletions src/vorta/assets/UI/exportwindow.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>555</width>
<height>78</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="storePassword">
<property name="toolTip">
<string>If set, sharing this file with others will disclose your borg passphrase. Use with caution!</string>
</property>
<property name="text">
<string>Include borg passphrase in export</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
84 changes: 84 additions & 0 deletions src/vorta/assets/UI/importwindow.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>551</width>
<height>134</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Borg passphrase:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="repoPassword">
<property name="inputMask">
<string/>
</property>
<property name="text">
<string/>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string/>
</property>
<property name="clearButtonEnabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="overwriteExistingProfile">
<property name="text">
<string>Overwrite existing profile</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="overwriteExistingSettings">
<property name="text">
<string>Overwrite existing settings</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
13 changes: 13 additions & 0 deletions src/vorta/assets/UI/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<height>16</height>
</size>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
</property>
</widget>
</item>
<item>
Expand All @@ -88,6 +91,16 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="profileExportButton">
<property name="toolTip">
<string>Export Profile</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="profileDeleteButton">
<property name="toolTip">
Expand Down
1 change: 1 addition & 0 deletions src/vorta/assets/icons/file-import-solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/vorta/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path
import appdirs

APP_NAME = 'Vorta'
Expand All @@ -9,6 +10,7 @@
LOG_DIR = dirs.user_log_dir
CACHE_DIR = dirs.user_cache_dir
TEMP_DIR = os.path.join(CACHE_DIR, "tmp")
PROFILE_BOOTSTRAP_FILE = Path.home() / '.vorta-init.json'

if not os.path.exists(SETTINGS_DIR):
os.makedirs(SETTINGS_DIR)
Expand Down
4 changes: 0 additions & 4 deletions src/vorta/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,6 @@ def init_db(con=None):
db.create_tables([RepoModel, RepoPassword, BackupProfileModel, SourceFileModel, SettingsModel,
ArchiveModel, WifiSettingModel, EventLogModel, SchemaVersion])

if BackupProfileModel.select().count() == 0:
default_profile = BackupProfileModel(name='Default')
default_profile.save()

# Delete old log entries after 3 months.
three_months_ago = datetime.now() - timedelta(days=180)
EventLogModel.delete().where(EventLogModel.start_time < three_months_ago)
Expand Down
Loading

0 comments on commit 5192bd1

Please sign in to comment.