def initialise(self, data_dir=None, config_dir=None, filename=None, automatic_upgrades=True, debug_file=None, server_only=False): """The automatic upgrades of the database can be turned off by setting 'automatic_upgrade' to False. This is mainly useful for the testsuite. """ if debug_file: self.component_manager.debug_file = open(debug_file, "w", 0) self.register_components() # Upgrade from 1.x if needed. if automatic_upgrades: from mnemosyne.libmnemosyne.upgrades.upgrade1 import Upgrade1 Upgrade1(self.component_manager).backup_old_dir() if data_dir: self.config().data_dir = data_dir self.config().config_dir = data_dir if config_dir: self.config().config_dir = config_dir # Upgrade config if needed. if automatic_upgrades: from mnemosyne.libmnemosyne.upgrades.upgrade3 import Upgrade3 Upgrade3(self.component_manager).run() self.activate_components() register_component_manager(self.component_manager, self.config()["user_id"]) self.execute_user_plugin_dir() self.activate_saved_plugins() # If we are only running a sync or a review server, do not yet load # the database to prevent threading access issues. if server_only: if filename: self.config()["last_database"] = \ contract_path(filename, self.config().data_dir) return # Loading the database should come after all user plugins have been # loaded, since these could be needed e.g. for a card type in the # database. if filename and not filename.endswith(".db"): from mnemosyne.libmnemosyne.translator import _ self.main_widget().show_error(\ _("Command line argument is not a *.db file.")) sys.exit() self.load_database(filename) # Only now that the database is loaded, we can start writing log # events to it. This is why we log started_scheduler and # loaded_database manually. try: self.log().started_program() except Exception, e: if "lock" in str(e): from mnemosyne.libmnemosyne.translator import _ self.main_widget().show_error(\ _("Another copy of Mnemosyne is still running.") + "\n" + \ _("Continuing is impossible and will lead to data loss!")) sys.exit() else: raise e
def initialise(self, basedir, filename=None): self.component_manager = new_component_manager() self.register_components() self.config().basedir = basedir self.config().resource_limited = self.resource_limited self.activate_components() self.initialise_error_handling() register_component_manager(self.component_manager, self.config()["user_id"]) self.execute_user_plugin_dir() self.activate_saved_plugins() # Loading the database should come after all user plugins have been # loaded, since these could be needed e.g. for a card type in the # database. self.load_database(filename) self.log().started_program() self.log().started_scheduler() self.log().loaded_database() # Finally, we can activate the main widget and upgrade if needed. self.main_widget().activate() if self.upgrade_needed: from mnemosyne.libmnemosyne.upgrades.upgrade_database \ import UpgradeDatabase UpgradeDatabase(self.component_manager).run(self.file_to_upgrade)