mirror of
https://github.com/bombsquad-community/plugin-manager.git
synced 2025-10-08 14:54:36 +00:00
[ci] auto-format
This commit is contained in:
parent
e7476a6ae2
commit
86e3597513
1 changed files with 10 additions and 11 deletions
|
|
@ -3,6 +3,7 @@ import json
|
||||||
import sys
|
import sys
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
|
|
||||||
def get_latest_version(plugin_name, category):
|
def get_latest_version(plugin_name, category):
|
||||||
base_url = "https://github.com/bombsquad-community/plugin-manager/raw/main/"
|
base_url = "https://github.com/bombsquad-community/plugin-manager/raw/main/"
|
||||||
endpoints = {
|
endpoints = {
|
||||||
|
|
@ -11,37 +12,36 @@ def get_latest_version(plugin_name, category):
|
||||||
"maps": "plugins/maps.json",
|
"maps": "plugins/maps.json",
|
||||||
"plugman": "index.json"
|
"plugman": "index.json"
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with urlopen(f"{base_url}{endpoints[category]}") as response:
|
with urlopen(f"{base_url}{endpoints[category]}") as response:
|
||||||
data = json.loads(response.read().decode('utf-8'))
|
data = json.loads(response.read().decode('utf-8'))
|
||||||
|
|
||||||
# Handle plugman separately
|
# Handle plugman separately
|
||||||
if category == "plugman":
|
if category == "plugman":
|
||||||
version = next(iter(data.get("versions")))
|
version = next(iter(data.get("versions")))
|
||||||
return version
|
return version
|
||||||
|
|
||||||
# For plugins
|
# For plugins
|
||||||
plugin = data.get("plugins", {}).get(plugin_name)
|
plugin = data.get("plugins", {}).get(plugin_name)
|
||||||
if not plugin:
|
if not plugin:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Get latest version from versions dict
|
# Get latest version from versions dict
|
||||||
if "versions" in plugin and isinstance(plugin["versions"], dict):
|
if "versions" in plugin and isinstance(plugin["versions"], dict):
|
||||||
latest_version = next(iter(plugin["versions"])) # Gets first key
|
latest_version = next(iter(plugin["versions"])) # Gets first key
|
||||||
return latest_version
|
return latest_version
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def update_plugman_json(version):
|
def update_plugman_json(version):
|
||||||
with open("index.json", "r+") as file:
|
with open("index.json", "r+") as file:
|
||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
plugman_version = int(get_latest_version("plugin_manager", "plugman").replace(".", ""))
|
plugman_version = int(get_latest_version("plugin_manager", "plugman").replace(".", ""))
|
||||||
current_version = int(version["version"].replace(".", ""))
|
current_version = int(version["version"].replace(".", ""))
|
||||||
|
|
||||||
if current_version > plugman_version:
|
if current_version > plugman_version:
|
||||||
with open("index.json", "r+") as file:
|
with open("index.json", "r+") as file:
|
||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
|
|
@ -49,7 +49,6 @@ def update_plugman_json(version):
|
||||||
data["versions"] = dict(
|
data["versions"] = dict(
|
||||||
sorted(data["versions"].items(), reverse=True)
|
sorted(data["versions"].items(), reverse=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def update_plugin_json(plugin_info, category):
|
def update_plugin_json(plugin_info, category):
|
||||||
|
|
@ -62,7 +61,7 @@ def update_plugin_json(plugin_info, category):
|
||||||
plugin = data["plugins"][name]
|
plugin = data["plugins"][name]
|
||||||
plugman_version = int(get_latest_version(name, category).replace(".", ""))
|
plugman_version = int(get_latest_version(name, category).replace(".", ""))
|
||||||
current_version = int(plugin_info["version"].replace(".", ""))
|
current_version = int(plugin_info["version"].replace(".", ""))
|
||||||
# Ensure the version is always greater from the already released version
|
# Ensure the version is always greater from the already released version
|
||||||
if current_version > plugman_version:
|
if current_version > plugman_version:
|
||||||
plugin["versions"][plugin_info["version"]] = None
|
plugin["versions"][plugin_info["version"]] = None
|
||||||
# Ensure latest version appears first
|
# Ensure latest version appears first
|
||||||
|
|
@ -94,7 +93,7 @@ def extract_plugman(plugins):
|
||||||
try:
|
try:
|
||||||
# Split the path and get the part after 'plugins/'
|
# Split the path and get the part after 'plugins/'
|
||||||
parts = plugin.split("plugins/")[1].split("/")
|
parts = plugin.split("plugins/")[1].split("/")
|
||||||
category = parts[0] # First part after plugins/
|
category = parts[0] # First part after plugins/
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if "plugin_manager" in plugin:
|
if "plugin_manager" in plugin:
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue