Use plugin Id instead of __file__ for XmlMaterialProfile

CURA-6255
This commit is contained in:
Nino van Hooff 2019-12-24 15:42:01 +01:00
parent 49b93db6df
commit 128bfa987e
3 changed files with 22 additions and 2 deletions

View File

@ -0,0 +1,15 @@
from UM.PluginObject import PluginObject
class PluginInfo(PluginObject):
__instance = None # type: PluginInfo
def __init__(self, *args, **kwags):
super().__init__(*args, **kwags)
if PluginInfo.__instance is not None:
raise RuntimeError("Try to create singleton '%s' more than once" % self.__class__.__name__)
PluginInfo.__instance = self
@classmethod
def getInstance(cls, *args, **kwargs) -> "USBPrinterOutputDeviceManager":
return cls.__instance

View File

@ -9,6 +9,7 @@ import sys
from typing import Any, Dict, List, Optional, Tuple, cast, Set, Union
import xml.etree.ElementTree as ET
from UM.PluginRegistry import PluginRegistry
from UM.Resources import Resources
from UM.Logger import Logger
import UM.Dictionary
@ -19,6 +20,7 @@ from UM.ConfigurationErrorMessage import ConfigurationErrorMessage
from cura.CuraApplication import CuraApplication
from cura.Machines.ContainerTree import ContainerTree
from cura.Machines.VariantType import VariantType
from plugins.XmlMaterialProfile import PluginInfo
try:
from .XmlMaterialValidator import XmlMaterialValidator
@ -1068,7 +1070,9 @@ class XmlMaterialProfile(InstanceContainer):
# This loads the mapping from a file.
@classmethod
def getProductIdMap(cls) -> Dict[str, List[str]]:
product_to_id_file = os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), "product_to_id.json")
plugin_id = PluginInfo.getInstance().getPluginId()
plugin_path = PluginRegistry.getInstance().getPluginPath(plugin_id)
product_to_id_file = os.path.join(plugin_path, "product_to_id.json")
with open(product_to_id_file, encoding = "utf-8") as f:
product_to_id_map = json.load(f)
product_to_id_map = {key: [value] for key, value in product_to_id_map.items()}

View File

@ -1,6 +1,6 @@
# Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from plugins.XmlMaterialProfile.PluginInfo import PluginInfo
from . import XmlMaterialProfile
from . import XmlMaterialUpgrader
@ -46,4 +46,5 @@ def register(app):
return {"version_upgrade": upgrader,
"settings_container": XmlMaterialProfile.XmlMaterialProfile("default_xml_material_profile"),
"plugin_info": PluginInfo()
}