mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
Added search function
This commit is contained in:
parent
e229324117
commit
d427886c49
@ -12,7 +12,7 @@ try:
|
|||||||
from src.utils.utilities import check_requirements, api_test_spiget
|
from src.utils.utilities import check_requirements, api_test_spiget
|
||||||
from src.handlers.handle_input import handle_input
|
from src.handlers.handle_input import handle_input
|
||||||
except:
|
except:
|
||||||
print("Folder 'src' not found in the directory or missing files detected! \
|
print("Folder 'src' not found in the directory or missing files or broken functions detected! \
|
||||||
\nPlease redownload the files from here: https://www.github.com/Neocky/pluGET")
|
\nPlease redownload the files from here: https://www.github.com/Neocky/pluGET")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ if __name__ == "__main__":
|
|||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||||
#parser.add_argument("-a", "--archive", action="store_true", help="archive mode")
|
#parser.add_argument("-a", "--archive", action="store_true", help="archive mode")
|
||||||
#parser.add_argument("--exclude", help="files to exclude")
|
#parser.add_argument("--exclude", help="files to exclude")
|
||||||
parser.add_argument("mode", help="Mode (install/update)", nargs='?', default=None)
|
parser.add_argument("mode", help="Mode (install/update/etc.)", nargs='?', default=None)
|
||||||
parser.add_argument("object", help="Object/Plugin Name", nargs='?', default=None)
|
parser.add_argument("object", help="Object/Plugin Name", nargs='?', default=None)
|
||||||
parser.add_argument("version", help="Version", nargs='?', default=None)
|
parser.add_argument("version", help="Version", nargs='?', default=None)
|
||||||
args = vars(parser.parse_args())
|
args = vars(parser.parse_args())
|
||||||
|
@ -11,9 +11,9 @@ from rich.console import Console
|
|||||||
|
|
||||||
class config_value():
|
class config_value():
|
||||||
"""
|
"""
|
||||||
Class which holds all the available configuration values from the config file and which will be used later in
|
Class which holds all the available configuration values from the config file and which will be used later in
|
||||||
the process of updating plugins
|
the process of updating plugins
|
||||||
If bool in config can't be read it will default to 'False'
|
If bool in config can't be read it will default to 'False'
|
||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
yaml = ruamel.yaml.YAML()
|
yaml = ruamel.yaml.YAML()
|
||||||
@ -35,8 +35,8 @@ class config_value():
|
|||||||
|
|
||||||
def check_config() -> None:
|
def check_config() -> None:
|
||||||
"""
|
"""
|
||||||
Check if there is a pluGET_config.yml file in the same folder as pluget.py and if not create a new config
|
Check if there is a pluGET_config.yml file in the same folder as pluget.py and if not create a new config
|
||||||
and exit the programm
|
and exit the programm
|
||||||
"""
|
"""
|
||||||
if not os.path.isfile("pluGET_config.yaml"):
|
if not os.path.isfile("pluGET_config.yaml"):
|
||||||
create_config()
|
create_config()
|
||||||
@ -44,7 +44,7 @@ def check_config() -> None:
|
|||||||
|
|
||||||
def create_config() -> None:
|
def create_config() -> None:
|
||||||
"""
|
"""
|
||||||
Creates the yaml config in the current directory with the filename pluGET_config.yml
|
Creates the yaml config in the current directory with the filename pluGET_config.yml
|
||||||
"""
|
"""
|
||||||
# this is the whole yaml code because of weird formating indention is not possible
|
# this is the whole yaml code because of weird formating indention is not possible
|
||||||
configuration = """\
|
configuration = """\
|
||||||
@ -90,7 +90,7 @@ def create_config() -> None:
|
|||||||
|
|
||||||
def validate_config() -> None:
|
def validate_config() -> None:
|
||||||
"""
|
"""
|
||||||
Validates the config variables after config class is loaded and exit if error is detected and print error
|
Validates the config variables after config class is loaded and exit if error is detected and print error
|
||||||
"""
|
"""
|
||||||
accepted_values = [
|
accepted_values = [
|
||||||
("local", "sftp", "ftp")
|
("local", "sftp", "ftp")
|
||||||
|
@ -3,7 +3,7 @@ Handles the input through the pluGET command line
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from src.utils.console_output import rich_print_error
|
from src.utils.console_output import rich_print_error
|
||||||
from src.plugin.plugin_downloader import get_specific_plugin
|
from src.plugin.plugin_downloader import get_specific_plugin, search_specific_plugin
|
||||||
|
|
||||||
|
|
||||||
# check
|
# check
|
||||||
@ -60,8 +60,7 @@ def handle_input(input_command=None, input_selected_object=None, input_parameter
|
|||||||
#checkInstalledPackage(inputSelectedObject, inputParams)
|
#checkInstalledPackage(inputSelectedObject, inputParams)
|
||||||
|
|
||||||
case "search":
|
case "search":
|
||||||
print("search package")
|
search_specific_plugin(input_selected_object)
|
||||||
#searchPackage(inputSelectedObject)
|
|
||||||
case "remove":
|
case "remove":
|
||||||
print("remove package")
|
print("remove package")
|
||||||
#removePlugin(inputSelectedObject)
|
#removePlugin(inputSelectedObject)
|
||||||
@ -85,7 +84,7 @@ def get_input() -> None:
|
|||||||
Gets command line input and calls the handle input function
|
Gets command line input and calls the handle input function
|
||||||
"""
|
"""
|
||||||
input_command = None
|
input_command = None
|
||||||
print("'STRG + C' to exit")
|
print("\n'STRG + C' to exit")
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
input_command, input_selected_object, *input_parameter = input("pluGET >> ").split()
|
input_command, input_selected_object, *input_parameter = input("pluGET >> ").split()
|
||||||
|
@ -4,10 +4,10 @@ File and functions which handle the download of the specific plugins
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from urllib.error import HTTPError
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import rich
|
from rich.table import Table
|
||||||
|
from rich.console import Console
|
||||||
|
|
||||||
from src.utils.utilities import convert_file_size_down, remove_temp_plugin_folder, create_temp_plugin_folder
|
from src.utils.utilities import convert_file_size_down, remove_temp_plugin_folder, create_temp_plugin_folder
|
||||||
from src.utils.utilities import api_do_request
|
from src.utils.utilities import api_do_request
|
||||||
@ -167,3 +167,53 @@ def get_specific_plugin(plugin_id, plugin_version="latest") -> None:
|
|||||||
if config_values.connection != "local":
|
if config_values.connection != "local":
|
||||||
remove_temp_plugin_folder()
|
remove_temp_plugin_folder()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def search_specific_plugin(plugin_name) -> None:
|
||||||
|
"""
|
||||||
|
Search for a name and return the top 10 results sorted for their download count
|
||||||
|
Then ask for input and download that plugin
|
||||||
|
"""
|
||||||
|
url= f"https://api.spiget.org/v2/search/resources/{plugin_name}?field=name&sort=-downloads"
|
||||||
|
plugin_search_results = api_do_request(url)
|
||||||
|
if plugin_search_results == None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
print(f"Searching for {plugin_name}...")
|
||||||
|
print(f"Found plugins:")
|
||||||
|
# create table with rich
|
||||||
|
rich_table = Table(box=None)
|
||||||
|
rich_table.add_column("No.", justify="right", style="cyan", no_wrap=True)
|
||||||
|
rich_table.add_column("Name", style="bright_magenta")
|
||||||
|
rich_table.add_column("Downloads", justify="right", style="bright_green")
|
||||||
|
rich_table.add_column("Description", justify="left", style="white")
|
||||||
|
# start counting at 1 for all my non-programming friends :)
|
||||||
|
i = 1
|
||||||
|
for found_plugin in plugin_search_results:
|
||||||
|
plugin_name = handle_regex_package_name(found_plugin["name"])
|
||||||
|
plugin_downloads = found_plugin["downloads"]
|
||||||
|
plugin_description = found_plugin["tag"]
|
||||||
|
rich_table.add_row(str(i), plugin_name, str(plugin_downloads), plugin_description)
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
# print table from rich
|
||||||
|
rich_console = Console()
|
||||||
|
rich_console.print(rich_table)
|
||||||
|
|
||||||
|
try:
|
||||||
|
plugin_selected = input("Select your wanted resource (No.)(0 to exit): ")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
return None
|
||||||
|
if plugin_selected == "0":
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
plugin_selected = int(plugin_selected) - 1
|
||||||
|
plugin_selected_id = plugin_search_results[plugin_selected]["id"]
|
||||||
|
except ValueError:
|
||||||
|
rich_print_error("Error: Input wasn't a number! Please try again!")
|
||||||
|
return None
|
||||||
|
except IndexError:
|
||||||
|
rich_print_error("Error: Number was out of range! Please try again!")
|
||||||
|
return None
|
||||||
|
|
||||||
|
get_specific_plugin(plugin_selected_id)
|
||||||
|
@ -20,7 +20,7 @@ def api_do_request(url) -> list:
|
|||||||
try:
|
try:
|
||||||
response = requests.get(url, headers=webrequest_header)
|
response = requests.get(url, headers=webrequest_header)
|
||||||
except:
|
except:
|
||||||
print("Couldn't create webrequest")
|
rich_print_error("Error: Couldn't create webrequest")
|
||||||
# return None to make functions quit
|
# return None to make functions quit
|
||||||
return None
|
return None
|
||||||
api_json_data = response.json()
|
api_json_data = response.json()
|
||||||
@ -39,7 +39,7 @@ def api_test_spiget() -> None:
|
|||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
rich_print_error("Error: Problems with the API detected. Plese try it again later!")
|
rich_print_error("Error: Problems with the API detected. Plese try it again later!")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
return
|
return None
|
||||||
|
|
||||||
|
|
||||||
def create_temp_plugin_folder() -> Path:
|
def create_temp_plugin_folder() -> Path:
|
||||||
@ -107,3 +107,4 @@ def check_requirements() -> None:
|
|||||||
print("Check sftp folder")
|
print("Check sftp folder")
|
||||||
case "ftp":
|
case "ftp":
|
||||||
print("check ftp folder")
|
print("check ftp folder")
|
||||||
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user