mirror of
				https://github.com/Neocky/pluGET.git
				synced 2024-04-29 16:12:30 +00:00 
			
		
		
		
	Merge pull request #54 from smcclennon/dev/1.7.1
Handle Spiget api errors, use best-practice, disable incompatible code
This commit is contained in:
		| @@ -6,8 +6,8 @@ import os | ||||
|  | ||||
| try: | ||||
|     print("Installing Python packages and dependencies from requirements.txt...\n") | ||||
|     os.system('py -m pip install -r requirements.txt' if os.name=='nt' else 'pip install -r requirements.txt') | ||||
|     os.system('py -m pip install -r requirements.txt' if os.name=='nt' else 'python3 -m pip install -r requirements.txt') | ||||
|     print("\nStart pluGET by launching the 'pluGET.py' file!") | ||||
| except: | ||||
|     print("Requirements couldn't be installed. Check if file 'requirements.txt' is in the same folder and that Python3\ | ||||
| except Exception as e: | ||||
|     print(f"Requirements couldn't be installed.\nError message: {e}\n\nCommon solution: Check if file 'requirements.txt' is in the same folder and that Python3\ | ||||
|          and pip is installed!") | ||||
|   | ||||
| @@ -520,49 +520,61 @@ def search_plugin_spiget(plugin_file: str, plugin_file_name: str, plugin_file_ve | ||||
|     """ | ||||
|     url = f"https://api.spiget.org/v2/search/resources/{plugin_file_name}?field=name&sort=-downloads" | ||||
|     plugin_list = api_do_request(url) | ||||
|     plugin_file_version2 = plugin_file_version | ||||
|     for i in range(4): | ||||
|         if i == 1: | ||||
|             plugin_file_version2 = re.sub(r'(\-\w*)', '', plugin_file_version) | ||||
|         if i == 2: | ||||
|             plugin_name_in_yml, plugin_version_in_yml = egg_cracking_jar(plugin_file) | ||||
|             url = f"https://api.spiget.org/v2/search/resources/{plugin_name_in_yml}?field=name&sort=-downloads" | ||||
|             try: | ||||
|                 plugin_list = api_do_request(url) | ||||
|             except ValueError: | ||||
|                 continue | ||||
|             # if no plugin name was found with egg_cracking_jar() skip this round | ||||
|             if plugin_list is None: | ||||
|                 continue | ||||
|  | ||||
|         # search with version which is in plugin.yml for the plugin | ||||
|         if i == 3: | ||||
|             plugin_file_version2 = plugin_version_in_yml | ||||
|     # Handle failed api request | ||||
|     """ | ||||
|     {'error': 'Unexpected Exception', 'msg': 'Unexpected Exception. Please report this to  | ||||
|     https://github.com/SpiGetOrg/api.spiget.org/issues'} | ||||
|     """ | ||||
|     if "error" in plugin_list: | ||||
|         rich_print_error( | ||||
|             f"[not bold]Error: Spiget error occurred whilst searching for plugin '{plugin_file}': {plugin_list['msg']}" | ||||
|         ) | ||||
|         return plugin_list['msg'] | ||||
|     else: | ||||
|         plugin_file_version2 = plugin_file_version | ||||
|         for i in range(4): | ||||
|             if i == 1: | ||||
|                 plugin_file_version2 = re.sub(r'(\-\w*)', '', plugin_file_version) | ||||
|             if i == 2: | ||||
|                 plugin_name_in_yml, plugin_version_in_yml = egg_cracking_jar(plugin_file) | ||||
|                 url = f"https://api.spiget.org/v2/search/resources/{plugin_name_in_yml}?field=name&sort=-downloads" | ||||
|                 try: | ||||
|                     plugin_list = api_do_request(url) | ||||
|                 except ValueError: | ||||
|                     continue | ||||
|                 # if no plugin name was found with egg_cracking_jar() skip this round | ||||
|                 if plugin_list is None: | ||||
|                     continue | ||||
|  | ||||
|             # search with version which is in plugin.yml for the plugin | ||||
|             if i == 3: | ||||
|                 plugin_file_version2 = plugin_version_in_yml | ||||
|  | ||||
|  | ||||
|         for plugin in plugin_list: | ||||
|             plugin_id = plugin["id"] | ||||
|             url2 = f"https://api.spiget.org/v2/resources/{plugin_id}/versions?size=100&sort=-name" | ||||
|             try: | ||||
|                 plugin_versions = api_do_request(url2) | ||||
|             except ValueError: | ||||
|                 continue | ||||
|             if plugin_versions is None: | ||||
|                 continue | ||||
|             for updates in plugin_versions: | ||||
|                 update_version_name = updates["name"] | ||||
|                 if plugin_file_version2 in update_version_name: | ||||
|                     #spigot_update_id = updates["id"] | ||||
|                     plugin_latest_version = get_latest_plugin_version_spiget(plugin_id) | ||||
|                     plugin_is_outdated = compare_plugin_version(plugin_latest_version, update_version_name) | ||||
|                     Plugin.add_to_plugin_list( | ||||
|                         plugin_file, | ||||
|                         plugin_file_name, | ||||
|                         plugin_file_version, | ||||
|                         plugin_latest_version, | ||||
|                         plugin_is_outdated, | ||||
|                         "spigot", | ||||
|                         [plugin_id] | ||||
|                     ) | ||||
|                     return plugin_id | ||||
|     return None | ||||
|             for plugin in plugin_list: | ||||
|                 plugin_id = plugin["id"] | ||||
|                 url2 = f"https://api.spiget.org/v2/resources/{plugin_id}/versions?size=100&sort=-name" | ||||
|                 try: | ||||
|                     plugin_versions = api_do_request(url2) | ||||
|                 except ValueError: | ||||
|                     continue | ||||
|                 if plugin_versions is None: | ||||
|                     continue | ||||
|                 for updates in plugin_versions: | ||||
|                     update_version_name = updates["name"] | ||||
|                     if plugin_file_version2 in update_version_name: | ||||
|                         #spigot_update_id = updates["id"] | ||||
|                         plugin_latest_version = get_latest_plugin_version_spiget(plugin_id) | ||||
|                         plugin_is_outdated = compare_plugin_version(plugin_latest_version, update_version_name) | ||||
|                         Plugin.add_to_plugin_list( | ||||
|                             plugin_file, | ||||
|                             plugin_file_name, | ||||
|                             plugin_file_version, | ||||
|                             plugin_latest_version, | ||||
|                             plugin_is_outdated, | ||||
|                             "spigot", | ||||
|                             [plugin_id] | ||||
|                         ) | ||||
|                         return plugin_id | ||||
|         return None | ||||
|   | ||||
| @@ -21,7 +21,8 @@ def rename_console_title() -> None: | ||||
|     """ | ||||
|     Renames the console title on first startup | ||||
|     """ | ||||
|     os.system("title " + "pluGET │ By Neocky") | ||||
|     if os.name == "nt": | ||||
|         os.system("title " + "pluGET │ By Neocky") | ||||
|     return None | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Neocky
					Neocky