Example #1
0
    def save(self, recalculate_size=False):
        if not self.sites:
            self.log.debug("Save skipped: No sites found")
            return
        if not self.loaded:
            self.log.debug("Save skipped: Not loaded")
            return
        s = time.time()
        data = {}
        # Generate data file
        s = time.time()
        for address, site in list(self.list().items()):
            if recalculate_size:
                site.settings["size"], site.settings[
                    "size_optional"] = site.content_manager.getTotalSize(
                    )  # Update site size
            data[address] = site.settings
            data[address]["cache"] = site.getSettingsCache()
        time_generate = time.time() - s

        s = time.time()
        if data:
            helper.atomicWrite("%s/sites.json" % config.data_dir,
                               helper.jsonDumps(data).encode("utf8"))
        else:
            self.log.debug("Save error: No data")
        time_write = time.time() - s

        # Remove cache from site settings
        for address, site in self.list().items():
            site.settings["cache"] = {}

        self.log.debug("Saved sites in %.2fs (generate: %.2fs, write: %.2fs)" %
                       (time.time() - s, time_generate, time_write))
Example #2
0
 def save(self):
     s = time.time()
     users = json.load(open("%s/users.json" % config.data_dir))
     if self.master_address not in users:
         users[self.master_address] = {}  # Create if not exist
     user_data = users[self.master_address]
     if self.master_seed:
         user_data["master_seed"] = self.master_seed
     user_data["sites"] = self.sites
     user_data["certs"] = self.certs
     user_data["settings"] = self.settings
     helper.atomicWrite("%s/users.json" % config.data_dir,
                        helper.jsonDumps(users).encode("utf8"))
     self.log.debug("Saved in %.3fs" % (time.time() - s))
     self.delayed_save_thread = None
Example #3
0
 def writeJson(self, inner_path, data):
     # Write to disk
     self.write(inner_path, helper.jsonDumps(data).encode("utf8"))