def run(self, data, config=None, pipeline=None): """Write file.""" with Stream(self.output, "w") as out: for key1, value1 in data.items(): out.write(key1 + ":" + str(type(value1)) + "\n") # If it is a list then if isinstance(value1, list): value1 = value1[0] if isinstance(value1, dict): for key2, value2 in value1.items(): out.write("\t" + key2 + ":" + str(type(value2)) + "\n") return data
def run(self, data, config=None, pipeline=None): """Write CSV file.""" jmespath_opts = jmespath.Options(custom_functions=JMESExtensions(data)) results = jmespath.search(self.select_expr, data, jmespath_opts) with Stream(self.output, "w") as csv_out: if not results: print("# No results", file=csv_out) else: writer = csv.DictWriter(csv_out, sorted(results[0].keys()), restval=self.null_placeholder) if self.header: writer.writeheader() for record in results: self._fill_placeholders(record) writer.writerow(record) return data
def run(self, data, config=None, pipeline=None): """Load pipeline state from pickle.""" with Stream(self.input_source, "rb") as in_fh: loaded = pickle.load(in_fh) data.update(loaded) return data
def run(self, data, config=None, pipeline=None): with Stream(self.input_source, "r") as in_fh: loaded = yaml.load(in_fh, SafeLoader) data.update(loaded) return data
def run(self, data, config=None, pipeline=None): """Dump pipeline state.""" with Stream(self.input_source, "r") as in_fh: loaded = json.load(in_fh) data.update(loaded) return data
def run(self, data, config=None, pipeline=None): with Stream(self.output, "wb") as out_fh: pickle.dump(self._filter(data), out_fh) return data
def run(self, data, config=None, pipeline=None): with Stream(self.output, "w") as out_fh: yaml.dump(self._filter(data), out_fh, Dumper=YamlStateDumper) return data
def run(self, data, config=None, pipeline=None): """Dump pipeline state.""" with Stream(self.output, "w") as out_fh: json.dump(self._filter(data), out_fh, cls=JsonStateEncoder) return data
def __init__(self, file, query_name): """Parse a tabulated file produced by an hhsuite tool.""" self.hits = [] self.query_name = query_name with Stream(file, "r") as fh: self._parse_file(fh)