mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
🎨 Save patch resource version
This commit is contained in:
committed by
Nikhil Badyal
parent
86c7ea0e12
commit
0d84842ee4
+11
-6
@@ -36,7 +36,7 @@ class APP(object):
|
|||||||
self.patches_json_dl = config.env.str(f"{app_name}_PATCHES_JSON_DL".upper(), self.patches_dl)
|
self.patches_json_dl = config.env.str(f"{app_name}_PATCHES_JSON_DL".upper(), self.patches_dl)
|
||||||
self.exclude_request: list[str] = config.env.list(f"{app_name}_EXCLUDE_PATCH".upper(), [])
|
self.exclude_request: list[str] = config.env.list(f"{app_name}_EXCLUDE_PATCH".upper(), [])
|
||||||
self.include_request: list[str] = config.env.list(f"{app_name}_INCLUDE_PATCH".upper(), [])
|
self.include_request: list[str] = config.env.list(f"{app_name}_INCLUDE_PATCH".upper(), [])
|
||||||
self.resource: dict[str, str] = {}
|
self.resource: dict[str, dict[str, str]] = {}
|
||||||
self.no_of_patches: int = 0
|
self.no_of_patches: int = 0
|
||||||
self.keystore_name = config.env.str(f"{app_name}_KEYSTORE_FILE_NAME".upper(), config.global_keystore_name)
|
self.keystore_name = config.env.str(f"{app_name}_KEYSTORE_FILE_NAME".upper(), config.global_keystore_name)
|
||||||
self.archs_to_build = config.env.list(f"{app_name}_ARCHS_TO_BUILD".upper(), config.global_archs_to_build)
|
self.archs_to_build = config.env.list(f"{app_name}_ARCHS_TO_BUILD".upper(), config.global_archs_to_build)
|
||||||
@@ -91,7 +91,7 @@ class APP(object):
|
|||||||
return ", ".join([f"{key}: {value}" for key, value in attrs.items()])
|
return ", ".join([f"{key}: {value}" for key, value in attrs.items()])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def download(url: str, config: RevancedConfig, assets_filter: str, file_name: str = "") -> str:
|
def download(url: str, config: RevancedConfig, assets_filter: str, file_name: str = "") -> tuple[str, str]:
|
||||||
"""The `download` function downloads a file from a given URL & filters the assets based on a given filter.
|
"""The `download` function downloads a file from a given URL & filters the assets based on a given filter.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@@ -118,17 +118,18 @@ class APP(object):
|
|||||||
from src.downloader.download import Downloader
|
from src.downloader.download import Downloader
|
||||||
|
|
||||||
url = url.strip()
|
url = url.strip()
|
||||||
|
tag = "latest"
|
||||||
if url.startswith("https://github"):
|
if url.startswith("https://github"):
|
||||||
from src.downloader.github import Github
|
from src.downloader.github import Github
|
||||||
|
|
||||||
url = Github.patch_resource(url, assets_filter, config)
|
tag, url = Github.patch_resource(url, assets_filter, config)
|
||||||
elif url.startswith("local://"):
|
elif url.startswith("local://"):
|
||||||
return url.split("/")[-1]
|
return tag, url.split("/")[-1]
|
||||||
if not file_name:
|
if not file_name:
|
||||||
extension = pathlib.Path(url).suffix
|
extension = pathlib.Path(url).suffix
|
||||||
file_name = APP.generate_filename(url) + extension
|
file_name = APP.generate_filename(url) + extension
|
||||||
Downloader(config).direct_download(url, file_name)
|
Downloader(config).direct_download(url, file_name)
|
||||||
return file_name
|
return tag, file_name
|
||||||
|
|
||||||
def download_patch_resources(self: Self, config: RevancedConfig) -> None:
|
def download_patch_resources(self: Self, config: RevancedConfig) -> None:
|
||||||
"""The function `download_patch_resources` downloads various resources req. for patching.
|
"""The function `download_patch_resources` downloads various resources req. for patching.
|
||||||
@@ -158,7 +159,11 @@ class APP(object):
|
|||||||
# Retrieve results from completed tasks
|
# Retrieve results from completed tasks
|
||||||
for resource_name, future in futures.items():
|
for resource_name, future in futures.items():
|
||||||
try:
|
try:
|
||||||
self.resource[resource_name] = future.result()
|
tag, file_name = future.result()
|
||||||
|
self.resource[resource_name] = {
|
||||||
|
"file_name": file_name,
|
||||||
|
"version": tag,
|
||||||
|
}
|
||||||
except BuilderError as e:
|
except BuilderError as e:
|
||||||
msg = "Failed to download resource."
|
msg = "Failed to download resource."
|
||||||
raise PatchingFailedError(msg) from e
|
raise PatchingFailedError(msg) from e
|
||||||
|
|||||||
@@ -57,13 +57,10 @@ class Github(Downloader):
|
|||||||
tag_position = 3
|
tag_position = 3
|
||||||
if len(path_segments) > tag_position and path_segments[3] == "latest-prerelease":
|
if len(path_segments) > tag_position and path_segments[3] == "latest-prerelease":
|
||||||
logger.info(f"Including pre-releases/beta for {github_repo_name} selection.")
|
logger.info(f"Including pre-releases/beta for {github_repo_name} selection.")
|
||||||
latest_tag = str(latest(f"{github_repo_owner}/{github_repo_name}", output_format="tag", pre_ok=True))
|
pre_ok = True
|
||||||
release_tag = f"tags/{latest_tag}"
|
|
||||||
else:
|
else:
|
||||||
release_tag = next(
|
pre_ok = False
|
||||||
(f"tags/{path_segments[i + 1]}" for i, segment in enumerate(path_segments) if segment == "tag"),
|
release_tag = str(latest(f"{github_repo_owner}/{github_repo_name}", output_format="tag", pre_ok=pre_ok))
|
||||||
"latest",
|
|
||||||
)
|
|
||||||
return github_repo_owner, github_repo_name, release_tag
|
return github_repo_owner, github_repo_name, release_tag
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -99,7 +96,8 @@ class Github(Downloader):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def patch_resource(repo_url: str, assets_filter: str, config: RevancedConfig) -> str:
|
def patch_resource(repo_url: str, assets_filter: str, config: RevancedConfig) -> tuple[str, str]:
|
||||||
"""Fetch patch resource from repo url."""
|
"""Fetch patch resource from repo url."""
|
||||||
repo_owner, repo_name, tag = Github._extract_repo_owner_and_tag(repo_url)
|
repo_owner, repo_name, latest_tag = Github._extract_repo_owner_and_tag(repo_url)
|
||||||
return Github._get_release_assets(repo_owner, repo_name, tag, assets_filter, config)
|
tag = f"tags/{latest_tag}"
|
||||||
|
return latest_tag, Github._get_release_assets(repo_owner, repo_name, tag, assets_filter, config)
|
||||||
|
|||||||
+4
-4
@@ -164,7 +164,7 @@ class Parser(object):
|
|||||||
The `app` parameter is an instance of the `APP` class. It represents an application that needs
|
The `app` parameter is an instance of the `APP` class. It represents an application that needs
|
||||||
to be patched.
|
to be patched.
|
||||||
"""
|
"""
|
||||||
is_new, version = self.is_new_cli(self.config.temp_folder.joinpath(app.resource["cli"]))
|
is_new, version = self.is_new_cli(self.config.temp_folder.joinpath(app.resource["cli"]["file_name"]))
|
||||||
if is_new:
|
if is_new:
|
||||||
apk_arg = self.NEW_APK_ARG
|
apk_arg = self.NEW_APK_ARG
|
||||||
exp = "--force"
|
exp = "--force"
|
||||||
@@ -173,13 +173,13 @@ class Parser(object):
|
|||||||
exp = "--experimental"
|
exp = "--experimental"
|
||||||
args = [
|
args = [
|
||||||
self.CLI_JAR,
|
self.CLI_JAR,
|
||||||
app.resource["cli"],
|
app.resource["cli"]["file_name"],
|
||||||
apk_arg,
|
apk_arg,
|
||||||
app.download_file_name,
|
app.download_file_name,
|
||||||
self.PATCHES_ARG,
|
self.PATCHES_ARG,
|
||||||
app.resource["patches"],
|
app.resource["patches"]["file_name"],
|
||||||
self.INTEGRATIONS_ARG,
|
self.INTEGRATIONS_ARG,
|
||||||
app.resource["integrations"],
|
app.resource["integrations"]["file_name"],
|
||||||
self.OUTPUT_ARG,
|
self.OUTPUT_ARG,
|
||||||
app.get_output_file_name(),
|
app.get_output_file_name(),
|
||||||
self.KEYSTORE_ARG,
|
self.KEYSTORE_ARG,
|
||||||
|
|||||||
+2
-1
@@ -116,7 +116,8 @@ class Patches(object):
|
|||||||
"""
|
"""
|
||||||
self.patches_dict[app.app_name] = []
|
self.patches_dict[app.app_name] = []
|
||||||
patch_loader = PatchLoader()
|
patch_loader = PatchLoader()
|
||||||
patches = patch_loader.load_patches(f'{config.temp_folder}/{app.resource["patches_json"]}')
|
patches_file = app.resource["patches_json"]["file_name"]
|
||||||
|
patches = patch_loader.load_patches(f"{config.temp_folder}/{patches_file}")
|
||||||
|
|
||||||
for patch in patches:
|
for patch in patches:
|
||||||
if not patch["compatiblePackages"]:
|
if not patch["compatiblePackages"]:
|
||||||
|
|||||||
Reference in New Issue
Block a user