def get_client_info(self): """get client info: returns json dictionary of client information """ out = {} client = self.larch.symtable._sys.client for attr in dir(client): out[attr] = getattr(client, attr) return encode4js(out)
def onSaveFit(self, event=None): dgroup = self.get_datagroup() deffile = dgroup.filename.replace(".", "_") + ".fitconf" outfile = FileSave(self, "Save Fit Configuration and Results", default_file=deffile, wildcard=FITCONF_WILDCARDS) if outfile is None: return buff = ["#XYFit Config version 1"] buff.append(json.dumps(encode4js(self.summary), encoding="UTF-8", default=str)) buff.append("") try: fout = open(outfile, "w") fout.write("\n".join(buff)) fout.close() except IOError: print("could not write %s" % outfile)
def save(fname, *args, **kws): """save groups and data into a portable json file save(fname, arg1, arg2, ....) Parameters ---------- fname name of output save file. args list of groups, data items to be saved. See Also: restore() """ _larch = kws.get('_larch', None) isgroup = _larch.symtable.isgroup expr = getattr(_larch, 'this_expr', 'save(foo)') expr = expr.replace('\n', ' ').replace('\r', ' ') grouplist = _larch.symtable._sys.saverestore_groups[:] buff = [ "#Larch Save File: 1.0", "#save.date: %s" % time.strftime('%Y-%m-%d %H:%M:%S'), "#save.command: %s" % expr, "#save.nitems: %i" % len(args) ] names = [] if expr.startswith('save('): names = [a.strip() for a in expr[5:-1].split(',')] try: names.pop(0) except: pass if len(names) < len(args): names.extend(["_unknown_"] * (len(args) - len(names))) for name, arg in zip(names, args): buff.append("#=> %s" % name) buff.append(json.dumps(encode4js(arg, grouplist=grouplist))) buff.append("") with open(fname, "w") as fh: fh.write("\n".join(buff))
def onSaveFit(self, event=None): dgroup = self.get_datagroup() deffile = dgroup.filename.replace('.', '_') + '.fitconf' outfile = FileSave(self, 'Save Fit Configuration and Results', default_file=deffile, wildcard=FITCONF_WILDCARDS) if outfile is None: return buff = ['#XYFit Config version 1'] buff.append(json.dumps(encode4js(self.summary), encoding='UTF-8',default=str)) buff.append('') try: fout = open(outfile, 'w') fout.write('\n'.join(buff)) fout.close() except IOError: print('could not write %s' % outfile)
def save(fname, *args, **kws): """save groups and data into a portable json file save(fname, arg1, arg2, ....) Parameters ---------- fname name of output save file. args list of groups, data items to be saved. See Also: restore() """ _larch = kws.get('_larch', None) isgroup = _larch.symtable.isgroup expr = getattr(_larch, 'this_expr', 'save(foo)') expr = expr.replace('\n', ' ').replace('\r', ' ') grouplist = _larch.symtable._sys.saverestore_groups[:] buff = ["#Larch Save File: 1.0", "#save.date: %s" % time.strftime('%Y-%m-%d %H:%M:%S'), "#save.command: %s" % expr, "#save.nitems: %i" % len(args)] names = [] if expr.startswith('save('): names = [a.strip() for a in expr[5:-1].split(',')] try: names.pop(0) except: pass if len(names) < len(args): names.extend(["_unknown_"]*(len(args) - len(names))) for name, arg in zip(names, args): buff.append("#=> %s" % name) buff.append(json.dumps(encode4js(arg, grouplist=grouplist))) buff.append("") with open(fname, "w") as fh: fh.write("\n".join(buff))
def get_data(self, expr): "return json encoded data for a larch expression" self.keep_alive_time = time.time() + self.IDLE_TIME return encode4js(self.larch.eval(expr))
def encode(obj): out = encode4js(obj) print("Encoded to: ", out) return out
def get_data(self, expr): "return json encoded data for a larch expression" self.larch('_sys.client.last_event = %i' % time()) return encode4js(self.larch.eval(expr))
def get_data(self, expr): "return json encoded data for a larch expression" return encode4js(self.larch.eval(expr))