def leo_echo_cb(out, err, code, ent): arg = ent['arg'] g.es("> " + arg[0] + " " + repr(arg[1:]) ) if out: g.es(out) if err: g.es_error(err)
def leo_echo_cb(out, err, code, ent): arg = ent['arg'] g.es("> " + arg[0] + " " + repr(arg[1:])) if out: g.es(out) if err: g.es_error(err)
def init_dict(c): """ (Re)Initialize the formats dictionary """ cs = str(c) try: fbody = g.findNodeAnywhere(c, "Headline Formats").b except Exception as e: g.es_trace("This outline has no Headline Formats node\n" + str(e)) return try: # There is something wrong. Both pylint and mypy complain. # pylint: disable=no-value-for-parameter formats = yaml.load(fbody) # type:ignore except Exception as e: g.es_trace("Could not parse Headline Format yaml file\n" + str(e)) return try: formats = formats["Headline Formats"] except Exception as e: g.es_trace("Yaml file does not have proper heading.\n" + str(e)) return #preprocess multi headline styles g.app.permanentScriptDict[cs + 'formats'] = {} try: for k, f in formats.items(): if "`" in k: _ = k.split("`") for _1 in _: g.app.permanentScriptDict[cs + 'formats'][_1.strip()] = f else: g.app.permanentScriptDict[cs + 'formats'][k] = f except Exception as e: g.es_error(e)
def init_dict(c): """ (Re)Initialize the formats dictionary """ cs = str(c) try: fbody = g.findNodeAnywhere(c, "Headline Formats").b except Exception as e: g.es_trace("This outline has no Headline Formats node\n" + str(e)) return try: formats = yaml.load(fbody) except Exception as e: g.es_trace("Could not parse Headline Format yaml file\n" + str(e)) return try: formats = formats["Headline Formats"] except Exception as e: g.es_trace("Yaml file does not have proper heading.\n" + str(e)) return #preprocess multi headline styles g.app.permanentScriptDict[cs + 'formats'] = {} try: for k, f in formats.items(): if "`" in k: _ = k.split("`") for _1 in _: g.app.permanentScriptDict[cs + 'formats'][_1.strip()] = f else: g.app.permanentScriptDict[cs + 'formats'][k] = f except Exception as e: g.es_error(e)
def update_vs(self): ''' Evaluate @r <expr> nodes, puting the result in their body text. Output @vso nodes, based on file extension ''' c = self.c for p in c.all_unique_positions(): h = p.h.strip() if h.startswith('@r '): expr = h[3:].strip() try: result = eval(expr,self.d) except Exception: g.es_exception() g.es("Failed to render " + h) continue self.render_value(p,result) if h.startswith("@vso "): expr = h[5:].strip() bname, ext = os.path.splitext(expr) try: result = eval(bname,self.d) except Exception: g.es_exception() g.es("@vso failed: " + h) continue if ext.lower() == '.json': cnt = json.dumps(result, indent = 2) pth = os.path.join(c.getNodePath(p), expr) self.render_value(p, cnt) g.es("Writing @vso: " + pth) open(pth, "w").write(cnt) else: g.es_error("Unknown vso extension (should be .json, ...): " + ext)
def update_vs(self): ''' Evaluate @r <expr> nodes, puting the result in their body text. Output @vso nodes, based on file extension ''' c = self.c for p in c.all_unique_positions(): h = p.h.strip() if h.startswith('@r '): if self.trace and self.verbose: g.trace('pass2:',p.h) expr = h[3:].strip() try: result = eval(expr,self.d) except: g.es_exception() g.es("Failed to render " + h) continue if self.trace: print("Eval:",expr,"result:",repr(result)) self.render_value(p,result) if h.startswith("@vso "): expr = h[5:].strip() bname, ext = os.path.splitext(expr) try: result = eval(bname,self.d) except: g.es_exception() g.es("@vso failed: " + h) continue if ext.lower() == '.json': cnt = json.dumps(result, indent = 2) pth = os.path.join(c.getNodePath(p), expr) self.render_value(p, cnt) g.es("Writing @vso: " + pth) open(pth, "w").write(cnt) else: g.es_error("Unknown vso extension (should be .json, ...): " + ext) # dump file as json pass
def phaseError(self): g.es_error('command not valid in phase: %s'%self.phase)