Checkpoint
This commit is contained in:
@@ -28,8 +28,6 @@
|
||||
import os
|
||||
import json
|
||||
import pkg_resources
|
||||
import subprocess
|
||||
import copy
|
||||
from pkg_resources import Requirement, resource_filename
|
||||
|
||||
|
||||
@@ -55,14 +53,6 @@ class Config(object):
|
||||
except Exception: self.log.exception('Internal error: Failed to load config template')
|
||||
|
||||
|
||||
def get(self, name, default = None):
|
||||
return self.values.get(name, default)
|
||||
|
||||
|
||||
def get_index(self, name, index, default = None):
|
||||
return self.values.get(name, {}).get(str(index), None)
|
||||
|
||||
|
||||
def load(self):
|
||||
path = self.ctrl.get_path('config.json')
|
||||
|
||||
@@ -72,7 +62,7 @@ class Config(object):
|
||||
else: config = {'version': self.version}
|
||||
|
||||
try:
|
||||
self.upgrade(config)
|
||||
self._upgrade(config)
|
||||
except Exception: self.log.exception('Internal error: Failed to upgrade config')
|
||||
|
||||
except Exception as e:
|
||||
@@ -83,6 +73,33 @@ class Config(object):
|
||||
return config
|
||||
|
||||
|
||||
def reload(self):
|
||||
self._update(self.load(), True)
|
||||
|
||||
|
||||
def get(self, name, default = None):
|
||||
return self.values.get(name, default)
|
||||
|
||||
|
||||
def save(self, config):
|
||||
self._upgrade(config)
|
||||
self._update(config, False)
|
||||
|
||||
with open(self.ctrl.get_path('config.json'), 'w') as f:
|
||||
json.dump(config, f, indent=2)
|
||||
|
||||
os.sync()
|
||||
|
||||
self.ctrl.preplanner.invalidate_all()
|
||||
self.log.info('Saved')
|
||||
|
||||
|
||||
def reset(self):
|
||||
if os.path.exists('config.json'): os.unlink('config.json')
|
||||
self.reload()
|
||||
self.ctrl.preplanner.invalidate_all()
|
||||
|
||||
|
||||
def _valid_value(self, template, value):
|
||||
type = template['type']
|
||||
|
||||
@@ -136,7 +153,7 @@ class Config(object):
|
||||
self.__defaults(conf, name, tmpl)
|
||||
|
||||
|
||||
def upgrade(self, config):
|
||||
def _upgrade(self, config):
|
||||
version = config['version']
|
||||
version = version.split('b')[0] # Strip off any "beta" suffix
|
||||
version = tuple(map(int, version.split('.'))) # Break it into a tuple of integers
|
||||
@@ -171,24 +188,6 @@ class Config(object):
|
||||
config['version'] = self.version.split('b')[0]
|
||||
config['full_version'] = self.version
|
||||
|
||||
def save(self, config):
|
||||
self.upgrade(config)
|
||||
self._update(config, False)
|
||||
|
||||
with open(self.ctrl.get_path('config.json'), 'w') as f:
|
||||
json.dump(config, f, indent=2)
|
||||
|
||||
os.sync()
|
||||
|
||||
self.ctrl.preplanner.invalidate_all()
|
||||
self.log.info('Saved')
|
||||
|
||||
|
||||
def reset(self):
|
||||
if os.path.exists('config.json'): os.unlink('config.json')
|
||||
self.reload()
|
||||
self.ctrl.preplanner.invalidate_all()
|
||||
|
||||
|
||||
def _encode(self, name, index, config, tmpl, with_defaults):
|
||||
# Handle category
|
||||
@@ -238,6 +237,3 @@ class Config(object):
|
||||
for name, tmpl in self.template.items():
|
||||
conf = config.get(name, None)
|
||||
self._encode(name, '', conf, tmpl, with_defaults)
|
||||
|
||||
|
||||
def reload(self): self._update(self.load(), True)
|
||||
|
||||
@@ -96,7 +96,7 @@ class Planner():
|
||||
'max-merge-error': deviation,
|
||||
'max-arc-error': deviation / 10,
|
||||
'junction-accel': config.get('junction-accel'),
|
||||
}
|
||||
}
|
||||
|
||||
# We place an upper limit of 1000 km/min^3 on jerk for MDI movements
|
||||
if mdi:
|
||||
|
||||
@@ -93,16 +93,15 @@ class State(object):
|
||||
observer.start()
|
||||
|
||||
|
||||
#def is_metric(self): return self.get('units', 'METRIC') == 'METRIC'
|
||||
|
||||
def init(self):
|
||||
# Init machine units
|
||||
metric = self.ctrl.config.get('units', 'METRIC').upper() == 'METRIC'
|
||||
self.log.info('INIT Metric %d' % metric)
|
||||
if not 'metric' in self.vars: self.set('metric', metric)
|
||||
if not 'imperial' in self.vars: self.set('imperial', not metric)
|
||||
#Bit diameter for probing
|
||||
diameter = self.ctrl.config.get('probe-diameter',6.35)
|
||||
|
||||
# Bit diameter for probing
|
||||
diameter = self.ctrl.config.get('probe-diameter', 6.35)
|
||||
self.log.info('INIT Diameter %f' % diameter)
|
||||
self.set('bitDiameter',diameter)
|
||||
|
||||
|
||||
@@ -225,7 +225,8 @@ class PasswordHandler(bbctrl.APIHandler):
|
||||
|
||||
|
||||
class ConfigLoadHandler(bbctrl.APIHandler):
|
||||
def get(self): self.write_json(self.get_ctrl().config.load())
|
||||
def get(self):
|
||||
self.write_json(self.get_ctrl().config.load())
|
||||
|
||||
|
||||
class ConfigDownloadHandler(bbctrl.APIHandler):
|
||||
|
||||
Reference in New Issue
Block a user