Ejemplo n.º 1
0
Archivo: base.py Proyecto: nbashev/noc
 def save_state(self):
     """
     Save current state
     """
     if not self.new_state_path:
         return
     self.logger.info("Summary: %d new, %d changed, %d removed", self.c_add,
                      self.c_change, self.c_delete)
     self.logger.info("Error delete by referred: %s",
                      "\n".join(b.json() for _, b in self.referred_errors))
     t = time.localtime()
     archive_path = os.path.join(
         self.archive_dir,
         compressor.get_path("import-%04d-%02d-%02d-%02d-%02d-%02d.jsonl" %
                             tuple(t[:6])),
     )
     self.logger.info("Moving %s to %s", self.new_state_path, archive_path)
     if self.new_state_path.endswith(compressor.ext):
         # Simply move the file
         shutil.move(self.new_state_path, archive_path)
     else:
         # Compress the file
         self.logger.info("Compressing")
         with open(self.new_state_path,
                   "r") as s, compressor(archive_path, "w") as d:
             d.write(s.read())
         os.unlink(self.new_state_path)
     self.logger.info("Saving mappings to %s", self.mappings_path)
     mdata = "\n".join("%s,%s" % (k, self.mappings[k])
                       for k in sorted(self.mappings))
     safe_rewrite(self.mappings_path, mdata)
Ejemplo n.º 2
0
Archivo: base.py Proyecto: nbashev/noc
 def get_new_state(self) -> Optional[TextIOWrapper]:
     """
     Returns file object of new state, or None when not present
     """
     # Try import.csv
     path = compressor.get_path(
         os.path.join(self.import_dir, "import.jsonl"))
     if not os.path.isfile(path):
         return None
     logger.info("Loading from %s", path)
     self.new_state_path = path
     return compressor(path, "r").open()
Ejemplo n.º 3
0
Archivo: base.py Proyecto: nbashev/noc
 def get_new_state(self) -> io.TextIOWrapper:
     self.ensure_import_dir()
     path = compressor.get_path(os.path.join(self.import_dir, "import.jsonl"))
     self.logger.info("Writing to %s", path)
     return compressor(path, "w").open()
Ejemplo n.º 4
0
Archivo: base.py Proyecto: nbashev/noc
 def get_problem_file(self) -> io.TextIOWrapper:
     self.ensure_import_dir()
     path = compressor.get_path(os.path.join(self.import_dir, "import.csv.rej"))
     self.logger.info("Writing to %s", path)
     return compressor(path, "w").open()