| 6 | |
| 7 | |
| 8 | def update(): |
| 9 | from Config import config |
| 10 | config.parse() |
| 11 | |
| 12 | if getattr(sys, 'source_update_dir', False): |
| 13 | if not os.path.isdir(sys.source_update_dir): |
| 14 | os.makedirs(sys.source_update_dir) |
| 15 | source_path = sys.source_update_dir.rstrip("/") |
| 16 | else: |
| 17 | source_path = os.getcwd().rstrip("/") |
| 18 | |
| 19 | if config.dist_type.startswith("bundle_linux"): |
| 20 | runtime_path = os.path.normpath(os.path.dirname(sys.executable) + "/../..") |
| 21 | else: |
| 22 | runtime_path = os.path.dirname(sys.executable) |
| 23 | |
| 24 | updatesite_path = config.data_dir + "/" + config.updatesite |
| 25 | |
| 26 | sites_json = json.load(open(config.data_dir + "/sites.json")) |
| 27 | updatesite_bad_files = sites_json.get(config.updatesite, {}).get("cache", {}).get("bad_files", {}) |
| 28 | print( |
| 29 | "Update site path: %s, bad_files: %s, source path: %s, runtime path: %s, dist type: %s" % |
| 30 | (updatesite_path, len(updatesite_bad_files), source_path, runtime_path, config.dist_type) |
| 31 | ) |
| 32 | |
| 33 | updatesite_content_json = json.load(open(updatesite_path + "/content.json")) |
| 34 | inner_paths = list(updatesite_content_json.get("files", {}).keys()) |
| 35 | inner_paths += list(updatesite_content_json.get("files_optional", {}).keys()) |
| 36 | |
| 37 | # Keep file only in ZeroNet directory |
| 38 | inner_paths = [inner_path for inner_path in inner_paths if re.match("^(core|bundle)", inner_path)] |
| 39 | |
| 40 | # Checking plugins |
| 41 | plugins_enabled = [] |
| 42 | plugins_disabled = [] |
| 43 | if os.path.isdir("%s/plugins" % source_path): |
| 44 | for dir in os.listdir("%s/plugins" % source_path): |
| 45 | if dir.startswith("disabled-"): |
| 46 | plugins_disabled.append(dir.replace("disabled-", "")) |
| 47 | else: |
| 48 | plugins_enabled.append(dir) |
| 49 | print("Plugins enabled:", plugins_enabled, "disabled:", plugins_disabled) |
| 50 | |
| 51 | update_paths = {} |
| 52 | |
| 53 | for inner_path in inner_paths: |
| 54 | if ".." in inner_path: |
| 55 | continue |
| 56 | inner_path = inner_path.replace("\\", "/").strip("/") # Make sure we have unix path |
| 57 | print(".", end=" ") |
| 58 | if inner_path.startswith("core"): |
| 59 | dest_path = source_path + "/" + re.sub("^core/", "", inner_path) |
| 60 | elif inner_path.startswith(config.dist_type): |
| 61 | dest_path = runtime_path + "/" + re.sub("^bundle[^/]+/", "", inner_path) |
| 62 | else: |
| 63 | continue |
| 64 | |
| 65 | if not dest_path: |