mirror of
https://github.com/sotam0316/docker-py-revanced.git
synced 2026-04-25 03:48:37 +09:00
📝 Updated docs [skip ci]
This commit is contained in:
+64
-5
@@ -43,11 +43,28 @@ class APP(object):
|
||||
self.download_patch_resources(config)
|
||||
|
||||
def get_output_file_name(self) -> str:
|
||||
"""Get output file appended with version."""
|
||||
"""The function returns a string representing the output file name for
|
||||
an APK file appended with version.
|
||||
|
||||
Returns
|
||||
-------
|
||||
a string that represents the output file name for an APK file.
|
||||
"""
|
||||
return f"Re-{self.app_name}-{slugify(self.app_version)}-output.apk"
|
||||
|
||||
def set_recommended_version(self, version: str, exp: bool = False) -> None:
|
||||
"""Update if cooking non-recommended."""
|
||||
"""The function sets the recommended version and experiment flag for an
|
||||
app.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
version : str
|
||||
The version parameter is a string that represents the recommended version of the app.
|
||||
exp : bool, optional
|
||||
The "exp" parameter is a boolean flag that indicates whether the specified version is for an
|
||||
experimental or regular release. If "exp" is set to True, it means the version is for an
|
||||
experimental release. If "exp" is set to False or not provided, it means the version is for
|
||||
"""
|
||||
self.app_version = version
|
||||
self.experiment = exp
|
||||
|
||||
@@ -59,7 +76,30 @@ class APP(object):
|
||||
def download(
|
||||
url: str, config: RevancedConfig, assets_filter: str, file_name: str = ""
|
||||
) -> str:
|
||||
"""Downloader."""
|
||||
"""The `download` function downloads a file from a given URL using a
|
||||
specified configuration and filters the assets based on a given filter.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
url : str
|
||||
The `url` parameter is a string that represents the URL of the resource you want to download.
|
||||
It can be a URL from GitHub or a local file URL.
|
||||
config : RevancedConfig
|
||||
The `config` parameter is an instance of the `RevancedConfig` class. It is used to provide
|
||||
configuration settings for the download process.
|
||||
assets_filter : str
|
||||
The `assets_filter` parameter is a string that is used to filter the assets to be downloaded
|
||||
from a GitHub repository. It is used when the `url` parameter starts with "https://github". The
|
||||
`assets_filter` string is matched against the names of the assets in the repository, and only
|
||||
file_name : str
|
||||
The `file_name` parameter is a string that represents the name of the file that will be
|
||||
downloaded. If no value is provided for `file_name`, the function will generate a filename based
|
||||
on the URL of the file being downloaded.
|
||||
|
||||
Returns
|
||||
-------
|
||||
a string, which is the file name of the downloaded file.
|
||||
"""
|
||||
from src.downloader.download import Downloader
|
||||
|
||||
url = url.strip()
|
||||
@@ -76,7 +116,15 @@ class APP(object):
|
||||
return file_name
|
||||
|
||||
def download_patch_resources(self, config: RevancedConfig) -> None:
|
||||
"""Download resource for patching."""
|
||||
"""The function `download_patch_resources` downloads various resources
|
||||
for patching in parallel using a ThreadPoolExecutor.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
config : RevancedConfig
|
||||
The `config` parameter is an instance of the `RevancedConfig` class. It is used to provide
|
||||
configuration settings for the resource download tasks.
|
||||
"""
|
||||
logger.info("Downloading resources for patching.")
|
||||
# Create a list of resource download tasks
|
||||
download_tasks = [
|
||||
@@ -105,6 +153,17 @@ class APP(object):
|
||||
|
||||
@staticmethod
|
||||
def generate_filename(url: str) -> str:
|
||||
"""Get file name from url."""
|
||||
"""The function `generate_filename` takes a URL as input and returns a
|
||||
hashed version of the URL as the filename.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
url : str
|
||||
The `url` parameter is a string that represents a URL.
|
||||
|
||||
Returns
|
||||
-------
|
||||
the encoded URL as a string.
|
||||
"""
|
||||
encoded_url: str = hashlib.sha256(url.encode()).hexdigest()
|
||||
return encoded_url
|
||||
|
||||
+50
-13
@@ -30,33 +30,61 @@ class Parser(object):
|
||||
self.config = config
|
||||
|
||||
def include(self, name: str) -> None:
|
||||
"""Include a given patch.
|
||||
"""The function `include` adds a given patch to a list of patches.
|
||||
|
||||
:param name: Name of the patch
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
The `name` parameter is a string that represents the name of the patch to be included.
|
||||
"""
|
||||
self._PATCHES.extend(["-i", name])
|
||||
|
||||
def exclude(self, name: str) -> None:
|
||||
"""Exclude a given patch.
|
||||
"""The `exclude` function adds a given patch to the list of excluded
|
||||
patches.
|
||||
|
||||
:param name: Name of the patch to exclude
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
The `name` parameter is a string that represents the name of the patch to be excluded.
|
||||
"""
|
||||
self._PATCHES.extend(["-e", name])
|
||||
self._EXCLUDED.append(name)
|
||||
|
||||
def get_excluded_patches(self) -> List[str]:
|
||||
"""Getter to get all excluded patches :return: List of excluded
|
||||
patches."""
|
||||
"""The function `get_excluded_patches` is a getter method that returns
|
||||
a list of excluded patches.
|
||||
|
||||
Returns
|
||||
-------
|
||||
The method is returning a list of excluded patches.
|
||||
"""
|
||||
return self._EXCLUDED
|
||||
|
||||
def get_all_patches(self) -> List[str]:
|
||||
"""Getter to get all excluded patches :return: List of excluded
|
||||
patches."""
|
||||
"""The function "get_all_patches" is a getter method that returns a
|
||||
list of all patches.
|
||||
|
||||
Returns
|
||||
-------
|
||||
The method is returning a list of all patches.
|
||||
"""
|
||||
return self._PATCHES
|
||||
|
||||
def invert_patch(self, name: str) -> bool:
|
||||
"""Getter to get all excluded patches :return: List of excluded
|
||||
patches."""
|
||||
"""The function `invert_patch` takes a name as input, it toggles the
|
||||
status of the patch and returns True, otherwise it returns False.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
The `name` parameter is a string that represents the name of a patch.
|
||||
|
||||
Returns
|
||||
-------
|
||||
a boolean value. It returns True if the patch name is found in the list of patches and
|
||||
successfully inverted, and False if the patch name is not found in the list.
|
||||
"""
|
||||
try:
|
||||
name = name.lower().replace(" ", "-")
|
||||
patch_index = self._PATCHES.index(name)
|
||||
@@ -71,7 +99,11 @@ class Parser(object):
|
||||
return False
|
||||
|
||||
def exclude_all_patches(self) -> None:
|
||||
"""Exclude all patches to Speed up CI."""
|
||||
"""The function `exclude_all_patches` replaces all occurrences of "-i"
|
||||
with "-e" in the list `self._PATCHES`.
|
||||
|
||||
Hence exclude all patches
|
||||
"""
|
||||
for idx, item in enumerate(self._PATCHES):
|
||||
if item == "-i":
|
||||
self._PATCHES[idx] = "-e"
|
||||
@@ -81,9 +113,14 @@ class Parser(object):
|
||||
self,
|
||||
app: APP,
|
||||
) -> None:
|
||||
"""Revanced APP Patcher.
|
||||
"""The function `patch_app` is used to patch an app using the Revanced
|
||||
CLI tool.
|
||||
|
||||
:param app: Name of the app
|
||||
Parameters
|
||||
----------
|
||||
app : APP
|
||||
The `app` parameter is an instance of the `APP` class. It represents an application that needs
|
||||
to be patched.
|
||||
"""
|
||||
args = [
|
||||
self.CLI_JAR,
|
||||
|
||||
+84
-15
@@ -62,7 +62,19 @@ class Patches(object):
|
||||
|
||||
@staticmethod
|
||||
def get_package_name(app: str) -> str:
|
||||
"""Get Package name from app name."""
|
||||
"""The function `get_package_name` takes an app name as input and
|
||||
returns the corresponding package name, or raises an exception if the
|
||||
app is not supported.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
app : str
|
||||
The `app` parameter is a string that represents the name of an app.
|
||||
|
||||
Returns
|
||||
-------
|
||||
a string, which is the package name corresponding to the given app name.
|
||||
"""
|
||||
for package, app_tuple in Patches.revanced_app_ids.items():
|
||||
if app_tuple[0] == app:
|
||||
return package
|
||||
@@ -70,11 +82,27 @@ class Patches(object):
|
||||
|
||||
@staticmethod
|
||||
def support_app() -> Dict[str, str]:
|
||||
"""Return supported apps."""
|
||||
"""The function `support_app()` returns a dictionary of supported app
|
||||
IDs.
|
||||
|
||||
Returns
|
||||
-------
|
||||
a dictionary of supported apps.
|
||||
"""
|
||||
return Patches._revanced_app_ids
|
||||
|
||||
def fetch_patches(self, config: RevancedConfig, app: APP) -> None:
|
||||
"""Function to fetch all patches."""
|
||||
"""The function fetches patches from a JSON file and organizes them
|
||||
based on compatibility with different applications.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
config : RevancedConfig
|
||||
The `config` parameter is of type `RevancedConfig` and represents the configuration for the
|
||||
application.
|
||||
app : APP
|
||||
The `app` parameter is of type `APP`. It represents an instance of the `APP` class.
|
||||
"""
|
||||
patch_loader = PatchLoader()
|
||||
patches = patch_loader.load_patches(
|
||||
f'{config.temp_folder}/{app.resource["patches_json"]}'
|
||||
@@ -105,10 +133,20 @@ class Patches(object):
|
||||
self.fetch_patches(config, app)
|
||||
|
||||
def get(self, app: str) -> Tuple[List[Dict[str, str]], str]:
|
||||
"""Get all patches for the given app.
|
||||
"""The function `get` retrieves all patches for a given application and
|
||||
returns them along with the latest version.
|
||||
|
||||
:param app: Name of the application
|
||||
:return: Patches
|
||||
Parameters
|
||||
----------
|
||||
app : str
|
||||
The `app` parameter is a string that represents the name of the application for which you want
|
||||
to retrieve patches.
|
||||
|
||||
Returns
|
||||
-------
|
||||
a tuple containing two elements. The first element is a list of dictionaries representing
|
||||
patches for the given app. The second element is a string representing the version of the
|
||||
patches.
|
||||
"""
|
||||
app_names = {value[0]: value[1] for value in self.revanced_app_ids.values()}
|
||||
|
||||
@@ -124,11 +162,20 @@ class Patches(object):
|
||||
def include_exclude_patch(
|
||||
self, app: APP, parser: Any, patches: List[Dict[str, str]]
|
||||
) -> None:
|
||||
"""Include and exclude patches for a given app.
|
||||
"""The function `include_exclude_patch` includes and excludes patches
|
||||
for a given app based on certain conditions.
|
||||
|
||||
:param app: Name of the app
|
||||
:param parser: Parser Obj
|
||||
:param patches: All the patches of a given app
|
||||
Parameters
|
||||
----------
|
||||
app : APP
|
||||
The "app" parameter is the name of the app for which the patches are being included or
|
||||
excluded.
|
||||
parser : Any
|
||||
The `parser` parameter is an object of type `Any`, which means it can be any type of object. It
|
||||
is used to perform parsing operations.
|
||||
patches : List[Dict[str, str]]
|
||||
A list of dictionaries, where each dictionary represents a patch and contains the following
|
||||
keys:
|
||||
"""
|
||||
for patch in patches:
|
||||
normalized_patch = patch["name"].lower().replace(" ", "-")
|
||||
@@ -144,11 +191,21 @@ class Patches(object):
|
||||
logger.info(app)
|
||||
|
||||
def get_app_configs(self, app: "APP") -> List[Dict[str, str]]:
|
||||
"""Get Configurations for a given app.
|
||||
"""The function `get_app_configs` retrieves configurations for a given
|
||||
app, including patches, version information, and whether it is
|
||||
experimental.
|
||||
|
||||
:param app: Name of the application
|
||||
:return: All Patches , Its version and whether it is
|
||||
experimental
|
||||
Parameters
|
||||
----------
|
||||
app : "APP"
|
||||
The "app" parameter is the name of the application for which you want to get the
|
||||
configurations.
|
||||
|
||||
Returns
|
||||
-------
|
||||
the total_patches, which is a list of dictionaries containing information about the patches for
|
||||
the given app. Each dictionary in the list contains the keys "Patches", "Version", and
|
||||
"Experimental".
|
||||
"""
|
||||
experiment = False
|
||||
total_patches, recommended_version = self.get(app=app.app_name)
|
||||
@@ -170,7 +227,19 @@ class PatchLoader:
|
||||
|
||||
@staticmethod
|
||||
def load_patches(file_name: str) -> Any:
|
||||
"""Load patches from a file."""
|
||||
"""The function `load_patches` loads patches from a file and returns
|
||||
them.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
file_name : str
|
||||
The `file_name` parameter is a string that represents the name or path of the file from which
|
||||
the patches will be loaded.
|
||||
|
||||
Returns
|
||||
-------
|
||||
the patches loaded from the file.
|
||||
"""
|
||||
try:
|
||||
with open(file_name) as f:
|
||||
patches = json.load(f)
|
||||
|
||||
+105
-13
@@ -26,14 +26,44 @@ bs4_parser = "html.parser"
|
||||
|
||||
|
||||
def update_changelog(name: str, response: Dict[str, str]) -> None:
|
||||
"""Updated Changelog."""
|
||||
"""The function `update_changelog` updates the changelog file with the
|
||||
provided name and response.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
A string representing the name of the change or update.
|
||||
response : Dict[str, str]
|
||||
The `response` parameter is a dictionary that contains information about the changes made. The keys
|
||||
in the dictionary represent the type of change (e.g., "bug fix", "feature", "documentation"), and
|
||||
the values represent the specific changes made for each type.
|
||||
"""
|
||||
parent_repo = get_parent_repo()
|
||||
change_log = format_changelog(name, response, parent_repo)
|
||||
write_to_file(change_log)
|
||||
|
||||
|
||||
def format_changelog(name: str, response: Dict[str, str], parent_repo: str) -> str:
|
||||
"""Format changelog."""
|
||||
"""The `format_changelog` function takes in a name, a response dictionary,
|
||||
and a parent repository, and returns a formatted changelog string.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
The `name` parameter is a string that represents the name of the changelog. It is used to create a
|
||||
collapsible section in the formatted changelog.
|
||||
response : Dict[str, str]
|
||||
The `response` parameter is a dictionary that contains information about a release. It has the
|
||||
following keys:
|
||||
parent_repo : str
|
||||
The `parent_repo` parameter is a string that represents the URL or name of the parent repository.
|
||||
It is used to generate a footer in the formatted changelog, indicating that the changelogs were
|
||||
generated by a specific tool or script.
|
||||
|
||||
Returns
|
||||
-------
|
||||
a formatted changelog as a string.
|
||||
"""
|
||||
collapse_start = f"\n<details> <summary>👀 {name} </summary>\n\n"
|
||||
release_version = (
|
||||
f"**Release Version** - [{response['tag_name']}]({response['html_url']})<br>"
|
||||
@@ -57,25 +87,59 @@ def format_changelog(name: str, response: Dict[str, str], parent_repo: str) -> s
|
||||
|
||||
|
||||
def write_to_file(change_log: str) -> None:
|
||||
"""Write changelog to file."""
|
||||
"""The function `write_to_file` writes a given changelog string to a file
|
||||
named "changelog.md".
|
||||
|
||||
Parameters
|
||||
----------
|
||||
change_log : str
|
||||
A string representing the changelog that you want to write to the file.
|
||||
"""
|
||||
with open("changelog.md", "w", encoding="utf_8") as file1:
|
||||
file1.write(change_log)
|
||||
|
||||
|
||||
def get_parent_repo() -> str:
|
||||
"""Get parent repository URL from configuration file."""
|
||||
"""The function `get_parent_repo()` returns the URL of the parent
|
||||
repository.
|
||||
|
||||
Returns
|
||||
-------
|
||||
the URL of the parent repository, which is "https://github.com/nikhilbadyal/docker-py-revanced".
|
||||
"""
|
||||
return "https://github.com/nikhilbadyal/docker-py-revanced"
|
||||
|
||||
|
||||
def handle_request_response(response: Response) -> None:
|
||||
"""Handle Get Request Response."""
|
||||
"""The function handles the response of a GET request and raises an
|
||||
exception if the response code is not 200.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
response : Response
|
||||
The parameter `response` is of type `Response`, which is likely referring to a response object from
|
||||
an HTTP request. This object typically contains information about the response received from the
|
||||
server, such as the status code, headers, and response body.
|
||||
"""
|
||||
response_code = response.status_code
|
||||
if response_code != 200:
|
||||
raise DownloadFailure(f"Unable to downloaded assets. Reason - {response.text}")
|
||||
|
||||
|
||||
def slugify(string: str) -> str:
|
||||
"""Converts a string to a slug format."""
|
||||
"""The `slugify` function converts a string to a slug format by converting
|
||||
it to lowercase, removing special characters, replacing spaces with dashes,
|
||||
removing consecutive dashes, and removing leading and trailing dashes.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
string : str
|
||||
The `string` parameter is a string that you want to convert to a slug format.
|
||||
|
||||
Returns
|
||||
-------
|
||||
The function `slugify` returns a modified version of the input string in slug format.
|
||||
"""
|
||||
# Convert to lowercase
|
||||
modified_string = string.lower()
|
||||
|
||||
@@ -95,7 +159,21 @@ def slugify(string: str) -> str:
|
||||
|
||||
|
||||
def check_java(dry_run: bool) -> None:
|
||||
"""Check if Java>=17 is installed."""
|
||||
"""The function `check_java` checks if Java version 17 or higher is
|
||||
installed and logs an error message if it is not.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
dry_run : bool
|
||||
The `dry_run` parameter is a boolean flag that determines whether the function should actually
|
||||
check if Java is installed or just simulate the check. If `dry_run` is `True`, the function will
|
||||
return without performing the check. If `dry_run` is `False`, the function will execute the
|
||||
|
||||
Returns
|
||||
-------
|
||||
The function `check_java` does not return any value. It has a return type annotation of `None`,
|
||||
indicating that it does not return anything.
|
||||
"""
|
||||
try:
|
||||
if dry_run:
|
||||
return
|
||||
@@ -114,7 +192,15 @@ def check_java(dry_run: bool) -> None:
|
||||
|
||||
|
||||
def extra_downloads(config: RevancedConfig) -> None:
|
||||
"""Download extra files."""
|
||||
"""The function `extra_downloads` downloads extra files specified in the
|
||||
`config` object using the `APP.download` method.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
config : RevancedConfig
|
||||
The `config` parameter is an instance of the `RevancedConfig` class. It is used to provide
|
||||
configuration settings for the download process.
|
||||
"""
|
||||
from src.app import APP
|
||||
|
||||
try:
|
||||
@@ -135,13 +221,19 @@ def extra_downloads(config: RevancedConfig) -> None:
|
||||
|
||||
|
||||
def apkmirror_status_check(package_name: str) -> Any:
|
||||
"""Check if app exists on APKMirror.
|
||||
"""The `apkmirror_status_check` function checks if an app exists on
|
||||
APKMirror by making a POST request to the APKMirror API with the package
|
||||
name as a parameter.
|
||||
|
||||
Args:
|
||||
package_name (str): The name of the package to check.
|
||||
Parameters
|
||||
----------
|
||||
package_name : str
|
||||
The `package_name` parameter is a string that represents the name of the app package to check on
|
||||
APKMirror.
|
||||
|
||||
Returns:
|
||||
dict: The response from APKMirror API as a JSON object.
|
||||
Returns
|
||||
-------
|
||||
the response from the APKMirror API as a JSON object.
|
||||
"""
|
||||
api_url = f"{apk_mirror_base_url}/wp-json/apkm/v1/app_exists/"
|
||||
body = {"pnames": [package_name]}
|
||||
|
||||
Reference in New Issue
Block a user