From 581cb5ce3f2d99e6015cd0725e7239a308391ee5 Mon Sep 17 00:00:00 2001 From: daijro Date: Tue, 17 Sep 2024 12:24:18 -0500 Subject: [PATCH] pythonlib: Fixes & cleanup - Fix chmod not working - Add more instructions to README - Cleanup comments --- pythonlib/README.md | 12 +++++++++++- pythonlib/camoufox/__main__.py | 2 +- pythonlib/camoufox/pkgman.py | 15 +++++++-------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/pythonlib/README.md b/pythonlib/README.md index 9956d8a..a12d9d6 100644 --- a/pythonlib/README.md +++ b/pythonlib/README.md @@ -7,12 +7,22 @@ ## Installation +First, install the `camoufox` package: + ```bash -git clone https://github.com/camoufox +git clone --depth 1 https://github.com/camoufox cd camoufox/pythonlib pip install . ``` +Then, download the Camoufox browser: + +```bash +camoufox fetch +``` + +To uninstall, run `camoufox remove`. +
## Usage diff --git a/pythonlib/camoufox/__main__.py b/pythonlib/camoufox/__main__.py index 689a4fa..beedcce 100644 --- a/pythonlib/camoufox/__main__.py +++ b/pythonlib/camoufox/__main__.py @@ -64,7 +64,7 @@ def cli() -> None: @cli.command(name='fetch') -def fetch(): +def fetch() -> None: """ Fetch the latest version of Camoufox """ diff --git a/pythonlib/camoufox/pkgman.py b/pythonlib/camoufox/pkgman.py index b79e2ec..c709348 100644 --- a/pythonlib/camoufox/pkgman.py +++ b/pythonlib/camoufox/pkgman.py @@ -1,6 +1,7 @@ import os import platform import re +import shlex import shutil import sys import tempfile @@ -69,10 +70,9 @@ class CamoufoxFetcher: Get the current platform and architecture information. Returns: - + str: The architecture of the current platform Raises: - UnsupportedOS: If the current OS is not supported UnsupportedArchitecture: If the current architecture is not supported """ @@ -125,7 +125,7 @@ class CamoufoxFetcher: url (str): The URL to download the file from Returns: - BytesIO: The downloaded file content as a BytesIO object + DownloadBuffer: The downloaded file content as a BytesIO object """ rprint(f'Downloading package: {url}') return webdl(url, buffer=file) @@ -135,7 +135,7 @@ class CamoufoxFetcher: Extract the contents of a zip file to the installation directory. Args: - zip_file (BytesIO): The zip file content as a BytesIO object + zip_file (DownloadBuffer): The zip file content as a BytesIO object """ rprint(f'Extracting Camoufox: {INSTALL_DIR}') unzip(zip_file, str(INSTALL_DIR)) @@ -177,11 +177,10 @@ class CamoufoxFetcher: self.extract_zip(temp_file) self.set_version() - # Run chmod -R 755 on INSTALL_DIR + # Set permissions on INSTALL_DIR if OS_NAME != 'win': - shutil.chmod(INSTALL_DIR, 0o755) + os.system(f'chmod -R 755 {shlex.quote(str(INSTALL_DIR))}') - # Clean up old installation rprint('\nCamoufox successfully installed.', fg="yellow") except Exception as e: rprint(f"Error installing Camoufox: {str(e)}") @@ -302,7 +301,7 @@ def webdl( Raises: requests.RequestException: If there's an error downloading the file """ - response = requests.get(url, stream=True, timeout=20) + response = requests.get(url, stream=True) response.raise_for_status() total_size = int(response.headers.get('content-length', 0))