MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / loadSettings

Method loadSettings

src/Site/Site.py:89–119  ·  view source on GitHub ↗
(self, settings=None)

Source from the content-addressed store, hash-verified

87
88 # Load site settings from data/sites.json
89 def loadSettings(self, settings=None):
90 if not settings:
91 settings = json.load(open("%s/sites.json" % config.data_dir)).get(self.address)
92 if settings:
93 self.settings = settings
94 if "cache" not in settings:
95 settings["cache"] = {}
96 if "size_files_optional" not in settings:
97 settings["size_optional"] = 0
98 if "optional_downloaded" not in settings:
99 settings["optional_downloaded"] = 0
100 if "downloaded" not in settings:
101 settings["downloaded"] = settings.get("added")
102 self.bad_files = settings["cache"].get("bad_files", {})
103 settings["cache"]["bad_files"] = {}
104 # Give it minimum 10 tries after restart
105 for inner_path in self.bad_files:
106 self.bad_files[inner_path] = min(self.bad_files[inner_path], 20)
107 else:
108 self.settings = {
109 "own": False, "serving": True, "permissions": [], "cache": {"bad_files": {}}, "size_files_optional": 0,
110 "added": int(time.time()), "downloaded": None, "optional_downloaded": 0, "size_optional": 0
111 } # Default
112 if config.download_optional == "auto":
113 self.settings["autodownloadoptional"] = True
114
115 # Add admin permissions to homepage
116 if self.address in (config.homepage, config.updatesite) and "ADMIN" not in self.settings["permissions"]:
117 self.settings["permissions"].append("ADMIN")
118
119 return
120
121 # Save site settings to data/sites.json
122 def saveSettings(self):

Callers 1

__init__Method · 0.95

Calls 2

getMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected