def main(): args = parse_args() frozen_binary = getattr(sys, 'frozen', False) # Don't fork if user specifies it or when running from onedir app bundle on macOS. if hasattr(args, 'foreground') or (frozen_binary and sys.platform == 'darwin'): pass else: print('Forking to background (see system tray).') if os.fork(): sys.exit() # Init database sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db')) init_db(sqlite_db) # Send crashes to Sentry. if SettingsModel.get(key='send_sentry_reports').value: vorta.sentry.init() app = VortaApp(sys.argv, single_app=True) app.updater = get_updater() sys.exit(app.exec_())
def main(): args = parse_args() signal.signal(signal.SIGINT, signal.SIG_DFL) # catch ctrl-c and exit frozen_binary = getattr(sys, 'frozen', False) want_version = getattr(args, 'version', False) want_foreground = getattr(args, 'foreground', False) if want_version: print(f"Vorta {__version__}") sys.exit() # We assume that a frozen binary is a fat single-file binary made with # PyInstaller. These are not compatible with forking into background here: if not (want_foreground or frozen_binary): if os.fork(): sys.exit() init_logger(foreground=want_foreground) # Init database sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db')) init_db(sqlite_db) # Init app after database is available from vorta.application import VortaApp app = VortaApp(sys.argv, single_app=True) app.updater = get_updater() # Force fusion style on Linux if sys.platform.startswith('linux'): app.setStyle('Fusion') sys.exit(app.exec_())
def main(): args = parse_args() signal.signal(signal.SIGINT, signal.SIG_DFL) # catch ctrl-c and exit want_version = getattr(args, 'version', False) want_background = getattr(args, 'daemonize', False) if want_version: print(f"Vorta {__version__}") sys.exit() if want_background: if os.fork(): sys.exit() init_logger(background=want_background) # Init database sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db')) init_db(sqlite_db) # Init app after database is available from vorta.application import VortaApp app = VortaApp(sys.argv, single_app=True) app.updater = get_updater() sys.exit(app.exec_())
def main(): def exception_handler(type, value, tb): from traceback import format_exception from PyQt5.QtWidgets import QMessageBox logger.critical( "Uncaught exception, file a report at https://github.com/borgbase/vorta/issues/new", exc_info=(type, value, tb)) full_exception = ''.join(format_exception(type, value, tb)) title = trans_late('app', 'Fatal Error') error_message = trans_late( 'app', 'Uncaught exception, please file a report with this text at\n' 'https://github.com/borgbase/vorta/issues/new\n') if app: QMessageBox.critical( None, translate('app', title), translate('app', error_message) + full_exception) else: # Crashed before app startup, cannot translate sys.exit(1) sys.excepthook = exception_handler app = None args = parse_args() signal.signal(signal.SIGINT, signal.SIG_DFL) # catch ctrl-c and exit want_version = getattr(args, 'version', False) want_background = getattr(args, 'daemonize', False) if want_version: print(f"Vorta {__version__}") sys.exit() if want_background: if os.fork(): sys.exit() init_logger(background=want_background) # Init database sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db'), pragmas={ 'journal_mode': 'wal', }) init_db(sqlite_db) # Init app after database is available from vorta.application import VortaApp app = VortaApp(sys.argv, single_app=args.profile is None) app.updater = get_updater() sys.exit(app.exec())
def main(): # Send crashes to Sentry. if not os.environ.get('NO_SENTRY', False): vorta.sentry.init() # Init database sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db')) init_db(sqlite_db) app = VortaApp(sys.argv, single_app=True) app.updater = get_updater() sys.exit(app.exec_())
def main(): args = parse_args() frozen_binary = getattr(sys, 'frozen', False) want_foreground = getattr(args, 'foreground', False) # We assume that a frozen binary is a fat single-file binary made with # PyInstaller. These are not compatible with forking into background here: if not (want_foreground or frozen_binary): print('Forking to background (see system tray).') if os.fork(): sys.exit() init_logger(foreground=want_foreground) # Init database sqlite_db = peewee.SqliteDatabase(os.path.join(SETTINGS_DIR, 'settings.db')) init_db(sqlite_db) app = VortaApp(sys.argv, single_app=True) app.updater = get_updater() sys.exit(app.exec_())
def to_db(self, overwrite_profile=False, overwrite_settings=True): profile_schema = self._profile_dict['SchemaVersion']['version'] keyring = VortaKeyring.get_keyring() if SCHEMA_VERSION < profile_schema: raise VersionException() elif SCHEMA_VERSION > profile_schema: # Add model upgrading code here, only needed if not adding columns if profile_schema < 16: for sourcedir in self._profile_dict['SourceFileModel']: sourcedir['dir_files_count'] = -1 sourcedir['dir_size'] = -1 sourcedir['path_isdir'] = False existing_profile = None if overwrite_profile: existing_profile = BackupProfileModel.get_or_none(BackupProfileModel.name == self.name) if existing_profile: self._profile_dict['id'] = existing_profile.id if not overwrite_profile or not existing_profile: # Guarantee uniqueness of ids while BackupProfileModel.get_or_none(BackupProfileModel.id == self.id) is not None: self._profile_dict['id'] += 1 # Add suffix incase names are the same if BackupProfileModel.get_or_none(BackupProfileModel.name == self.name) is not None: suffix = 1 while BackupProfileModel.get_or_none(BackupProfileModel.name == f"{self.name}-{suffix}") is not None: suffix += 1 self._profile_dict['name'] = f"{self.name}-{suffix}" # Load existing repo or restore it if self._profile_dict['repo']: repo = RepoModel.get_or_none(RepoModel.url == self.repo_url) if repo is None: # Load repo from export repo = dict_to_model(RepoModel, self._profile_dict['repo']) repo.save(force_insert=True) self._profile_dict['repo'] = model_to_dict(repo) if self.repo_password: keyring.set_password('vorta-repo', self.repo_url, self.repo_password) del self._profile_dict['password'] # Delete and recreate the tables to clear them if overwrite_settings: db.drop_tables([SettingsModel, WifiSettingModel]) db.create_tables([SettingsModel, WifiSettingModel]) SettingsModel.insert_many(self._profile_dict['SettingsModel']).execute() WifiSettingModel.insert_many(self._profile_dict['WifiSettingModel']).execute() # Set the profile ids to be match new profile for source in self._profile_dict['SourceFileModel']: source['profile'] = self.id SourceFileModel.insert_many(self._profile_dict['SourceFileModel']).execute() # Delete added dictionaries to make it match BackupProfileModel del self._profile_dict['SettingsModel'] del self._profile_dict['SourceFileModel'] del self._profile_dict['WifiSettingModel'] del self._profile_dict['SchemaVersion'] # dict to profile new_profile = dict_to_model(BackupProfileModel, self._profile_dict) if overwrite_profile and existing_profile: force_insert = False else: force_insert = True new_profile.save(force_insert=force_insert) init_db() # rerun db init code to perform the same operations on the new as as on application boot return new_profile