()
| 110 | |
| 111 | |
| 112 | def 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 | |
| 161 | def prepop_cache(): |
no test coverage detected