def write(self): f = open(self.__fn(), 'w') try: json.dump(self.content, f, indent=2, default=json.encode) except Exception: pass f.close()
def write_migration_facts(self): migration_date = datetime.now().isoformat() if not os.path.exists(FACT_FILE): f = open(FACT_FILE, 'w') json.dump({"migration.classic_system_id": self.system_id, "migration.migrated_from": self.rhncfg['serverURL'], "migration.migration_date": migration_date}, f) f.close()
def write_avail_pkgs_cache(self, avail_pkgs): try: if not os.access(os.path.dirname(self.CACHE_FILE), os.R_OK): os.makedirs(os.path.dirname(self.CACHE_FILE)) with open(self.CACHE_FILE, "w") as file: json.dump(avail_pkgs, file, default=json.encode) log.debug("Wrote cache: %s" % self.CACHE_FILE) except IOError as err: log.error("Unable to write cache: %s" % self.CACHE_FILE) log.exception(err)
def write_migration_facts(self): migration_date = datetime.now().isoformat() if not os.path.exists(FACT_FILE): f = open(FACT_FILE, 'w') json.dump( { "migration.classic_system_id": self.get_system_id(), "migration.migrated_from": "rhn_hosted_classic", "migration.migration_date": migration_date }, f) f.close()
def __write_cache_file(data, file_name): try: dir_name = os.path.dirname(file_name) if not os.access(dir_name, os.R_OK): log.debug("Try to create directory: %s" % dir_name) os.makedirs(dir_name) with open(file_name, "w") as file: json.dump(data, file, default=json.encode) log.debug("Wrote cache: %s" % file_name) except IOError as err: log.error("Unable to write cache: %s" % file_name) log.exception(err)
def write_migration_facts(self): migration_date = datetime.now().isoformat() if not os.path.exists(FACT_FILE): f = open(FACT_FILE, "w") json.dump( { "migration.classic_system_id": self.get_system_id(), "migration.migrated_from": "rhn_hosted_classic", "migration.migration_date": migration_date, }, f, ) f.close()
def write_cache(self, debug=True): """ Write the current cache to disk. Should only be done after successful communication with the server. The update_check method will call this for you if an update was required, but the method is exposed as some system data can be bundled up with the registration request, after which we need to manually write to disk. """ # Logging in this method (when threaded) can cause a segfault, BZ 988861 and 988430 try: if not os.access(os.path.dirname(self.CACHE_FILE), os.R_OK): os.makedirs(os.path.dirname(self.CACHE_FILE)) f = open(self.CACHE_FILE, "w+") json.dump(self.to_dict(), f, default=json.encode) f.close() if debug: log.debug("Wrote cache: %s" % self.CACHE_FILE) except IOError as err: log.error("Unable to write cache: %s" % self.CACHE_FILE) log.exception(err)