Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
 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
Пример #4
0
 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
Пример #5
0
 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
Пример #6
0
 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
Пример #7
0
 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
Пример #8
0
 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
Пример #9
0
 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)