Skip to content

Commit

Permalink
Merge branch 'devine-dl:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Sp5rky authored Apr 21, 2024
2 parents 2fa7895 + 9768de8 commit 5ed8d0b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 47 deletions.
39 changes: 31 additions & 8 deletions devine/commands/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
from typing import Optional

import click
from rich.padding import Padding
from rich.table import Table
from rich.tree import Tree

from devine.core.config import config, config_path
from devine.core.config import POSSIBLE_CONFIG_PATHS, config, config_path
from devine.core.console import console
from devine.core.constants import context_settings
from devine.core.services import Services

Expand All @@ -18,13 +22,32 @@ def env() -> None:
def info() -> None:
"""Displays information about the current environment."""
log = logging.getLogger("env")
log.info(f"[Config] : {config_path or '--'}")
log.info(f"[Cookies] : {config.directories.cookies}")
log.info(f"[WVDs] : {config.directories.wvds}")
log.info(f"[Cache] : {config.directories.cache}")
log.info(f"[Logs] : {config.directories.logs}")
log.info(f"[Temp Files] : {config.directories.temp}")
log.info(f"[Downloads] : {config.directories.downloads}")

if config_path:
log.info(f"Config loaded from {config_path}")
else:
tree = Tree("No config file found, you can use any of the following locations:")
for i, path in enumerate(POSSIBLE_CONFIG_PATHS, start=1):
tree.add(f"[repr.number]{i}.[/] [text2]{path.resolve()}[/]")
console.print(Padding(
tree,
(0, 5)
))

table = Table(title="Directories", expand=True)
table.add_column("Name", no_wrap=True)
table.add_column("Path")

for name in sorted(dir(config.directories)):
if name.startswith("__") or name == "app_dirs":
continue
path = getattr(config.directories, name).resolve()
table.add_row(name.title(), str(path))

console.print(Padding(
table,
(1, 5)
))


@env.group(name="clear", short_help="Clear an environment directory.", context_settings=context_settings)
Expand Down
34 changes: 16 additions & 18 deletions devine/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,27 @@ def from_yaml(cls, path: Path) -> Config:
return cls(**yaml.safe_load(path.read_text(encoding="utf8")) or {})


def get_config_path() -> Optional[Path]:
"""
Get Path to Config from various locations.
# noinspection PyProtectedMember
POSSIBLE_CONFIG_PATHS = (
# The Devine Namespace Folder (e.g., %appdata%/Python/Python311/site-packages/devine)
Config._Directories.namespace_dir / Config._Filenames.root_config,
# The Parent Folder to the Devine Namespace Folder (e.g., %appdata%/Python/Python311/site-packages)
Config._Directories.namespace_dir.parent / Config._Filenames.root_config,
# The AppDirs User Config Folder (e.g., %localappdata%/devine)
Config._Directories.user_configs / Config._Filenames.root_config
)

Looks for a config file in the following folders in order:

1. The Devine Namespace Folder (e.g., %appdata%/Python/Python311/site-packages/devine)
2. The Parent Folder to the Devine Namespace Folder (e.g., %appdata%/Python/Python311/site-packages)
3. The AppDirs User Config Folder (e.g., %localappdata%/devine)
def get_config_path() -> Optional[Path]:
"""
Get Path to Config from any one of the possible locations.
Returns None if no config file could be found.
"""
# noinspection PyProtectedMember
path = Config._Directories.namespace_dir / Config._Filenames.root_config
if not path.exists():
# noinspection PyProtectedMember
path = Config._Directories.namespace_dir.parent / Config._Filenames.root_config
if not path.exists():
# noinspection PyProtectedMember
path = Config._Directories.user_configs / Config._Filenames.root_config
if not path.exists():
path = None
return path
for path in POSSIBLE_CONFIG_PATHS:
if path.exists():
return path
return None


config_path = get_config_path()
Expand Down
8 changes: 1 addition & 7 deletions devine/core/downloaders/curl_impersonate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pathlib import Path
from typing import Any, Generator, MutableMapping, Optional, Union

from curl_cffi import CurlOpt
from curl_cffi.requests import Session
from rich import filesize

Expand All @@ -18,7 +17,7 @@
RETRY_WAIT = 2
CHUNK_SIZE = 1024
PROGRESS_WINDOW = 5
BROWSER = config.curl_impersonate.get("browser", "chrome120")
BROWSER = config.curl_impersonate.get("browser", "chrome124")


def download(
Expand Down Expand Up @@ -53,11 +52,6 @@ def download(
for one-time request changes like a header, cookie, or proxy. For example,
to request Byte-ranges use e.g., `headers={"Range": "bytes=0-128"}`.
"""
# https://github.com/yifeikong/curl_cffi/issues/6#issuecomment-2028518677
# must be applied here since the `session.curl` is thread-localized
# noinspection PyProtectedMember
session.curl.setopt(CurlOpt.PROXY_CAINFO, session.curl._cacert)

save_dir = save_path.parent
control_file = save_path.with_name(f"{save_path.name}.!dev")

Expand Down
29 changes: 16 additions & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ subtitle-filter = "^1.4.9"
Unidecode = "^1.3.8"
urllib3 = "^2.2.1"
chardet = "^5.2.0"
curl-cffi = "^0.6.2"
curl-cffi = "^0.7.0b4"
language-data = "^1.2.0"
marisa-trie = "^1.1.0"

Expand Down

0 comments on commit 5ed8d0b

Please sign in to comment.