예제 #1
0
def roConfig(key):
    global _instance

    if _instance is None:

        defaults = {
            'cloud': {
                'apiHost': "https://api.astroprint.com",
                'apiClientId': None,
                'boxrouter': "wss://boxrouter.astroprint.com"
            },
            'network': {
                'ssl': {
                    'certPath': '/boot/.astrobox/ssl/cert.pem'
                }
            }
        }

        roFile = os.path.join(settings().getConfigFolder(), 'ro-config.yaml')
        with open(roFile, 'r') as f:
            config = yaml.safe_load(f)

        merge_dict(defaults, config)
        _instance = defaults

    v = _instance
    for k in key.split('.'):
        v = v[k]

    return v
예제 #2
0
def roConfig(key):
	global _instance

	if _instance is None:

		defaults = {
			'cloud': {
				'apiHost': "https://api.astroprint.com",
				'apiClientId': None,
				'boxrouter': "wss://boxrouter.astroprint.com"
			}
		}

		roFile = os.path.join(settings().getConfigFolder(),'ro-config.yaml')
		with open(roFile,'r') as f:
			config = yaml.safe_load(f)

		merge_dict(defaults, config)
		_instance = defaults

	v = _instance
	for k in key.split('.'):
		v = v[k]

	return v
예제 #3
0
	def _loadDefinition(self, ):
		if os.path.isdir(self._folder):
			def_file = os.path.join(self._folder, 'definition.yaml')

			if os.path.isfile(def_file):
				try:
					with open(def_file, "r") as f:
						definition = yaml.safe_load(f)

					if definition:
						self._logger.info("Manufacturer definition loaded.")
						merge_dict(self.data, definition)

				except:
					self._logger.error("There was an error loading %s:" % def_file, exc_info= True)

				return

		self._logger.info('No Manufacturer Package present')
예제 #4
0
    def _loadDefinition(self, ):
        if os.path.isdir(self._folder):
            def_file = os.path.join(self._folder, 'definition.yaml')

            if os.path.isfile(def_file):
                try:
                    with open(def_file, "r") as f:
                        definition = yaml.safe_load(f)

                    if definition:
                        self._logger.info("Manufacturer definition loaded.")
                        merge_dict(self.data, definition)

                except:
                    self._logger.error("There was an error loading %s:" %
                                       def_file,
                                       exc_info=True)

                return

        self._logger.info('No Manufacturer Package present')
예제 #5
0
	def __init__(self):
		self._settings = settings()

		configDir = self._settings.getConfigFolder()

		self._infoFile = "%s/printer-profile.yaml" % configDir
		self._logger = logging.getLogger(__name__)
		self.data = {
			'driver': "marlin",
			'plugin': None,
			'extruder_count': 1,
			'max_nozzle_temp': 280,
			'max_bed_temp': 140,
			'heated_bed': True,
			'cancel_gcode': ['G28 X0 Y0'],
			'invert_z': False,
			'invert_x': False,
			'invert_y': False,
			'printer_model': {
				'id': None,
				'name': None
			},
			'temp_presets' : [
					{ 'id' : "3e0fc9b398234f2f871310c1998aa000",
					'name' : "PLA",
					'nozzle_temp' : 220,
					'bed_temp' : 40},
				 	{'id' : "2cc9df599f3e4292b379913f4940c000s",
					'name': "ABS",
					'nozzle_temp': 230,
					'bed_temp' : 80}
			],
			'last_presets_used' : [
			]
		}

		config = None
		if not os.path.isfile(self._infoFile):
			factoryFile = "%s/printer-profile.factory" % configDir

			if os.path.isfile(factoryFile):
				with open(factoryFile, "r") as f:
					config = yaml.safe_load(f)

			#overlay manufactuer definition of printer profile
			if not config:
				config = {}

			mfDefinition = manufacturerPkgManager().printerProfile
			for k in mfDefinition.keys():
				v = mfDefinition[k]
				if v is not None:
					config[k] = v

			if config:
				merge_dict(self.data, config)

			self.save()

		else:
			with open(self._infoFile, "r") as f:
				config = yaml.safe_load(f)

			if config:
				merge_dict(self.data, config)
예제 #6
0
    def __init__(self):
        self._settings = settings()

        configDir = self._settings.getConfigFolder()

        self._infoFile = "%s/printer-profile.yaml" % configDir
        self._logger = logging.getLogger(__name__)
        self.data = {
            'last_definition_version': None,
            'driver': "marlin",
            'plugin': None,
            'extruder_count': 1,
            'check_clear_bed': True,
            'max_nozzle_temp': 280,
            'max_bed_temp': 140,
            'heated_bed': True,
            'cancel_gcode': ['G28 X0 Y0'],
            'invert_z': False,
            'invert_x': False,
            'invert_y': False,
            'manufacturer_id': None,
            'printer_model': {
                'id': None,
                'name': None
            },
            'filament': {
                'color': None,
                'name': None
            },
            'temp_presets': {
                '3e0fc9b398234f2f871310c1998aa000': {
                    'name': "PLA",
                    'nozzle_temp': 220,
                    'bed_temp': 40
                },
                '2cc9df599f3e4292b379913f4940c000': {
                    'name': "ABS",
                    'nozzle_temp': 230,
                    'bed_temp': 80
                },
            },
            'last_presets_used': {}
        }
        config = None

        if not os.path.isfile(self._infoFile):
            factoryFile = "%s/printer-profile.factory" % configDir

            if os.path.isfile(factoryFile):
                with open(factoryFile, "r") as f:
                    config = yaml.safe_load(f)

            if not config:
                config = {}

            if config:
                merge_dict(self.data, config)

            self.save()

        else:
            with open(self._infoFile, "r") as f:
                config = yaml.safe_load(f)

            if config:
                # remove old array formats
                if 'temp_presets' in config and isinstance(
                        config['temp_presets'], list) == True:
                    del config['temp_presets']
                if 'last_presets_used' in config and isinstance(
                        config['last_presets_used'], list) == True:
                    del config['last_presets_used']

                merge_dict(self.data, config)

        # check manufacturer definition update
        version = manufacturerPkgManager().version
        mfDefProfile = manufacturerPkgManager().printerProfile
        mfConfig = {}
        if version != self.data['last_definition_version']:
            self._logger.info(
                "A New update for manufacturer package has been found: %s" %
                (version))

            mfDefVariant = manufacturerPkgManager().variant
            for k in mfDefProfile.keys():
                v = mfDefProfile[k]
                if v is not None:
                    mfConfig[k] = v
                    if k == "temp_presets":
                        for mfPresetID in v.keys():
                            p = mfConfig[k][mfPresetID]

                            if self.data[k] is not None:
                                dKey = self._checkPresetExisted(k, mfPresetID)
                                if dKey:
                                    # if manufacturer updates its preset and user it's not allowed to edit => REPLACE
                                    if mfPresetID and mfDefVariant[
                                            'temperature_presets_edit'] is False:
                                        mfConfig[k][dKey] = {
                                            "manufacturer_id": mfPresetID,
                                            "name": p['name'],
                                            "bed_temp": p['bed_temp'],
                                            "nozzle_temp": p['nozzle_temp'],
                                        }
                                        del mfConfig[k][mfPresetID]

                                    # if manfufacturer updates its preset and user it's allowed to edit => check if different ID. This way is user has edited a preset, and manufacturer update it after using same ID, it wont be overwritten but ignored it.
                                    else:
                                        matchedId = ""
                                        for i in self.data['temp_presets']:
                                            if "manufacturer_id" in self.data[
                                                    'temp_presets'][i]:
                                                if self.data['temp_presets'][i][
                                                        'manufacturer_id'] == mfPresetID:
                                                    matchedId = mfPresetID

                                        if not matchedId:
                                            mfConfig[k][dKey] = {
                                                "manufacturer_id": mfPresetID,
                                                "name": p['name'],
                                                "bed_temp": p['bed_temp'],
                                                "nozzle_temp":
                                                p['nozzle_temp'],
                                            }
                                        else:
                                            del mfConfig[k][mfPresetID]

                                else:
                                    # Add new attribute object with correct format
                                    mfConfig[k][uuid.uuid4().hex] = {
                                        "manufacturer_id": mfPresetID,
                                        "name": p['name'],
                                        "bed_temp": p['bed_temp'],
                                        "nozzle_temp": p['nozzle_temp'],
                                    }
                                    del mfConfig[k][mfPresetID]
                            else:
                                mfConfig[k][uuid.uuid4().hex] = {
                                    "manufacturer_id": mfPresetID,
                                    "name": p['name'],
                                    "bed_temp": p['bed_temp'],
                                    "nozzle_temp": p['nozzle_temp'],
                                }
                                del mfConfig[k][mfPresetID]
            # update version number
            self.data['last_definition_version'] = version

        if version or mfConfig:
            if "temp_presets" in mfConfig.keys() or version:
                self._removeDefaultTempPresets()
            merge_dict(self.data, mfConfig)
        self.save()
예제 #7
0
	def __init__(self):
		self._settings = settings()

		configDir = self._settings.getConfigFolder()

		self._infoFile = "%s/printer-profile.yaml" % configDir
		self._logger = logging.getLogger(__name__)
		self.data = {
			'last_definition_version': None,
			'driver': "marlin",
			'plugin': None,
			'extruder_count': 1,
			'max_nozzle_temp': 280,
			'max_bed_temp': 140,
			'heated_bed': True,
			'cancel_gcode': ['G28 X0 Y0'],
			'invert_z': False,
			'invert_x': False,
			'invert_y': False,
			'printer_model': {
				'id': None,
				'name': None
			},
			'filament': {
				'color': None,
				'name': None
			},
			'temp_presets' : {
				'3e0fc9b398234f2f871310c1998aa000': {
					'name' : "PLA",
					'nozzle_temp' : 220,
					'bed_temp' : 40
				},
				'2cc9df599f3e4292b379913f4940c000': {
					'name' : "ABS",
					'nozzle_temp' : 230,
					'bed_temp' : 80
				},
			},
			'last_presets_used' : {}
		}
		config = None

		if not os.path.isfile(self._infoFile):
			factoryFile = "%s/printer-profile.factory" % configDir

			if os.path.isfile(factoryFile):
				with open(factoryFile, "r") as f:
					config = yaml.safe_load(f)

			if not config:
				config = {}

			if config:
				merge_dict(self.data, config)

			self.save()

		else:
			with open(self._infoFile, "r") as f:
				config = yaml.safe_load(f)

			if config:
				# remove old array formats
				if 'temp_presets' in config and isinstance(config['temp_presets'], list) == True:
					del config['temp_presets']
				if 'last_presets_used'in config and isinstance(config['last_presets_used'], list) == True:
					del config['last_presets_used']

				merge_dict(self.data, config)

		# check manufacturer definition update
		version = manufacturerPkgManager().version
		mfDefProfile = manufacturerPkgManager().printerProfile
		mfConfig = {}
		if version != self.data['last_definition_version']:
			self._logger.info("A New update for manufacturer package has been found: %s" % (version))

			mfDefVariant = manufacturerPkgManager().variant
			for k in mfDefProfile.keys():
				v = mfDefProfile[k]
				if v is not None:
					mfConfig[k] = v
					if k == "temp_presets":
						for mfPresetID in v.keys():
							p = mfConfig[k][mfPresetID]

							if self.data[k] is not None:
								dKey = self._checkPresetExisted(k, mfPresetID)
								if dKey:
									# if manufacturer updates its preset and user it's not allowed to edit => REPLACE
									if mfPresetID and mfDefVariant['temperature_presets_edit'] is False:
										mfConfig[k][dKey] = {
											"manufacturer_id": mfPresetID,
											"name": p['name'],
											"bed_temp": p['bed_temp'],
											"nozzle_temp": p['nozzle_temp'],
										}
										del mfConfig[k][mfPresetID]

									# if manfufacturer updates its preset and user it's allowed to edit => check if different ID. This way is user has edited a preset, and manufacturer update it after using same ID, it wont be overwritten but ignored it.
									else:
										matchedId = ""
										for i in self.data['temp_presets']:
											if "manufacturer_id" in self.data['temp_presets'][i]:
												if self.data['temp_presets'][i]['manufacturer_id'] == mfPresetID:
													matchedId = mfPresetID

										if not matchedId:
											mfConfig[k][dKey] = {
												"manufacturer_id": mfPresetID,
												"name": p['name'],
												"bed_temp": p['bed_temp'],
												"nozzle_temp": p['nozzle_temp'],
											}
										else:
											del mfConfig[k][mfPresetID]

								else:
									# Add new attribute object with correct format
									mfConfig[k][uuid.uuid4().hex] = {
										"manufacturer_id": mfPresetID,
										"name": p['name'],
										"bed_temp": p['bed_temp'],
										"nozzle_temp": p['nozzle_temp'],
									}
									del mfConfig[k][mfPresetID]
							else:
								mfConfig[k][uuid.uuid4().hex] = {
									"manufacturer_id": mfPresetID,
									"name": p['name'],
									"bed_temp": p['bed_temp'],
									"nozzle_temp": p['nozzle_temp'],
								}
								del mfConfig[k][mfPresetID]
			# update version number
			self.data['last_definition_version'] = version

		if version or mfConfig:
			if "temp_presets" in mfConfig.keys() or version:
				self._removeDefaultTempPresets()
			merge_dict(self.data, mfConfig)
		self.save()