Exemple #1
0
 def delete(self, address):
     logging.debug("SiteManager deleted site: %s" % address)
     del(self.sites[address])
     # Delete from sites.json
     sites_settings = json.load(open("%s/sites.json" % config.data_dir))
     del(sites_settings[address])
     helper.atomicWrite("%s/sites.json" % config.data_dir, json.dumps(sites_settings, indent=2, sort_keys=True))
 def save(self):
     s = time.time()
     helper.atomicWrite(
         self.file_path,
         json.dumps(self.file_content, indent=2,
                    sort_keys=True).encode("utf8"))
     self.log.debug("Saved in %.3fs" % (time.time() - s))
Exemple #3
0
 def delete(self, address):
     logging.debug("SiteManager deleted site: %s" % address)
     del(self.sites[address])
     # Delete from sites.json
     sites_settings = json.load(open("%s/sites.json" % config.data_dir))
     del(sites_settings[address])
     helper.atomicWrite("%s/sites.json" % config.data_dir, json.dumps(sites_settings, indent=2, sort_keys=True))
Exemple #4
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))
Exemple #5
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 self.list().iteritems():
            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, json.dumps(data, indent=2, sort_keys=True))
        else:
            self.log.debug("Save error: No data")
        time_write = time.time() - s

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

        self.log.debug("Saved sites in %.2fs (generate: %.2fs, write: %.2fs)" % (time.time() - s, time_generate, time_write))
Exemple #6
0
    def save(self):
        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
        for address, site in self.list().iteritems():
            site.settings["size"] = site.content_manager.getTotalSize()  # Update site size
            data[address] = site.settings
            data[address]["cache"] = {}
            data[address]["cache"]["bad_files"] = site.bad_files
            data[address]["cache"]["hashfield"] = site.content_manager.hashfield.tostring().encode("base64")

        if data:
            helper.atomicWrite("%s/sites.json" % config.data_dir, json.dumps(data, indent=2, sort_keys=True))
        else:
            self.log.debug("Save error: No data")
        # Remove cache from site settings
        for address, site in self.list().iteritems():
            site.settings["cache"] = {}

        self.log.debug("Saved sites in %.2fs" % (time.time() - s))
Exemple #7
0
 def saveSettings(self):
     s = time.time()
     sites_settings = json.load(open("%s/sites.json" % config.data_dir))
     sites_settings[self.address] = self.settings
     helper.atomicWrite(
         "%s/sites.json" % config.data_dir,
         json.dumps(sites_settings, indent=2, sort_keys=True))
     self.log.debug("Saved settings in %.2fs" % (time.time() - s))
Exemple #8
0
 def saveMutes(self):
     helper.atomicWrite(
         "%s/mutes.json" % config.data_dir,
         json.dumps({
             "mutes": mutes,
             "site_blacklist": site_blacklist
         },
                    indent=2,
                    sort_keys=True))
Exemple #9
0
 def save(self):
     if not self.sites:
         logging.error("Save error: No sites found")
     s = time.time()
     data = json.load(open("%s/sites.json" % config.data_dir))
     for address, site in self.list().iteritems():
         data[address] = site.settings
     helper.atomicWrite("%s/sites.json" % config.data_dir, json.dumps(data, indent=2, sort_keys=True))
     logging.debug("Saved sites in %.2fs" % (time.time() - s))
Exemple #10
0
 def save(self):
     if not self.sites:
         self.log.error("Save error: No sites found")
     s = time.time()
     data = {}
     for address, site in self.list().iteritems():
         data[address] = site.settings
     helper.atomicWrite("%s/sites.json" % config.data_dir,
                        json.dumps(data, indent=2, sort_keys=True))
     self.log.debug("Saved sites in %.2fs" % (time.time() - s))
Exemple #11
0
 def save(self):
     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
     helper.atomicWrite("%s/users.json" % config.data_dir, json.dumps(users, indent=2, sort_keys=True))
     self.log.debug("Saved")
Exemple #12
0
 def save(self):
     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
     helper.atomicWrite("%s/users.json" % config.data_dir,
                        json.dumps(users, indent=2, sort_keys=True))
     self.log.debug("Saved")
Exemple #13
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, json.dumps(users, indent=2, sort_keys=True))
     self.log.debug("Saved in %.3fs" % (time.time() - s))
     self.delayed_save_thread = None
Exemple #14
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, json.dumps(users, indent=2, sort_keys=True))
     self.log.debug("Saved in %.3fs" % (time.time() - s))
     self.delayed_save_thread = None
Exemple #15
0
    def writeThread(self, inner_path, content):
        file_path = self.getPath(inner_path)
        # Create dir if not exist
        self.ensureDir(os.path.dirname(inner_path))
        # Write file
        if hasattr(content, 'read'):  # File-like object

            with open(file_path, "wb") as file:
                shutil.copyfileobj(content, file)  # Write buff to disk
        else:  # Simple string
            if inner_path == "content.json" and os.path.isfile(file_path):
                helper.atomicWrite(file_path, content)
            else:
                with open(file_path, "wb") as file:
                    file.write(content)
Exemple #16
0
 def write(self, inner_path, content):
     file_path = self.getPath(inner_path)
     # Create dir if not exist
     file_dir = os.path.dirname(file_path)
     if not os.path.isdir(file_dir):
         os.makedirs(file_dir)
     # Write file
     if hasattr(content, 'read'):  # File-like object
         with open(file_path, "wb") as file:
             shutil.copyfileobj(content, file)  # Write buff to disk
     else:  # Simple string
         if inner_path == "content.json" and os.path.isfile(file_path):
             helper.atomicWrite(file_path, content)
         else:
             with open(file_path, "wb") as file:
                 file.write(content)
     del content
     self.onUpdated(inner_path)
Exemple #17
0
 def write(self, inner_path, content):
     file_path = self.getPath(inner_path)
     # Create dir if not exist
     file_dir = os.path.dirname(file_path)
     if not os.path.isdir(file_dir):
         os.makedirs(file_dir)
     # Write file
     if hasattr(content, 'read'):  # File-like object
         with open(file_path, "wb") as file:
             shutil.copyfileobj(content, file)  # Write buff to disk
     else:  # Simple string
         if inner_path == "content.json" and os.path.isfile(file_path):
             helper.atomicWrite(file_path, content)
         else:
             with open(file_path, "wb") as file:
                 file.write(content)
     del content
     self.onUpdated(inner_path)
Exemple #18
0
 def saveMutes(self):
     helper.atomicWrite("%s/mutes.json" % config.data_dir, json.dumps({"mutes": mutes, "site_blacklist": site_blacklist}, indent=2, sort_keys=True))
Exemple #19
0
 def saveSettings(self):
     sites_settings = json.load(open("%s/sites.json" % config.data_dir))
     sites_settings[self.address] = self.settings
     helper.atomicWrite("%s/sites.json" % config.data_dir, json.dumps(sites_settings, indent=2, sort_keys=True))
Exemple #20
0
 def saveSettings(self):
     sites_settings = json.load(open("%s/sites.json" % config.data_dir))
     sites_settings[self.address] = self.settings
     helper.atomicWrite("%s/sites.json" % config.data_dir, json.dumps(sites_settings, indent=2, sort_keys=True))
Exemple #21
0
 def saveSettings(self):
     s = time.time()
     sites_settings = json.load(open("%s/sites.json" % config.data_dir))
     sites_settings[self.address] = self.settings
     helper.atomicWrite("%s/sites.json" % config.data_dir, json.dumps(sites_settings, indent=2, sort_keys=True))
     self.log.debug("Saved settings in %.2fs" % (time.time() - s))
 def save(self):
     s = time.time()
     helper.atomicWrite(self.file_path, json.dumps(self.file_content, indent=2, sort_keys=True))
     self.log.debug("Saved in %.3fs" % (time.time() - s))