def execute(self): for rec in sane_yaml.load_all(sys.stdin): for fn in self.ns.fieldname: if fn in rec: del rec[fn] print("---") sys.stdout.write(sane_yaml.dump(rec))
def execute(self): l = list(sane_yaml.load_all(sys.stdin)) l.sort(key=cmp_to_key(self.cmp_keys)) for d in l: print("---") sys.stdout.write(sane_yaml.dump(d))
def execute(self): ustrings = set(self.ns.string) for i, rec in enumerate(sane_yaml.load_all(sys.stdin)): if self.ns.fieldname in rec: if type(rec[self.ns.fieldname]) is not list: raise DataError( "unappend: expecting list under fieldname %s in %s, got %s instead" % (self.ns.fieldname, describe_record( i, rec), type(rec[self.ns.fieldname]))) rec[self.ns.fieldname] = list( set(rec[self.ns.fieldname]) - ustrings) print("---") sys.stdout.write(sane_yaml.dump(rec))
def execute(self): for i,rec in enumerate(sane_yaml.load_all(sys.stdin)): if self.ns.fieldname in rec: value=rec[self.ns.fieldname] if type(value) is not list: raise DataError("append: expecting a list under %s in %s, got %s instead" % (self.ns.fieldname,describe_record(i,rec),type(value))) value.extend(self.ns.string) value=list(set(value)) rec[self.ns.fieldname]=value else: rec[self.ns.fieldname]=[s for s in self.ns.string] print("---") sys.stdout.write(sane_yaml.dump(rec))
def execute(self): everything = [BibRecord(d) for d in sane_yaml.load_all(sys.stdin)] if any("key" not in rec for rec in everything): print("checkdups: All records MUST have a key field", file=sys.stderr) dupkeys = [] for rec1 in everything: for rec2 in everything: if rec1["key"] <= rec2["key"]: continue if all( strongly_similar(rec1, rec2, fn) for fn in self.ns.fieldname): dupkeys.append([rec1["key"], rec2["key"]]) sys.stdout.write(sane_yaml.dump(dupkeys))
def execute(self): for i,rec in enumerate(sane_yaml.load_all(sys.stdin)): if self.ns.fieldname in rec: if type(rec[self.ns.fieldname]) in (str,str): for pat,repl_with in self.rules: rec[self.ns.fieldname]=pat.sub(repl_with,rec[self.ns.fieldname]) elif type(rec[self.ns.fieldname]) is not list: raise DataError("rewrite: %s in %s is %s, expected a string or list" % (self.ns.fieldname,describe_record(i,rec),type(rec[self.ns.fieldname]))) for pat,repl_with in self.rules: new=[] for s in rec[self.ns.fieldname]: new.append(pat.sub(repl_with,s)) rec[self.ns.fieldname]=new print("---") sys.stdout.write(sane_yaml.dump(rec))
def execute(self): records = list(sane_yaml.load_all(sys.stdin)) key_dict = {} edge_tags = {} records_new = [] for rec in records: if "key" in rec: key_dict[rec["key"]] = rec records_new.append(rec) records = records_new for rec in records: if "myown" not in rec: rec["myown"] = False if not "citedby" in rec: rec["citedby"] = [] if not "cites" in rec: rec["cites"] = [] cites_objects = [] for key in rec["cites"]: if ';' in key: key, tags_s = key.split(';') tags = tags_s.split(' ') edge_tags[(rec["key"], key)] = tags else: edge_tags[(rec["key"], key)] = [] if key not in key_dict: continue cites_objects.append(key_dict[key]) rec["cites"] = cites_objects rec["cited_times"] = 0 for rec in records: if rec["myown"]: continue for cited in rec["cites"]: cited["cited_times"] += 1 cited["citedby"].append(rec) if self.cmp_keys: for rec in records: rec["citedby"].sort(cmp=self.cmp_keys) env = Environment(loader=FileSystemLoader(self.ns.template_dir), line_statement_prefix="#") env.filters['authorsformat'] = authors_format t = env.get_template(self.ns.template) sys.stdout.write( t.render(citation_tags=edge_tags, records=records, extra=self.extra))
def execute(self): exceptions=0 for i,rec in enumerate(sane_yaml.load_all(sys.stdin)): try: exec(self.ns.statement, self.mods,rec) except: if self.ns.failed: print("---") sys.stdout.write(sane_yaml.dump(rec)) elif self.ns.keep_going: exceptions+=1 print("exec: Warning: failed on %s" % describe_record(i,rec), file=sys.stderr) print("exec: The exception was %s" % sys.exc_info()[0], file=sys.stderr) else: raise if not self.ns.no_output and not self.ns.failed: print("---") sys.stdout.write(sane_yaml.dump(rec)) if exceptions and not self.ns.failed: print("exec: Warning: there were %d exceptions" % exceptions, file=sys.stderr)
def execute(self): for i, rec in enumerate(sane_yaml.load_all(sys.stdin)): rec[self.ns.fieldname] = eval(self.ns.value, {}) print("---") sys.stdout.write(sane_yaml.dump(rec))