improved logging
All checks were successful
CI / build (push) Successful in 54s

fixed bug with scan path
This commit is contained in:
2025-12-20 13:35:37 +08:00
parent ab27da85af
commit 253483c992
5 changed files with 54 additions and 29 deletions

View File

@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "jpacrepo-uploader" name = "jpacrepo-uploader"
version = "0.0.4" version = "0.0.5"
authors = [ authors = [
{ name="Walter Oggioni", email="oggioni.walter@gmail.com" }, { name="Walter Oggioni", email="oggioni.walter@gmail.com" },
] ]

View File

@@ -2,44 +2,44 @@
# This file is autogenerated by pip-compile with Python 3.13 # This file is autogenerated by pip-compile with Python 3.13
# by the following command: # by the following command:
# #
# pip-compile --allow-unsafe --extra=dev --output-file=requirements-dev.txt # pip-compile --cert=None --client-cert=None --extra=dev --index-url=None --output-file=requirements-dev.txt --pip-args=None --strip-extras pyproject.toml
# #
--index-url https://gitea.woggioni.net/api/packages/woggioni/pypi/simple --index-url https://gitea.woggioni.net/api/packages/woggioni/pypi/simple
--extra-index-url https://pypi.org/simple --extra-index-url https://pypi.org/simple
asttokens==3.0.0 asttokens==3.0.1
# via stack-data # via stack-data
build==1.3.0 build==1.3.0
# via # via
# jpacrepo-uploader (pyproject.toml) # jpacrepo-uploader (pyproject.toml)
# pip-tools # pip-tools
certifi==2025.8.3 certifi==2025.11.12
# via # via
# jpacrepo-uploader (pyproject.toml) # jpacrepo-uploader (pyproject.toml)
# requests # requests
cffi==2.0.0 cffi==2.0.0
# via cryptography # via cryptography
charset-normalizer==3.4.3 charset-normalizer==3.4.4
# via requests # via requests
click==8.3.0 click==8.3.1
# via pip-tools # via pip-tools
cryptography==46.0.2 cryptography==46.0.3
# via secretstorage # via secretstorage
decorator==5.2.1 decorator==5.2.1
# via # via
# ipdb # ipdb
# ipython # ipython
docutils==0.22.2 docutils==0.22.4
# via readme-renderer # via readme-renderer
executing==2.2.1 executing==2.2.1
# via stack-data # via stack-data
id==1.5.0 id==1.5.0
# via twine # via twine
idna==3.10 idna==3.11
# via requests # via requests
ipdb==0.13.13 ipdb==0.13.13
# via jpacrepo-uploader (pyproject.toml) # via jpacrepo-uploader (pyproject.toml)
ipython==9.6.0 ipython==9.8.0
# via ipdb # via ipdb
ipython-pygments-lexers==1.1.1 ipython-pygments-lexers==1.1.1
# via ipython # via ipython
@@ -55,11 +55,13 @@ jeepney==0.9.0
# via # via
# keyring # keyring
# secretstorage # secretstorage
keyring==25.6.0 keyring==25.7.0
# via twine # via twine
librt==0.7.4
# via mypy
markdown-it-py==4.0.0 markdown-it-py==4.0.0
# via rich # via rich
matplotlib-inline==0.1.7 matplotlib-inline==0.2.1
# via ipython # via ipython
mdurl==0.1.2 mdurl==0.1.2
# via markdown-it-py # via markdown-it-py
@@ -67,11 +69,11 @@ more-itertools==10.8.0
# via # via
# jaraco-classes # jaraco-classes
# jaraco-functools # jaraco-functools
mypy==1.18.2 mypy==1.19.1
# via jpacrepo-uploader (pyproject.toml) # via jpacrepo-uploader (pyproject.toml)
mypy-extensions==1.1.0 mypy-extensions==1.1.0
# via mypy # via mypy
nh3==0.3.0 nh3==0.3.2
# via readme-renderer # via readme-renderer
oidc-client==0.2.6 oidc-client==0.2.6
# via jpacrepo-uploader (pyproject.toml) # via jpacrepo-uploader (pyproject.toml)
@@ -85,7 +87,7 @@ pathspec==0.12.1
# via mypy # via mypy
pexpect==4.9.0 pexpect==4.9.0
# via ipython # via ipython
pip-tools==7.5.0 pip-tools==7.5.2
# via jpacrepo-uploader (pyproject.toml) # via jpacrepo-uploader (pyproject.toml)
progress==1.6.1 progress==1.6.1
# via jpacrepo-uploader (pyproject.toml) # via jpacrepo-uploader (pyproject.toml)
@@ -122,9 +124,9 @@ requests-toolbelt==1.0.0
# via twine # via twine
rfc3986==2.0.0 rfc3986==2.0.0
# via twine # via twine
rich==14.1.0 rich==14.2.0
# via twine # via twine
secretstorage==3.4.0 secretstorage==3.5.0
# via keyring # via keyring
stack-data==0.6.3 stack-data==0.6.3
# via ipython # via ipython
@@ -134,14 +136,14 @@ traitlets==5.14.3
# matplotlib-inline # matplotlib-inline
twine==6.2.0 twine==6.2.0
# via jpacrepo-uploader (pyproject.toml) # via jpacrepo-uploader (pyproject.toml)
types-pycurl==7.45.7.20250926 types-pycurl==7.45.7.20251101
# via jpacrepo-uploader (pyproject.toml) # via jpacrepo-uploader (pyproject.toml)
typing-extensions==4.15.0 typing-extensions==4.15.0
# via # via
# jpacrepo-uploader (pyproject.toml) # jpacrepo-uploader (pyproject.toml)
# mypy # mypy
# pwo # pwo
urllib3==2.5.0 urllib3==2.6.2
# via # via
# requests # requests
# twine # twine
@@ -151,7 +153,5 @@ wheel==0.45.1
# via pip-tools # via pip-tools
# The following packages are considered to be unsafe in a requirements file: # The following packages are considered to be unsafe in a requirements file:
pip==25.2 # pip
# via pip-tools # setuptools
setuptools==80.9.0
# via pip-tools

View File

@@ -2,12 +2,12 @@
# This file is autogenerated by pip-compile with Python 3.13 # This file is autogenerated by pip-compile with Python 3.13
# by the following command: # by the following command:
# #
# pip-compile --allow-unsafe --output-file=requirements.txt # pip-compile --cert=None --client-cert=None --index-url=None --output-file=requirements.txt --pip-args=None --strip-extras pyproject.toml
# #
--index-url https://gitea.woggioni.net/api/packages/woggioni/pypi/simple --index-url https://gitea.woggioni.net/api/packages/woggioni/pypi/simple
--extra-index-url https://pypi.org/simple --extra-index-url https://pypi.org/simple
certifi==2025.8.3 certifi==2025.11.12
# via jpacrepo-uploader (pyproject.toml) # via jpacrepo-uploader (pyproject.toml)
oidc-client==0.2.6 oidc-client==0.2.6
# via jpacrepo-uploader (pyproject.toml) # via jpacrepo-uploader (pyproject.toml)
@@ -17,7 +17,7 @@ pwo==0.0.7
# via jpacrepo-uploader (pyproject.toml) # via jpacrepo-uploader (pyproject.toml)
pycurl==7.45.7 pycurl==7.45.7
# via jpacrepo-uploader (pyproject.toml) # via jpacrepo-uploader (pyproject.toml)
types-pycurl==7.45.7.20250926 types-pycurl==7.45.7.20251101
# via jpacrepo-uploader (pyproject.toml) # via jpacrepo-uploader (pyproject.toml)
typing-extensions==4.15.0 typing-extensions==4.15.0
# via # via

View File

@@ -5,9 +5,12 @@ from pathlib import Path
from itertools import chain from itertools import chain
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional from typing import Optional
import logging
_config_file_name = 'client.properties' _config_file_name = 'client.properties'
logger = logging.getLogger('jpacrepo-uploader.config')
@dataclass @dataclass
class Config: class Config:
@@ -27,7 +30,7 @@ config_file_candidates = [
.filter(Path.exists)), .filter(Path.exists)),
(Maybe.of_nullable(environ['HOME']) (Maybe.of_nullable(environ['HOME'])
.map(Path) .map(Path)
.map(lambda home: home / '.config' / _config_file_name) .map(lambda home: home / '.config' / 'jpacrepo' /_config_file_name)
.filter(Path.exists)) .filter(Path.exists))
] ]
@@ -41,6 +44,7 @@ def load_configuration() -> Config:
client_secret: Optional[str] = None client_secret: Optional[str] = None
for config_file_maybe in config_file_candidates: for config_file_maybe in config_file_candidates:
def process_configuration(config_file: Path) -> None: def process_configuration(config_file: Path) -> None:
logger.debug('Looking for configuration file in %s' % config_file)
nonlocal server_url, auth_server_url, client_id, client_secret nonlocal server_url, auth_server_url, client_id, client_secret
config = RawConfigParser() config = RawConfigParser()
with open(config_file, 'r') as lines: with open(config_file, 'r') as lines:

View File

@@ -11,6 +11,7 @@ from urllib.parse import urlparse, urlunparse, quote, urlencode
from urllib.request import Request from urllib.request import Request
from threading import Thread, Condition from threading import Thread, Condition
import enum
import certifi import certifi
import math import math
import oidc_client import oidc_client
@@ -25,7 +26,7 @@ from pwo import format_filesize, retry, ExceptionHandlerOutcome
from .config import load_configuration, Config from .config import load_configuration, Config
logger = logging.getLogger('jpacrepo.uploader') logger = logging.getLogger('jpacrepo-uploader.uploader')
package_file_pattern = re.compile('.*\\.pkg\\.tar\\.(xz|zst|gz)$') package_file_pattern = re.compile('.*\\.pkg\\.tar\\.(xz|zst|gz)$')
@@ -222,6 +223,7 @@ class JpacrepoClient:
raise RuntimeError(f'Received HTTP error code: {response.code}') raise RuntimeError(f'Received HTTP error code: {response.code}')
def packages_to_upload(self) -> tuple[Path, ...]: def packages_to_upload(self) -> tuple[Path, ...]:
logger.info('Scanned folders: [%s]' % ', '.join((f"\"{str(path)}\"" for path in self.config.repo_folders)))
package_files: dict[str, Path] = {file.name: file for ext in _supported_compression_formats for package_cache in package_files: dict[str, Path] = {file.name: file for ext in _supported_compression_formats for package_cache in
self.config.repo_folders self.config.repo_folders
for file in package_cache.glob(f'**/*.pkg.tar.{ext}') for file in package_cache.glob(f'**/*.pkg.tar.{ext}')
@@ -325,6 +327,20 @@ class JpacrepoClient:
if http_status_code != 201: if http_status_code != 201:
raise HttpException(http_status_code) raise HttpException(http_status_code)
class LogLevel(str, enum.Enum):
CREATE = 'create'
DELETE = 'delete'
MODIFY = 'modify'
CRITICAL = 'CRITICAL'
FATAL = CRITICAL
ERROR = 'ERROR'
WARNING = 'WARNING'
WARN = WARNING
INFO = 'INFO'
DEBUG = 'DEBUG'
def __str__(self):
return self.value
def main() -> None: def main() -> None:
parser = ArgumentParser( parser = ArgumentParser(
@@ -351,8 +367,13 @@ def main() -> None:
default=False, default=False,
action='store_true', action='store_true',
help="Enable HTTP/3 protocol") help="Enable HTTP/3 protocol")
parser.add_argument('-l', '--log-level',
default=LogLevel.INFO,
type=LogLevel,
help="Set logging level")
args = parser.parse_args() args = parser.parse_args()
logging.basicConfig(encoding='utf-8', level=logging.INFO) logging.basicConfig(encoding='utf-8', level=logging.getLevelNamesMapping()[args.log_level])
with JpacrepoClient(load_configuration(), **vars(args)) as client: with JpacrepoClient(load_configuration(), **vars(args)) as client:
client.authenticate() client.authenticate()
files = client.packages_to_upload() files = client.packages_to_upload()