コード例 #1
0
ファイル: __init__.py プロジェクト: Helisinus/OctoPrint-GPX
	def putmachine(self, machineid):
		response = self.validate_machineid(machineid)
		if response is not None:
			return response
		try:
			machine_ini = self.fetch_machine_ini(machineid)
		except ValueError:
			return make_response("Unknown machine id: %s" % machineid, 404)
		defaults = gpx.get_machine_defaults(machineid)
		incoming = self.ini_massage_in(request.json)
		for sectionname, section in incoming.items():
			if sectionname in defaults:
				for option, value in section.items():
					if option in defaults[sectionname]:
						if value == 'undefined':
							incoming[sectionname][option] = ''
							continue
						t = type(defaults[sectionname][option])
						try:
							if t == float:
								value = float(value)
							elif t == int:
								value = int(value)
						except ValueError:
							incoming[sectionname][option] = ''
						if defaults[sectionname][option] == value:
							# delete the option in the output so the builtin default
							# will shine through
							incoming[sectionname][option] = ''
		machine_ini.update(incoming)
		machine_ini.dump()
		machine_ini.write()
		return ('', 200)
コード例 #2
0
 def putmachine(self, machineid, *args, **kwargs):
     response = self.validate_machineid(machineid)
     if response is not None:
         return response
     try:
         machine_ini = self.fetch_machine_ini(machineid)
     except ValueError:
         return make_response("Unknown machine id: %s" % machineid, 404)
     defaults = gpx.get_machine_defaults(machineid)
     incoming = self.ini_massage_in(request.json)
     for sectionname, section in incoming.items():
         if sectionname in defaults:
             for option, value in section.items():
                 if option in defaults[sectionname]:
                     if value == 'undefined':
                         incoming[sectionname][option] = ''
                         continue
                     t = type(defaults[sectionname][option])
                     try:
                         if t == float:
                             value = float(value)
                         elif t == int:
                             value = int(value)
                     except ValueError:
                         incoming[sectionname][option] = ''
                     if defaults[sectionname][option] == value:
                         # delete the option in the output so the builtin default
                         # will shine through
                         incoming[sectionname][option] = ''
     machine_ini.update(incoming)
     machine_ini.dump()
     machine_ini.write()
     return ('', 200)
コード例 #3
0
ファイル: __init__.py プロジェクト: Helisinus/OctoPrint-GPX
	def defaultmachine(self, machineid):
		response = self.validate_machineid(machineid)
		if response is not None:
			return response
		if gpx is None:
			return None
		try:
			machine = gpx.get_machine_defaults(machineid)
		except ValueError:
			return make_response("Unknown machine id: %s" % machineid, 404)
		return flask.jsonify(self.ini_massage_out(machine))
コード例 #4
0
 def defaultmachine(self, machineid, *args, **kwargs):
     response = self.validate_machineid(machineid)
     if response is not None:
         return response
     if gpx is None:
         return None
     try:
         machine = gpx.get_machine_defaults(machineid)
     except ValueError:
         return make_response("Unknown machine id: %s" % machineid, 404)
     return flask.jsonify(self.ini_massage_out(machine))
コード例 #5
0
ファイル: __init__.py プロジェクト: Helisinus/OctoPrint-GPX
	def fetch_machine(self, machineid):
		if gpx is None:
			return None
		machine = gpx.get_machine_defaults(machineid)
		machine_ini = self.fetch_machine_ini(machineid)
		return _merge_dict(machine, machine_ini.ini)
コード例 #6
0
 def fetch_machine(self, machineid):
     if gpx is None:
         return None
     machine = gpx.get_machine_defaults(machineid)
     machine_ini = self.fetch_machine_ini(machineid)
     return _merge_dict(machine, machine_ini.ini)