Esempio n. 1
0
    def to_json(self, fname, path="data", absolute_path=None):
        self.item = {}
        if absolute_path:
            fname_csv = "{}/{}.csv".format(absolute_path, fname)
            fname_json = "{}/{}.json".format(absolute_path, fname)
        else:
            fname_csv = utils.get_path(fname, path, "csv")
        entries = []
        try:
            with open(fname_csv, encoding="windows-1251", newline='') as csv_file:
                reader = csv.DictReader(csv_file, skipinitialspace=True)
                for entry in reader:
                    entries.append(entry)
                    item = entry.get("syslogEnabled")
                    if item:
                        if item.lower() == "true":
                            entry["syslogEnabled"] = True
                        else :
                            entry["syslogEnabled"] = False

                    #self.Schema.validate(entry)
            if absolute_path:
                Json().writer_full_path(fname_json, entries)
            else:
                Json().writer(fname, entries, path)
        except Exception as err:
            l.logger.error("fname: {} not found".format(fname))
            l.runlogs_logger.error("fname: {} not found".format(fname))
            gv.EOM()
            gv.fake_assert()
        return entries
Esempio n. 2
0
 def _create_output(self, template, fname, context):
     fname_json = utils.get_path(fname, path="data", extension="json")
     with open(fname_json, 'w') as f:
         output = self.render_template(template, context)
         if output is None:
             l.logger.error("failed")
             return
         f.write(output)
         l.logger.debug(fname_json)
Esempio n. 3
0
    def reader(self, fname, path="data"):
        data = None
        try :
            fnameJson = utils.get_path(fname, path, "json")
            json_data=open(fnameJson).read()
            # json_data = json_data.replace("\n","")
            data = json.loads(json_data)
            #l.logger.debug("data: {}".format(data))
        except Exception as err:
            l.logger.error("exception failure fname:{} {}".format(fname, fnameJson))
            l.runlogs_logger.error("exception failure fname:{} {}".format(fname, fnameJson))
            gv.fake_assert()

        return data
Esempio n. 4
0
 def writer(self, fname, data, path="data", absolute_path=None, logPath=False):
     fnameJson = utils.get_path(fname, path, "json")
     self.writer_full_path(fnameJson, data)
     if logPath:
         l.runlogs_logger.info("created: {}".format(fnameJson))
         l.logger.info("created: {}".format(fnameJson))
Esempio n. 5
0
 def to_csv(self, fname, header=None, path="data"):
     fname_csv = utils.get_path(fname, path, 'csv')
     obj = Json()
     json_data = obj.reader(fname, path)
     self.data_to_csv(json_data, fname_csv, header)