MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / generate_json_file

Function generate_json_file

prepop_cache.py:112–158  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

110
111
112def generate_json_file():
113
114 jsons = get_json_dicts_from_dir(os.path.join(TEMP_CACHE_DIR, "plugin_versions"))
115 main_dict = {}
116 # github_base64s = get_json_dicts_from_dir(GITHUB_PRECACHE_DIR)
117 # gitlab_base64s = get_json_dicts_from_dir(GITLAB_PRECACHE_DIR)
118 # asset_lib_base64s = [(get_asset_lib_plugin_name(file_path), base64) for file_path, base64 in asset_lib_base64s]
119 # github_base64s = [(get_plugin_name_from_file(file_path), base64) for file_path, base64 in github_base64s]
120 # gitlab_base64s = [(get_plugin_name_from_file(file_path), base64) for file_path, base64 in gitlab_base64s]
121 # asset_lib_base64_dict = {plugin_name: base64 for plugin_name, base64 in asset_lib_base64s}
122 # github_base64_dict = {plugin_name: base64 for plugin_name, base64 in github_base64s}
123 # gitlab_base64_dict = {plugin_name: base64 for plugin_name, base64 in gitlab_base64s}
124 # main_dict = {
125 # "asset_lib": asset_lib_base64_dict,
126 # "github": github_base64_dict,
127 # "gitlab": gitlab_base64_dict
128 # }
129 previous_file_size = 0
130 for _, blob in jsons:
131 for _, json_dict in blob.items():
132 release_info = json_dict["release_info"]
133 key = (
134 release_info["plugin_source"]
135 + "-"
136 + str(release_info["primary_id"])
137 + "-"
138 + str(release_info["secondary_id"])
139 )
140 main_dict[key] = json_dict
141 # sort dict
142 main_dict = dict(sorted(main_dict.items()))
143 dest_path = JSON_DST_PATH
144 already_exists = os.path.exists(JSON_DST_PATH)
145 if already_exists:
146 # check the file_size
147 previous_file_size = os.path.getsize(JSON_DST_PATH)
148 dest_path = JSON_DST_PATH + ".tmp"
149 with open(dest_path, "w") as f:
150 json.dump(main_dict, f)
151 # if os.path.getsize(dest_path) < previous_file_size:
152 # print("File size decreased, aborting")
153 # # remove the tmp file
154 # os.remove(dest_path)
155 # sys.exit(1)
156 if already_exists:
157 # rename the tmp file to the original file
158 os.rename(dest_path, JSON_DST_PATH)
159
160
161def prepop_cache():

Callers 1

prepop_cache.pyFile · 0.85

Calls 3

get_json_dicts_from_dirFunction · 0.85
dumpMethod · 0.80
renameMethod · 0.80

Tested by

no test coverage detected