def __init__(self, file_name: str) -> None: super().__init__() self._logger = logging.getLogger(self._name) # Create python logger self._logger.setLevel(logging.DEBUG) self._show_once = set() # type: Set[str] # Do not try to save to the app dir as it may not be writeable or may not be the right # location to save the log file. Instead, try and save in the settings location since # that should be writeable. self.setFileName(Resources.getStoragePath(Resources.Resources, file_name)) VersionUpgradeManager.getInstance().registerIgnoredFile(file_name)
def __updateSerialized(self, serialized: str) -> str: configuration_type = "preferences" try: from UM.VersionUpgradeManager import VersionUpgradeManager version = VersionUpgradeManager.getInstance().getFileVersion(configuration_type, serialized) if version is not None: result = VersionUpgradeManager.getInstance().updateFilesData(configuration_type, version, [serialized], [""]) if result is not None: serialized = result.files_data[0] except: Logger.logException("d", "An exception occurred while trying to update the preferences.") return serialized
def __updateSerialized(self, serialized: str) -> str: configuration_type = self.getConfigurationTypeFromSerialized(serialized) version = self.getVersionFromSerialized(serialized) if configuration_type is not None and version is not None: from UM.VersionUpgradeManager import VersionUpgradeManager result = VersionUpgradeManager.getInstance().updateFilesData(configuration_type, version, [serialized], [""]) if result is not None: serialized = result.files_data[0] return serialized
def register(app): # add Mime type mime_type = MimeType( name = "application/x-ultimaker-material-profile", comment = "Ultimaker Material Profile", suffixes = [ "xml.fdm_material" ] ) MimeTypeDatabase.addMimeType(mime_type) # add upgrade version from cura.CuraApplication import CuraApplication from UM.VersionUpgradeManager import VersionUpgradeManager VersionUpgradeManager.getInstance().registerCurrentVersion( ("materials", XmlMaterialProfile.XmlMaterialProfile.Version * 1000000 + CuraApplication.SettingVersion), (CuraApplication.ResourceTypes.MaterialInstanceContainer, "application/x-ultimaker-material-profile") ) return {"version_upgrade": upgrader, "settings_container": XmlMaterialProfile.XmlMaterialProfile("default_xml_material_profile"), }
def _updateSerialized(cls, serialized: str, file_name: Optional[str] = None) -> str: configuration_type = cls.getConfigurationTypeFromSerialized(serialized) version = cls.getVersionFromSerialized(serialized) if configuration_type is not None and version is not None: from UM.VersionUpgradeManager import VersionUpgradeManager result = VersionUpgradeManager.getInstance().updateFilesData(configuration_type, version, [serialized], [file_name if file_name else ""]) if result is not None: serialized = result.files_data[0] return serialized
def register(app): # add Mime type mime_type = MimeType(name="application/x-ultimaker-material-profile", comment="Ultimaker Material Profile", suffixes=["xml.fdm_material"]) MimeTypeDatabase.addMimeType(mime_type) # add upgrade version from cura.CuraApplication import CuraApplication from UM.VersionUpgradeManager import VersionUpgradeManager VersionUpgradeManager.getInstance().registerCurrentVersion( ("materials", XmlMaterialProfile.XmlMaterialProfile.Version * 1000000 + CuraApplication.SettingVersion), (CuraApplication.ResourceTypes.MaterialInstanceContainer, "application/x-uranium-instancecontainer")) return { "version_upgrade": upgrader, "settings_container": XmlMaterialProfile.XmlMaterialProfile("default_xml_material_profile"), }
def _updateSerialized(cls, serialized: str, file_name: Optional[str] = None) -> str: configuration_type = cls.getConfigurationTypeFromSerialized(serialized) version = cls.getVersionFromSerialized(serialized) if configuration_type is not None and version is not None: from UM.VersionUpgradeManager import VersionUpgradeManager result = VersionUpgradeManager.getInstance().updateFilesData( configuration_type, version, [serialized], [file_name if file_name else ""]) if result is not None: serialized = result.files_data[0] return serialized
def getVersionFromSerialized(cls, serialized: str) -> Optional[int]: configuration_type = cls.getConfigurationTypeFromSerialized(serialized) if not configuration_type: Logger.log("d", "Could not get type from serialized.") return None # Get version version = None try: from UM.VersionUpgradeManager import VersionUpgradeManager version = VersionUpgradeManager.getInstance().getFileVersion(configuration_type, serialized) except Exception as e: Logger.log("d", "Could not get version from serialized: %s", e) return version
def _upgradeProfileVersion(self, serialized: str, profile_id: str, main_version: int, setting_version: int) -> List[Tuple[str, str]]: """Upgrade a serialized profile to the current profile format. :param serialized: The profile data to convert. :param profile_id: The name of the profile. :param source_version: The profile version of 'serialized'. :return: List of serialized profile strings and matching profile names. """ source_version = main_version * 1000000 + setting_version from UM.VersionUpgradeManager import VersionUpgradeManager results = VersionUpgradeManager.getInstance().updateFilesData( "quality_changes", source_version, [serialized], [profile_id]) if results is None: return [] serialized = results.files_data[0] parser = configparser.ConfigParser(interpolation=None) parser.read_string(serialized) if "general" not in parser: Logger.log("w", "Missing required section 'general'.") return [] new_source_version = results.version if int( new_source_version / 1000000 ) != InstanceContainer.Version or new_source_version % 1000000 != CuraApplication.SettingVersion: Logger.log("e", "Failed to upgrade profile [%s]", profile_id) if int(parser["general"]["version"]) != InstanceContainer.Version: Logger.log("e", "Failed to upgrade profile [%s]", profile_id) return [] return [(serialized, profile_id)]
def startSplashWindowPhase(self) -> None: super().startSplashWindowPhase() i18n_catalog = i18nCatalog("uranium") self.showSplashMessage( i18n_catalog.i18nc("@info:progress", "Initializing package manager...")) self._package_manager.initialize() # Read preferences here (upgrade won't work) to get the language in use, so the splash window can be shown in # the correct language. try: preferences_filename = Resources.getPath(Resources.Preferences, self._app_name + ".cfg") self._preferences.readFromFile(preferences_filename) except FileNotFoundError: Logger.log( "i", "Preferences file not found, ignore and use default language '%s'", self._default_language) signal.signal(signal.SIGINT, signal.SIG_DFL) # This is done here as a lot of plugins require a correct gl context. If you want to change the framework, # these checks need to be done in your <framework>Application.py class __init__(). self._configuration_error_message = ConfigurationErrorMessage( self, i18n_catalog.i18nc("@info:status", "Your configuration seems to be corrupt."), lifetime=0, title=i18n_catalog.i18nc("@info:title", "Configuration errors")) # Remove, install, and then loading plugins self.showSplashMessage( i18n_catalog.i18nc("@info:progress", "Loading plugins...")) # Remove and install the plugins that have been scheduled self._plugin_registry.initializeBeforePluginsAreLoaded() self._loadPlugins() self._plugin_registry.checkRequiredPlugins(self.getRequiredPlugins()) self.pluginsLoaded.emit() self.showSplashMessage( i18n_catalog.i18nc("@info:progress", "Updating configuration...")) with self._container_registry.lockFile(): VersionUpgradeManager.getInstance().upgrade() # Load preferences again because before we have loaded the plugins, we don't have the upgrade routine for # the preferences file. Now that we have, load the preferences file again so it can be upgraded and loaded. self.showSplashMessage( i18n_catalog.i18nc("@info:progress", "Loading preferences...")) try: preferences_filename = Resources.getPath(Resources.Preferences, self._app_name + ".cfg") with open(preferences_filename, "r", encoding="utf-8") as f: serialized = f.read() # This performs the upgrade for Preferences self._preferences.deserialize(serialized) self._preferences.setValue("general/plugins_to_remove", "") self._preferences.writeToFile(preferences_filename) except (FileNotFoundError, UnicodeDecodeError): Logger.log( "i", "The preferences file cannot be found or it is corrupted, so we will use default values" ) self.processEvents() # Force the configuration file to be written again since the list of plugins to remove maybe changed try: self._preferences_filename = Resources.getPath( Resources.Preferences, self._app_name + ".cfg") self._preferences.readFromFile(self._preferences_filename) except FileNotFoundError: Logger.log( "i", "The preferences file '%s' cannot be found, will use default values", self._preferences_filename) self._preferences_filename = Resources.getStoragePath( Resources.Preferences, self._app_name + ".cfg") # FIXME: This is done here because we now use "plugins.json" to manage plugins instead of the Preferences file, # but the PluginRegistry will still import data from the Preferences files if present, such as disabled plugins, # so we need to reset those values AFTER the Preferences file is loaded. self._plugin_registry.initializeAfterPluginsAreLoaded() # Check if we have just updated from an older version self._preferences.addPreference("general/last_run_version", "") last_run_version_str = self._preferences.getValue( "general/last_run_version") if not last_run_version_str: last_run_version_str = self._version last_run_version = Version(last_run_version_str) current_version = Version(self._version) if last_run_version < current_version: self._just_updated_from_old_version = True self._preferences.setValue("general/last_run_version", str(current_version)) self._preferences.writeToFile(self._preferences_filename) # Preferences: recent files self._preferences.addPreference("%s/recent_files" % self._app_name, "") file_names = self._preferences.getValue("%s/recent_files" % self._app_name).split(";") for file_name in file_names: if not os.path.isfile(file_name): continue self._recent_files.append(QUrl.fromLocalFile(file_name)) if not self.getIsHeadLess(): # Initialize System tray icon and make it invisible because it is used only to show pop up messages self._tray_icon = None if self._tray_icon_name: self._tray_icon = QIcon( Resources.getPath(Resources.Images, self._tray_icon_name)) self._tray_icon_widget = QSystemTrayIcon(self._tray_icon) self._tray_icon_widget.setVisible(False)
def startSplashWindowPhase(self) -> None: super().startSplashWindowPhase() self._package_manager.initialize() # Read preferences here (upgrade won't work) to get the language in use, so the splash window can be shown in # the correct language. try: preferences_filename = Resources.getPath(Resources.Preferences, self._app_name + ".cfg") self._preferences.readFromFile(preferences_filename) except FileNotFoundError: Logger.log("i", "Preferences file not found, ignore and use default language '%s'", self._default_language) signal.signal(signal.SIGINT, signal.SIG_DFL) # This is done here as a lot of plugins require a correct gl context. If you want to change the framework, # these checks need to be done in your <framework>Application.py class __init__(). i18n_catalog = i18nCatalog("uranium") self._configuration_error_message = ConfigurationErrorMessage(self, i18n_catalog.i18nc("@info:status", "Your configuration seems to be corrupt."), lifetime = 0, title = i18n_catalog.i18nc("@info:title", "Configuration errors") ) # Remove, install, and then loading plugins self.showSplashMessage(i18n_catalog.i18nc("@info:progress", "Loading plugins...")) # Remove and install the plugins that have been scheduled self._plugin_registry.initializeBeforePluginsAreLoaded() self._loadPlugins() self._plugin_registry.checkRequiredPlugins(self.getRequiredPlugins()) self.pluginsLoaded.emit() self.showSplashMessage(i18n_catalog.i18nc("@info:progress", "Updating configuration...")) with self._container_registry.lockFile(): VersionUpgradeManager.getInstance().upgrade() # Load preferences again because before we have loaded the plugins, we don't have the upgrade routine for # the preferences file. Now that we have, load the preferences file again so it can be upgraded and loaded. try: preferences_filename = Resources.getPath(Resources.Preferences, self._app_name + ".cfg") with open(preferences_filename, "r", encoding = "utf-8") as f: serialized = f.read() # This performs the upgrade for Preferences self._preferences.deserialize(serialized) self._preferences.setValue("general/plugins_to_remove", "") self._preferences.writeToFile(preferences_filename) except FileNotFoundError: Logger.log("i", "The preferences file cannot be found, will use default values") # Force the configuration file to be written again since the list of plugins to remove maybe changed self.showSplashMessage(i18n_catalog.i18nc("@info:progress", "Loading preferences...")) try: self._preferences_filename = Resources.getPath(Resources.Preferences, self._app_name + ".cfg") self._preferences.readFromFile(self._preferences_filename) except FileNotFoundError: Logger.log("i", "The preferences file '%s' cannot be found, will use default values", self._preferences_filename) self._preferences_filename = Resources.getStoragePath(Resources.Preferences, self._app_name + ".cfg") # FIXME: This is done here because we now use "plugins.json" to manage plugins instead of the Preferences file, # but the PluginRegistry will still import data from the Preferences files if present, such as disabled plugins, # so we need to reset those values AFTER the Preferences file is loaded. self._plugin_registry.initializeAfterPluginsAreLoaded() # Check if we have just updated from an older version self._preferences.addPreference("general/last_run_version", "") last_run_version_str = self._preferences.getValue("general/last_run_version") if not last_run_version_str: last_run_version_str = self._version last_run_version = Version(last_run_version_str) current_version = Version(self._version) if last_run_version < current_version: self._just_updated_from_old_version = True self._preferences.setValue("general/last_run_version", str(current_version)) self._preferences.writeToFile(self._preferences_filename) # Preferences: recent files self._preferences.addPreference("%s/recent_files" % self._app_name, "") file_names = self._preferences.getValue("%s/recent_files" % self._app_name).split(";") for file_name in file_names: if not os.path.isfile(file_name): continue self._recent_files.append(QUrl.fromLocalFile(file_name)) if not self.getIsHeadLess(): # Initialize System tray icon and make it invisible because it is used only to show pop up messages self._tray_icon = None if self._tray_icon_name: self._tray_icon = QIcon(Resources.getPath(Resources.Images, self._tray_icon_name)) self._tray_icon_widget = QSystemTrayIcon(self._tray_icon) self._tray_icon_widget.setVisible(False)