def _getUpgradeTasks(self) -> Iterator[UpgradeTask]: storage_path_prefixes = set() storage_path_prefixes.add(Resources.getConfigStoragePath()) storage_path_prefixes.add(Resources.getDataStoragePath()) # Make sure the types and paths are ordered so we always get the same results. self._storage_paths = collections.OrderedDict(sorted(self._storage_paths.items())) for key in self._storage_paths: self._storage_paths[key] = collections.OrderedDict(sorted(self._storage_paths[key].items())) # Use pattern: /^(pattern_a|pattern_b|pattern_c|...)$/ combined_regex_ignored_files = "^(" + "|".join(self._ignored_files) + ")" for old_configuration_type, version_storage_paths_dict in self._storage_paths.items(): for src_version, storage_paths in version_storage_paths_dict.items(): for prefix in storage_path_prefixes: for storage_path in storage_paths: path = os.path.join(prefix, storage_path) for configuration_file in self._getFilesInDirectory(path): # Get file version. Only add this upgrade task if the current file version matches with # the defined version that scans through this folder. if re.match(combined_regex_ignored_files, configuration_file): continue try: with open(os.path.join(path, configuration_file), "r", encoding = "utf-8") as f: file_version = self._get_version_functions[old_configuration_type](f.read()) if file_version != src_version: continue except: Logger.log("w", "Failed to get file version: %s, skip it", configuration_file) continue Logger.log("i", "Create upgrade task for configuration file [%s] with type [%s] and source version [%s]", configuration_file, old_configuration_type, file_version) yield UpgradeTask(storage_path = path, file_name = configuration_file, configuration_type = old_configuration_type)
def __init__(self, application, parent = None): super().__init__(parent) self._application = application self._container_registry = self._application.getContainerRegistry() self._plugin_registry = self._application.getPluginRegistry() #JSON files that keep track of all installed packages. self._user_package_management_file_path = None #type: str self._bundled_package_management_file_paths = [] #type: List[str] for search_path in Resources.getSearchPaths(): candidate_bundled_path = os.path.join(search_path, "bundled_packages.json") if os.path.exists(candidate_bundled_path): Logger.log("i", "Found bundled packages location: {location}".format(location = search_path)) self._bundled_package_management_file_paths.append(candidate_bundled_path) for search_path in (Resources.getDataStoragePath(), Resources.getConfigStoragePath()): candidate_user_path = os.path.join(search_path, "packages.json") if os.path.exists(candidate_user_path): self._user_package_management_file_path = candidate_user_path if self._user_package_management_file_path is None: #Doesn't exist yet. self._user_package_management_file_path = os.path.join(Resources.getDataStoragePath(), "packages.json") self._installation_dirs_dict = {"plugins": os.path.abspath(Resources.getStoragePath(Resources.Plugins))} # type: Dict[str, str] self._bundled_package_dict = {} # A dict of all bundled packages self._installed_package_dict = {} # A dict of all installed packages self._to_remove_package_set = set() # A set of packages that need to be removed at the next start self._to_install_package_dict = {} # A dict of packages that need to be installed at the next start
def upgrade(self): Logger.log("i", "Looking for old configuration files to upgrade.") upgraded = False #Did we upgrade something? paths = self._findShortestUpgradePaths() for old_configuration_type, storage_paths in self._storage_paths.items( ): for storage_path in storage_paths: storage_path_config = os.path.join( Resources.getConfigStoragePath(), storage_path) for configuration_file in self._getFilesInDirectory( storage_path_config, exclude_paths=["old", "cache"]): upgraded |= self._upgradeFile(storage_path_config, configuration_file, old_configuration_type, paths) storage_path_data = os.path.join( Resources.getDataStoragePath(), storage_path) #A second place to look. if storage_path_data != storage_path_config: for configuration_file in self._getFilesInDirectory( storage_path_data, exclude_paths=["old", "cache"]): upgraded |= self._upgradeFile(storage_path_data, configuration_file, old_configuration_type, paths) if upgraded: message = UM.Message(text=catalogue.i18nc( "@info:version-upgrade", "A configuration from an older version of {0} was imported.", UM.Application.getInstance().getApplicationName())) message.show() return upgraded
def __init__(self, parent=None): super().__init__(parent) self._application = Application.getInstance() self._container_registry = self._application.getContainerRegistry() self._plugin_registry = self._application.getPluginRegistry() #JSON files that keep track of all installed packages. self._user_package_management_file_path = None self._bundled_package_management_file_path = None for search_path in Resources.getSearchPaths(): candidate_bundled_path = os.path.join(search_path, "bundled_packages.json") if os.path.exists(candidate_bundled_path): self._bundled_package_management_file_path = candidate_bundled_path for search_path in (Resources.getDataStoragePath(), Resources.getConfigStoragePath()): candidate_user_path = os.path.join(search_path, "packages.json") if os.path.exists(candidate_user_path): self._user_package_management_file_path = candidate_user_path if self._user_package_management_file_path is None: #Doesn't exist yet. self._user_package_management_file_path = os.path.join( Resources.getDataStoragePath(), "packages.json") self._bundled_package_dict = {} # A dict of all bundled packages self._installed_package_dict = {} # A dict of all installed packages self._to_remove_package_set = set( ) # A set of packages that need to be removed at the next start self._to_install_package_dict = { } # A dict of packages that need to be installed at the next start
def _getUpgradeTasks(self) -> Iterator[UpgradeTask]: storage_path_prefixes = set() storage_path_prefixes.add(Resources.getConfigStoragePath()) storage_path_prefixes.add(Resources.getDataStoragePath()) # Make sure the types and paths are ordered so we always get the same results. self._storage_paths = collections.OrderedDict(sorted(self._storage_paths.items())) for key in self._storage_paths: self._storage_paths[key] = collections.OrderedDict(sorted(self._storage_paths[key].items())) combined_regex_ignored_files = "(" + ")|(".join(self._ignored_files) + ")" for old_configuration_type, version_storage_paths_dict in self._storage_paths.items(): for src_version, storage_paths in version_storage_paths_dict.items(): for prefix in storage_path_prefixes: for storage_path in storage_paths: path = os.path.join(prefix, storage_path) for configuration_file in self._getFilesInDirectory(path): # Get file version. Only add this upgrade task if the current file version matches with # the defined version that scans through this folder. if re.match(combined_regex_ignored_files, configuration_file): continue try: with open(os.path.join(path, configuration_file), "r", encoding = "utf-8") as f: file_version = self._get_version_functions[old_configuration_type](f.read()) if file_version != src_version: continue except: Logger.log("w", "Failed to get file version: %s, skip it", configuration_file) continue Logger.log("i", "Create upgrade task for configuration file [%s] with type [%s] and source version [%s]", configuration_file, old_configuration_type, file_version) yield UpgradeTask(storage_path = path, file_name = configuration_file, configuration_type = old_configuration_type)
def _backupAndStartClean(self): # backup the current cura directories and create clean ones from cura.CuraVersion import CuraVersion from UM.Resources import Resources # The early crash may happen before those information is set in Resources, so we need to set them here to # make sure that Resources can find the correct place. Resources.ApplicationIdentifier = "cura" Resources.ApplicationVersion = CuraVersion config_path = Resources.getConfigStoragePath() data_path = Resources.getDataStoragePath() cache_path = Resources.getCacheStoragePath() folders_to_backup = [] folders_to_remove = [] # only cache folder needs to be removed folders_to_backup.append(config_path) if data_path != config_path: folders_to_backup.append(data_path) # Only remove the cache folder if it's not the same as data or config if cache_path not in (config_path, data_path): folders_to_remove.append(cache_path) for folder in folders_to_remove: shutil.rmtree(folder, ignore_errors=True) for folder in folders_to_backup: base_name = os.path.basename(folder) root_dir = os.path.dirname(folder) import datetime date_now = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") idx = 0 file_name = base_name + "_" + date_now zip_file_path = os.path.join(root_dir, file_name + ".zip") while os.path.exists(zip_file_path): idx += 1 file_name = base_name + "_" + date_now + "_" + idx zip_file_path = os.path.join(root_dir, file_name + ".zip") try: # remove the .zip extension because make_archive() adds it zip_file_path = zip_file_path[:-4] shutil.make_archive(zip_file_path, "zip", root_dir=root_dir, base_dir=base_name) # remove the folder only when the backup is successful shutil.rmtree(folder, ignore_errors=True) # create an empty folder so Resources will not try to copy the old ones os.makedirs(folder, 0o0755, exist_ok=True) except Exception as e: Logger.logException("e", "Failed to backup [%s] to file [%s]", folder, zip_file_path) if not self.has_started: print("Failed to backup [%s] to file [%s]: %s", folder, zip_file_path, e) self.early_crash_dialog.close()
def __init__(self, application: "QtApplication", parent: Optional[QObject] = None) -> None: super().__init__(parent) self._application = application self._container_registry = self._application.getContainerRegistry() self._plugin_registry = self._application.getPluginRegistry() # JSON files that keep track of all installed packages. self._user_package_management_file_path = None # type: Optional[str] self._bundled_package_management_file_paths = [] # type: List[str] for search_path in Resources.getAllPathsForType( Resources.BundledPackages): if not os.path.isdir(search_path): continue # Load all JSON files that are located in the bundled_packages directory. for file_name in os.listdir(search_path): if not file_name.endswith(".json"): continue file_path = os.path.join(search_path, file_name) if not os.path.isfile(file_path): continue self._bundled_package_management_file_paths.append(file_path) Logger.log( "i", "Found bundled packages JSON file: {location}".format( location=file_path)) for search_path in (Resources.getDataStoragePath(), Resources.getConfigStoragePath()): candidate_user_path = os.path.join(search_path, "packages.json") if os.path.exists(candidate_user_path): self._user_package_management_file_path = candidate_user_path if self._user_package_management_file_path is None: # Doesn't exist yet. self._user_package_management_file_path = os.path.join( Resources.getDataStoragePath(), "packages.json") self._installation_dirs_dict = { "plugins": os.path.abspath(Resources.getStoragePath(Resources.Plugins)) } # type: Dict[str, str] self._bundled_package_dict = { } # type: Dict[str, Dict[str, Any]] # A dict of all bundled packages self._installed_package_dict = { } # type: Dict[str, Dict[str, Any]] # A dict of all installed packages self._to_remove_package_set = set( ) # type: Set[str] # A set of packages that need to be removed at the next start self._to_install_package_dict = { } # type: Dict[str, Dict[str, Any]] # A dict of packages that need to be installed at the next start self._dismissed_packages = set( ) # type: Set[str] # A set of packages that are dismissed by the user # There can be plugins that provide remote packages (and thus, newer / different versions for a package). self._available_package_versions = { } # type: Dict[str, Set[UMVersion]] self._packages_with_update_available = set() # type: Set[str]
def initializeBeforePluginsAreLoaded(self) -> None: config_path = Resources.getConfigStoragePath() # File to store plugin info, such as which ones to install/remove and which ones are disabled. # At this point we can load this here because we already know the actual Application name, so the directory name self._plugin_config_filename = os.path.join( os.path.abspath(config_path), "plugins.json") # type: str from UM.Settings.ContainerRegistry import ContainerRegistry container_registry = ContainerRegistry.getInstance() try: with container_registry.lockFile(): # Load the plugin info if exists if os.path.exists(self._plugin_config_filename): Logger.log("i", "Loading plugin configuration file '%s'", self._plugin_config_filename) with open(self._plugin_config_filename, "r", encoding="utf-8") as f: data = json.load(f) self._disabled_plugins = data["disabled"] self._plugins_to_install = data["to_install"] self._plugins_to_remove = data["to_remove"] except: Logger.logException( "e", "Failed to load plugin configuration file '%s'", self._plugin_config_filename) # Also load data from preferences, where the plugin info used to be saved preferences = self._application.getPreferences() disabled_plugins = preferences.getValue("general/disabled_plugins") disabled_plugins = disabled_plugins.split( ",") if disabled_plugins else [] for plugin_id in disabled_plugins: if plugin_id not in self._disabled_plugins: self._disabled_plugins.append(plugin_id) plugins_to_remove = preferences.getValue("general/plugins_to_remove") plugins_to_remove = plugins_to_remove.split( ",") if plugins_to_remove else [] for plugin_id in plugins_to_remove: if plugin_id not in self._plugins_to_remove: self._plugins_to_remove.append(plugin_id) # Remove plugins that need to be removed for plugin_id in self._plugins_to_remove: self._removePlugin(plugin_id) self._plugins_to_remove = [] if plugins_to_remove is not None: preferences.setValue("general/plugins_to_remove", "") self._savePluginData() # Install the plugins that need to be installed (overwrite existing) for plugin_id, plugin_info in self._plugins_to_install.items(): self._installPlugin(plugin_id, plugin_info["filename"]) self._plugins_to_install = dict() self._savePluginData()
def _getUpgradeTasks(self): storage_path_prefixes = set() storage_path_prefixes.add(Resources.getConfigStoragePath()) storage_path_prefixes.add(Resources.getDataStoragePath()) for old_configuration_type, storage_paths in self._storage_paths.items(): for prefix in storage_path_prefixes: for storage_path in storage_paths: path = os.path.join(prefix, storage_path) for configuration_file in self._getFilesInDirectory(path): yield UpgradeTask(storage_path = path, file_name = configuration_file, configuration_type = old_configuration_type)
def _getUpgradeTasks(self) -> Iterator[UpgradeTask]: storage_path_prefixes = set() storage_path_prefixes.add(Resources.getConfigStoragePath()) storage_path_prefixes.add(Resources.getDataStoragePath()) for old_configuration_type, storage_paths in self._storage_paths.items(): for prefix in storage_path_prefixes: for storage_path in storage_paths: path = os.path.join(prefix, storage_path) for configuration_file in self._getFilesInDirectory(path): yield UpgradeTask(storage_path = path, file_name = configuration_file, configuration_type = old_configuration_type)
def initializeBeforePluginsAreLoaded(self) -> None: config_path = Resources.getConfigStoragePath() # File to store plugin info, such as which ones to install/remove and which ones are disabled. # At this point we can load this here because we already know the actual Application name, so the directory name self._plugin_config_filename = os.path.join(os.path.abspath(config_path), "plugins.json") # type: str from UM.Settings.ContainerRegistry import ContainerRegistry container_registry = ContainerRegistry.getInstance() try: with container_registry.lockFile(): # Load the plugin info if exists if os.path.exists(self._plugin_config_filename): Logger.log("i", "Loading plugin configuration file '%s'", self._plugin_config_filename) with open(self._plugin_config_filename, "r", encoding = "utf-8") as f: data = json.load(f) self._disabled_plugins = data["disabled"] self._plugins_to_install = data["to_install"] self._plugins_to_remove = data["to_remove"] except: Logger.logException("e", "Failed to load plugin configuration file '%s'", self._plugin_config_filename) # Also load data from preferences, where the plugin info used to be saved preferences = self._application.getPreferences() disabled_plugins = preferences.getValue("general/disabled_plugins") disabled_plugins = disabled_plugins.split(",") if disabled_plugins else [] disabled_plugins = [plugin for plugin in disabled_plugins if len(plugin.strip()) > 0] for plugin_id in disabled_plugins: if plugin_id not in self._disabled_plugins: self._disabled_plugins.append(plugin_id) plugins_to_remove = preferences.getValue("general/plugins_to_remove") plugins_to_remove = plugins_to_remove.split(",") if plugins_to_remove else [] for plugin_id in plugins_to_remove: if plugin_id not in self._plugins_to_remove: self._plugins_to_remove.append(plugin_id) # Remove plugins that need to be removed for plugin_id in self._plugins_to_remove: self._removePlugin(plugin_id) self._plugins_to_remove = [] if plugins_to_remove is not None: preferences.setValue("general/plugins_to_remove", "") self._savePluginData() # Install the plugins that need to be installed (overwrite existing) for plugin_id, plugin_info in self._plugins_to_install.items(): self._installPlugin(plugin_id, plugin_info["filename"]) self._plugins_to_install = dict() self._savePluginData()
def _getUpgradeTasks(self): result = [] storage_path_prefixes = set() storage_path_prefixes.add(Resources.getConfigStoragePath()) for old_configuration_type, storage_paths in self._storage_paths.items( ): for prefix in storage_path_prefixes: for storage_path in storage_paths: path = os.path.join(prefix, storage_path) for configuration_file in self._getFilesInDirectory(path): result.append( UpgradeTask( storage_path=path, file_name=configuration_file, configuration_type=old_configuration_type)) return result
def __init__(self, application, parent=None): super().__init__(parent) self._application = application self._container_registry = self._application.getContainerRegistry() self._plugin_registry = self._application.getPluginRegistry() # JSON files that keep track of all installed packages. self._user_package_management_file_path = None # type: str self._bundled_package_management_file_paths = [] # type: List[str] for search_path in Resources.getAllPathsForType( Resources.BundledPackages): if not os.path.isdir(search_path): continue # Load all JSON files that are located in the bundled_packages directory. for file_name in os.listdir(search_path): if not file_name.endswith(".json"): continue file_path = os.path.join(search_path, file_name) if not os.path.isfile(file_path): continue self._bundled_package_management_file_paths.append(file_path) Logger.log( "i", "Found bundled packages JSON file: {location}".format( location=file_path)) for search_path in (Resources.getDataStoragePath(), Resources.getConfigStoragePath()): candidate_user_path = os.path.join(search_path, "packages.json") if os.path.exists(candidate_user_path): self._user_package_management_file_path = candidate_user_path if self._user_package_management_file_path is None: #Doesn't exist yet. self._user_package_management_file_path = os.path.join( Resources.getDataStoragePath(), "packages.json") self._installation_dirs_dict = { "plugins": os.path.abspath(Resources.getStoragePath(Resources.Plugins)) } # type: Dict[str, str] self._bundled_package_dict = {} # A dict of all bundled packages self._installed_package_dict = {} # A dict of all installed packages self._to_remove_package_set = set( ) # A set of packages that need to be removed at the next start self._to_install_package_dict = { } # A dict of packages that need to be installed at the next start
def _getUpgradeTasks(self): exclude_folders = ["old", "cache", "plugins"] for old_configuration_type, storage_paths in self._storage_paths.items( ): storage_path_prefixes = set( Resources.getSearchPaths()) #Set removes duplicates. storage_path_prefixes.add(Resources.getConfigStoragePath()) storage_path_prefixes.add(Resources.getDataStoragePath()) for prefix in storage_path_prefixes: for storage_path in storage_paths: path = os.path.join(prefix, storage_path) for configuration_file in self._getFilesInDirectory( path, exclude_paths=exclude_folders): yield UpgradeTask( storage_path=path, file_name=configuration_file, configuration_type=old_configuration_type)
def initializeBeforePluginsAreLoaded(self): config_path = Resources.getConfigStoragePath() self._plugin_config_filename = os.path.join( os.path.abspath(config_path), "plugins.json") # Load the plugin info if exists if os.path.exists(self._plugin_config_filename): Logger.log("i", "Loading plugin configuration file '%s'", self._plugin_config_filename) with open(self._plugin_config_filename, "r", encoding="utf-8") as f: data = json.load(f) self._disabled_plugins = data["disabled"] self._plugins_to_install = data["to_install"] self._plugins_to_remove = data["to_remove"] # Also load data from preferences, where the plugin info used to be saved preferences = Preferences.getInstance() disabled_plugins = preferences.getValue("general/disabled_plugins") disabled_plugins = disabled_plugins.split( ",") if disabled_plugins else [] for plugin_id in disabled_plugins: if plugin_id not in self._disabled_plugins: self._disabled_plugins.append(plugin_id) plugins_to_remove = preferences.getValue("general/plugins_to_remove") plugins_to_remove = plugins_to_remove.split( ",") if plugins_to_remove else [] for plugin_id in plugins_to_remove: if plugin_id not in self._plugins_to_remove: self._plugins_to_remove.append(plugin_id) # Remove plugins that need to be removed for plugin_id in self._plugins_to_remove: self._removePlugin(plugin_id) self._plugins_to_remove = [] if plugins_to_remove is not None: preferences.setValue("general/plugins_to_remove", "") self._savePluginData() # Install the plugins that need to be installed (overwrite existing) for plugin_id, plugin_info in self._plugins_to_install.items(): self._installPlugin(plugin_id, plugin_info["filename"]) self._plugins_to_install = dict() self._savePluginData()
def upgrade(self): Logger.log("i", "Looking for old configuration files to upgrade.") upgraded = False #Did we upgrade something? paths = self._findShortestUpgradePaths() for old_configuration_type, storage_paths in self._storage_paths.items(): for storage_path in storage_paths: storage_path_config = os.path.join(Resources.getConfigStoragePath(), storage_path) for configuration_file in self._getFilesInDirectory(storage_path_config, exclude_paths = ["old", "cache"]): upgraded |= self._upgradeFile(storage_path_config, configuration_file, old_configuration_type, paths) storage_path_data = os.path.join(Resources.getDataStoragePath(), storage_path) #A second place to look. if storage_path_data != storage_path_config: for configuration_file in self._getFilesInDirectory(storage_path_data, exclude_paths = ["old", "cache"]): upgraded |= self._upgradeFile(storage_path_data, configuration_file, old_configuration_type, paths) if upgraded: message = UM.Message(text=catalogue.i18nc("@info:version-upgrade", "A configuration from an older version of {0} was imported.", UM.Application.getInstance().getApplicationName())) message.show() return upgraded
def __init__(self, application: "QtApplication", parent: Optional[QObject] = None) -> None: super().__init__(parent) self._application = application self._container_registry = self._application.getContainerRegistry() self._plugin_registry = self._application.getPluginRegistry() # JSON files that keep track of all installed packages. self._user_package_management_file_path = None # type: Optional[str] self._bundled_package_management_file_paths = [] # type: List[str] for search_path in Resources.getAllPathsForType(Resources.BundledPackages): if not os.path.isdir(search_path): continue # Load all JSON files that are located in the bundled_packages directory. for file_name in os.listdir(search_path): if not file_name.endswith(".json"): continue file_path = os.path.join(search_path, file_name) if not os.path.isfile(file_path): continue self._bundled_package_management_file_paths.append(file_path) Logger.log("i", "Found bundled packages JSON file: {location}".format(location = file_path)) for search_path in (Resources.getDataStoragePath(), Resources.getConfigStoragePath()): candidate_user_path = os.path.join(search_path, "packages.json") if os.path.exists(candidate_user_path): self._user_package_management_file_path = candidate_user_path if self._user_package_management_file_path is None: # Doesn't exist yet. self._user_package_management_file_path = os.path.join(Resources.getDataStoragePath(), "packages.json") self._installation_dirs_dict = {"plugins": os.path.abspath(Resources.getStoragePath(Resources.Plugins))} # type: Dict[str, str] self._bundled_package_dict = {} # type: Dict[str, Dict[str, Any]] # A dict of all bundled packages self._installed_package_dict = {} # type: Dict[str, Dict[str, Any]] # A dict of all installed packages self._to_remove_package_set = set() # type: Set[str] # A set of packages that need to be removed at the next start self._to_install_package_dict = {} # type: Dict[str, Dict[str, Any]] # A dict of packages that need to be installed at the next start # There can be plugins that provide remote packages (and thus, newer / different versions for a package). self._available_package_versions = {} # type: Dict[str, Set[UMVersion]] self._packages_with_update_available = set() # type: Set[str]
def __init__(self, application: "QtApplication", parent: Optional[QObject] = None) -> None: super().__init__(parent) self._application = application self._container_registry = self._application.getContainerRegistry() self._plugin_registry = self._application.getPluginRegistry() # JSON files that keep track of all installed packages. self._user_package_management_file_path: Optional[str] = None self._bundled_package_management_file_paths: List[str] = [] for search_path in Resources.getAllPathsForType( Resources.BundledPackages): if not os.path.isdir(search_path): continue # Load all JSON files that are located in the bundled_packages directory. try: for file_name in os.listdir(search_path): if not file_name.endswith(".json"): continue file_path = os.path.join(search_path, file_name) if not os.path.isfile(file_path): continue self._bundled_package_management_file_paths.append( file_path) Logger.log( "i", "Found bundled packages JSON file: {location}".format( location=file_path)) except EnvironmentError as e: # Unable to read directory. Could be corrupt disk or insufficient access to list the directory. Logger.log( "e", f"Unable to read package directory to search for packages JSON files: {str(e)}" ) pass for search_path in (Resources.getDataStoragePath(), Resources.getConfigStoragePath()): candidate_user_path = os.path.join(search_path, "packages.json") if os.path.exists(candidate_user_path): self._user_package_management_file_path = candidate_user_path if self._user_package_management_file_path is None: # Doesn't exist yet. self._user_package_management_file_path = os.path.join( Resources.getDataStoragePath(), "packages.json") self._installation_dirs_dict: Dict[str, str] = { "plugins": os.path.abspath(Resources.getStoragePath(Resources.Plugins)) } self._bundled_package_dict: PackageDataDict = { } # A dict of all bundled packages self._installed_package_dict: PackageDataDict = { } # A dict of all installed packages self._to_remove_package_set: Set[str] = set( ) # A set of packages that need to be removed at the next start self._to_install_package_dict: PackageDataDict = { } # A dict of packages that need to be installed at the next start self._dismissed_packages: Set[str] = set( ) # A set of packages that are dismissed by the user self._installed_packages: PackageDataDict = { } # A dict of packages that were installed during startup # There can be plugins that provide remote packages (and thus, newer / different versions for a package). self._available_package_versions: Dict[str, Set[UMVersion]] = {} self._packages_with_update_available: Set[str] = set()
def __init__(self): Resources.addSearchPath( os.path.join(QtApplication.getInstallPrefix(), "share", "cura", "resources")) if not hasattr(sys, "frozen"): Resources.addSearchPath( os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "resources")) self._open_file_queue = [] # Files to open when plug-ins are loaded. # Need to do this before ContainerRegistry tries to load the machines SettingDefinition.addSupportedProperty("settable_per_mesh", DefinitionPropertyType.Any, default=True, read_only=True) SettingDefinition.addSupportedProperty("settable_per_extruder", DefinitionPropertyType.Any, default=True, read_only=True) # this setting can be changed for each group in one-at-a-time mode SettingDefinition.addSupportedProperty("settable_per_meshgroup", DefinitionPropertyType.Any, default=True, read_only=True) SettingDefinition.addSupportedProperty("settable_globally", DefinitionPropertyType.Any, default=True, read_only=True) # From which stack the setting would inherit if not defined per object (handled in the engine) # AND for settings which are not settable_per_mesh: # which extruder is the only extruder this setting is obtained from SettingDefinition.addSupportedProperty("limit_to_extruder", DefinitionPropertyType.Function, default="-1") # For settings which are not settable_per_mesh and not settable_per_extruder: # A function which determines the glabel/meshgroup value by looking at the values of the setting in all (used) extruders SettingDefinition.addSupportedProperty("resolve", DefinitionPropertyType.Function, default=None) SettingDefinition.addSettingType("extruder", None, str, Validator) SettingFunction.registerOperator( "extruderValues", cura.Settings.ExtruderManager.getExtruderValues) SettingFunction.registerOperator( "extruderValue", cura.Settings.ExtruderManager.getExtruderValue) SettingFunction.registerOperator( "resolveOrValue", cura.Settings.ExtruderManager.getResolveOrValue) ## Add the 4 types of profiles to storage. Resources.addStorageType(self.ResourceTypes.QualityInstanceContainer, "quality") Resources.addStorageType(self.ResourceTypes.VariantInstanceContainer, "variants") Resources.addStorageType(self.ResourceTypes.MaterialInstanceContainer, "materials") Resources.addStorageType(self.ResourceTypes.UserInstanceContainer, "user") Resources.addStorageType(self.ResourceTypes.ExtruderStack, "extruders") Resources.addStorageType(self.ResourceTypes.MachineStack, "machine_instances") ContainerRegistry.getInstance().addResourceType( self.ResourceTypes.QualityInstanceContainer) ContainerRegistry.getInstance().addResourceType( self.ResourceTypes.VariantInstanceContainer) ContainerRegistry.getInstance().addResourceType( self.ResourceTypes.MaterialInstanceContainer) ContainerRegistry.getInstance().addResourceType( self.ResourceTypes.UserInstanceContainer) ContainerRegistry.getInstance().addResourceType( self.ResourceTypes.ExtruderStack) ContainerRegistry.getInstance().addResourceType( self.ResourceTypes.MachineStack) ## Initialise the version upgrade manager with Cura's storage paths. import UM.VersionUpgradeManager #Needs to be here to prevent circular dependencies. UM.VersionUpgradeManager.VersionUpgradeManager.getInstance( ).setCurrentVersions({ ("quality", UM.Settings.InstanceContainer.Version): (self.ResourceTypes.QualityInstanceContainer, "application/x-uranium-instancecontainer"), ("machine_stack", UM.Settings.ContainerStack.Version): (self.ResourceTypes.MachineStack, "application/x-uranium-containerstack"), ("preferences", UM.Preferences.Version): (Resources.Preferences, "application/x-uranium-preferences"), ("user", UM.Settings.InstanceContainer.Version): (self.ResourceTypes.UserInstanceContainer, "application/x-uranium-instancecontainer") }) self._machine_action_manager = MachineActionManager.MachineActionManager( ) self._machine_manager = None # This is initialized on demand. self._setting_inheritance_manager = None self._additional_components = { } # Components to add to certain areas in the interface super().__init__(name="cura", version=CuraVersion, buildtype=CuraBuildType) self.setWindowIcon( QIcon(Resources.getPath(Resources.Images, "cura-icon.png"))) self.setRequiredPlugins([ "CuraEngineBackend", "MeshView", "LayerView", "STLReader", "SelectionTool", "CameraTool", "GCodeWriter", "LocalFileOutputDevice" ]) self._physics = None self._volume = None self._output_devices = {} self._print_information = None self._previous_active_tool = None self._platform_activity = False self._scene_bounding_box = AxisAlignedBox.Null self._job_name = None self._center_after_select = False self._camera_animation = None self._cura_actions = None self._started = False self._message_box_callback = None self._message_box_callback_arguments = [] self._i18n_catalog = i18nCatalog("cura") self.getController().getScene().sceneChanged.connect( self.updatePlatformActivity) self.getController().toolOperationStopped.connect( self._onToolOperationStopped) Resources.addType(self.ResourceTypes.QmlFiles, "qml") Resources.addType(self.ResourceTypes.Firmware, "firmware") self.showSplashMessage( self._i18n_catalog.i18nc("@info:progress", "Loading machines...")) # Add empty variant, material and quality containers. # Since they are empty, they should never be serialized and instead just programmatically created. # We need them to simplify the switching between materials. empty_container = ContainerRegistry.getInstance( ).getEmptyInstanceContainer() empty_variant_container = copy.deepcopy(empty_container) empty_variant_container._id = "empty_variant" empty_variant_container.addMetaDataEntry("type", "variant") ContainerRegistry.getInstance().addContainer(empty_variant_container) empty_material_container = copy.deepcopy(empty_container) empty_material_container._id = "empty_material" empty_material_container.addMetaDataEntry("type", "material") ContainerRegistry.getInstance().addContainer(empty_material_container) empty_quality_container = copy.deepcopy(empty_container) empty_quality_container._id = "empty_quality" empty_quality_container.setName("Not supported") empty_quality_container.addMetaDataEntry("quality_type", "normal") empty_quality_container.addMetaDataEntry("type", "quality") ContainerRegistry.getInstance().addContainer(empty_quality_container) empty_quality_changes_container = copy.deepcopy(empty_container) empty_quality_changes_container._id = "empty_quality_changes" empty_quality_changes_container.addMetaDataEntry( "type", "quality_changes") ContainerRegistry.getInstance().addContainer( empty_quality_changes_container) # Set the filename to create if cura is writing in the config dir. self._config_lock_filename = os.path.join( Resources.getConfigStoragePath(), CONFIG_LOCK_FILENAME) self.waitConfigLockFile() ContainerRegistry.getInstance().load() Preferences.getInstance().addPreference("cura/active_mode", "simple") Preferences.getInstance().addPreference("cura/recent_files", "") Preferences.getInstance().addPreference("cura/categories_expanded", "") Preferences.getInstance().addPreference("cura/jobname_prefix", True) Preferences.getInstance().addPreference("view/center_on_select", True) Preferences.getInstance().addPreference("mesh/scale_to_fit", True) Preferences.getInstance().addPreference("mesh/scale_tiny_meshes", True) for key in [ "dialog_load_path", # dialog_save_path is in LocalFileOutputDevicePlugin "dialog_profile_path", "dialog_material_path" ]: Preferences.getInstance().addPreference("local_file/%s" % key, os.path.expanduser("~/")) Preferences.getInstance().setDefault("local_file/last_used_type", "text/x-gcode") Preferences.getInstance().setDefault( "general/visible_settings", """ machine_settings resolution layer_height shell wall_thickness top_bottom_thickness infill infill_sparse_density material material_print_temperature material_bed_temperature material_diameter material_flow retraction_enable speed speed_print speed_travel acceleration_print acceleration_travel jerk_print jerk_travel travel cooling cool_fan_enabled support support_enable support_extruder_nr support_type support_interface_density platform_adhesion adhesion_type adhesion_extruder_nr brim_width raft_airgap layer_0_z_overlap raft_surface_layers dual prime_tower_enable prime_tower_size prime_tower_position_x prime_tower_position_y meshfix blackmagic print_sequence infill_mesh experimental """.replace("\n", ";").replace(" ", "")) JobQueue.getInstance().jobFinished.connect(self._onJobFinished) self.applicationShuttingDown.connect(self.saveSettings) self.engineCreatedSignal.connect(self._onEngineCreated) self._recent_files = [] files = Preferences.getInstance().getValue("cura/recent_files").split( ";") for f in files: if not os.path.isfile(f): continue self._recent_files.append(QUrl.fromLocalFile(f))
def _showConfigurationFolder(self): path = Resources.getConfigStoragePath() QDesktopServices.openUrl(QUrl.fromLocalFile(path))
def __init__(self): Resources.addSearchPath(os.path.join(QtApplication.getInstallPrefix(), "share", "cura", "resources")) if not hasattr(sys, "frozen"): Resources.addSearchPath(os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "resources")) self._open_file_queue = [] # Files to open when plug-ins are loaded. # Need to do this before ContainerRegistry tries to load the machines SettingDefinition.addSupportedProperty("settable_per_mesh", DefinitionPropertyType.Any, default = True, read_only = True) SettingDefinition.addSupportedProperty("settable_per_extruder", DefinitionPropertyType.Any, default = True, read_only = True) # this setting can be changed for each group in one-at-a-time mode SettingDefinition.addSupportedProperty("settable_per_meshgroup", DefinitionPropertyType.Any, default = True, read_only = True) SettingDefinition.addSupportedProperty("settable_globally", DefinitionPropertyType.Any, default = True, read_only = True) # From which stack the setting would inherit if not defined per object (handled in the engine) # AND for settings which are not settable_per_mesh: # which extruder is the only extruder this setting is obtained from SettingDefinition.addSupportedProperty("limit_to_extruder", DefinitionPropertyType.Function, default = "-1") # For settings which are not settable_per_mesh and not settable_per_extruder: # A function which determines the glabel/meshgroup value by looking at the values of the setting in all (used) extruders SettingDefinition.addSupportedProperty("resolve", DefinitionPropertyType.Function, default = None, depends_on = "value") SettingDefinition.addSettingType("extruder", None, str, Validator) SettingFunction.registerOperator("extruderValues", cura.Settings.ExtruderManager.getExtruderValues) SettingFunction.registerOperator("extruderValue", cura.Settings.ExtruderManager.getExtruderValue) SettingFunction.registerOperator("resolveOrValue", cura.Settings.ExtruderManager.getResolveOrValue) ## Add the 4 types of profiles to storage. Resources.addStorageType(self.ResourceTypes.QualityInstanceContainer, "quality") Resources.addStorageType(self.ResourceTypes.VariantInstanceContainer, "variants") Resources.addStorageType(self.ResourceTypes.MaterialInstanceContainer, "materials") Resources.addStorageType(self.ResourceTypes.UserInstanceContainer, "user") Resources.addStorageType(self.ResourceTypes.ExtruderStack, "extruders") Resources.addStorageType(self.ResourceTypes.MachineStack, "machine_instances") ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.QualityInstanceContainer) ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.VariantInstanceContainer) ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.MaterialInstanceContainer) ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.UserInstanceContainer) ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.ExtruderStack) ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.MachineStack) ## Initialise the version upgrade manager with Cura's storage paths. import UM.VersionUpgradeManager #Needs to be here to prevent circular dependencies. UM.VersionUpgradeManager.VersionUpgradeManager.getInstance().setCurrentVersions( { ("quality", UM.Settings.InstanceContainer.Version): (self.ResourceTypes.QualityInstanceContainer, "application/x-uranium-instancecontainer"), ("machine_stack", UM.Settings.ContainerStack.Version): (self.ResourceTypes.MachineStack, "application/x-uranium-containerstack"), ("preferences", UM.Preferences.Version): (Resources.Preferences, "application/x-uranium-preferences"), ("user", UM.Settings.InstanceContainer.Version): (self.ResourceTypes.UserInstanceContainer, "application/x-uranium-instancecontainer") } ) self._machine_action_manager = MachineActionManager.MachineActionManager() self._machine_manager = None # This is initialized on demand. self._setting_inheritance_manager = None self._additional_components = {} # Components to add to certain areas in the interface super().__init__(name = "cura", version = CuraVersion, buildtype = CuraBuildType) self.setWindowIcon(QIcon(Resources.getPath(Resources.Images, "cura-icon.png"))) self.setRequiredPlugins([ "CuraEngineBackend", "MeshView", "LayerView", "STLReader", "SelectionTool", "CameraTool", "GCodeWriter", "LocalFileOutputDevice" ]) self._physics = None self._volume = None self._output_devices = {} self._print_information = None self._previous_active_tool = None self._platform_activity = False self._scene_bounding_box = AxisAlignedBox.Null self._job_name = None self._center_after_select = False self._camera_animation = None self._cura_actions = None self._started = False self._message_box_callback = None self._message_box_callback_arguments = [] self._i18n_catalog = i18nCatalog("cura") self.getController().getScene().sceneChanged.connect(self.updatePlatformActivity) self.getController().toolOperationStopped.connect(self._onToolOperationStopped) Resources.addType(self.ResourceTypes.QmlFiles, "qml") Resources.addType(self.ResourceTypes.Firmware, "firmware") self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Loading machines...")) # Add empty variant, material and quality containers. # Since they are empty, they should never be serialized and instead just programmatically created. # We need them to simplify the switching between materials. empty_container = ContainerRegistry.getInstance().getEmptyInstanceContainer() empty_variant_container = copy.deepcopy(empty_container) empty_variant_container._id = "empty_variant" empty_variant_container.addMetaDataEntry("type", "variant") ContainerRegistry.getInstance().addContainer(empty_variant_container) empty_material_container = copy.deepcopy(empty_container) empty_material_container._id = "empty_material" empty_material_container.addMetaDataEntry("type", "material") ContainerRegistry.getInstance().addContainer(empty_material_container) empty_quality_container = copy.deepcopy(empty_container) empty_quality_container._id = "empty_quality" empty_quality_container.setName("Not supported") empty_quality_container.addMetaDataEntry("quality_type", "normal") empty_quality_container.addMetaDataEntry("type", "quality") ContainerRegistry.getInstance().addContainer(empty_quality_container) empty_quality_changes_container = copy.deepcopy(empty_container) empty_quality_changes_container._id = "empty_quality_changes" empty_quality_changes_container.addMetaDataEntry("type", "quality_changes") ContainerRegistry.getInstance().addContainer(empty_quality_changes_container) # Set the filename to create if cura is writing in the config dir. self._config_lock_filename = os.path.join(Resources.getConfigStoragePath(), CONFIG_LOCK_FILENAME) self.waitConfigLockFile() ContainerRegistry.getInstance().load() Preferences.getInstance().addPreference("cura/active_mode", "simple") Preferences.getInstance().addPreference("cura/recent_files", "") Preferences.getInstance().addPreference("cura/categories_expanded", "") Preferences.getInstance().addPreference("cura/jobname_prefix", True) Preferences.getInstance().addPreference("view/center_on_select", True) Preferences.getInstance().addPreference("mesh/scale_to_fit", True) Preferences.getInstance().addPreference("mesh/scale_tiny_meshes", True) for key in [ "dialog_load_path", # dialog_save_path is in LocalFileOutputDevicePlugin "dialog_profile_path", "dialog_material_path"]: Preferences.getInstance().addPreference("local_file/%s" % key, os.path.expanduser("~/")) Preferences.getInstance().setDefault("local_file/last_used_type", "text/x-gcode") Preferences.getInstance().setDefault("general/visible_settings", """ machine_settings resolution layer_height shell wall_thickness top_bottom_thickness infill infill_sparse_density material material_print_temperature material_bed_temperature material_diameter material_flow retraction_enable speed speed_print speed_travel acceleration_print acceleration_travel jerk_print jerk_travel travel cooling cool_fan_enabled support support_enable support_extruder_nr support_type support_interface_density platform_adhesion adhesion_type adhesion_extruder_nr brim_width raft_airgap layer_0_z_overlap raft_surface_layers dual prime_tower_enable prime_tower_size prime_tower_position_x prime_tower_position_y meshfix blackmagic print_sequence infill_mesh experimental """.replace("\n", ";").replace(" ", "")) JobQueue.getInstance().jobFinished.connect(self._onJobFinished) self.applicationShuttingDown.connect(self.saveSettings) self.engineCreatedSignal.connect(self._onEngineCreated) self._recent_files = [] files = Preferences.getInstance().getValue("cura/recent_files").split(";") for f in files: if not os.path.isfile(f): continue self._recent_files.append(QUrl.fromLocalFile(f))
def _showConfigurationFolder(self): path = Resources.getConfigStoragePath() QDesktopServices.openUrl(QUrl.fromLocalFile( path ))