removed multithreading

This commit is contained in:
2023-11-10 09:23:01 +08:00
parent 5a33ae9ac2
commit 93e7ccd9b7
2 changed files with 27 additions and 54 deletions

2
.gitignore vendored
View File

@@ -2,4 +2,4 @@ dist
.idea
*.pyc
*.egg-info
env
venv

View File

@@ -1,26 +1,24 @@
import urllib.parse
import re
import math
import json
import logging
import pycurl
import certifi
from time import time, monotonic
from threading import Thread, Condition
import re
import urllib.parse
from argparse import ArgumentParser
from dataclasses import dataclass, fields
import oidc_client
from oidc_client.discovery import fetch_provider_config
from oidc_client.config import ProviderConfig, DEFAULT_REDIRECT_URI
from oidc_client.oauth import TokenResponse
from urllib.request import Request
from urllib.parse import urlparse, urlunparse, quote, urlencode, ParseResult
from pathlib import Path
from time import time, monotonic
from typing import Optional, Any
from urllib.parse import urlparse, urlunparse, quote, urlencode
from urllib.request import Request
import certifi
import math
import oidc_client
import pycurl
from oidc_client.config import ProviderConfig, DEFAULT_REDIRECT_URI
from oidc_client.discovery import fetch_provider_config
from oidc_client.oauth import TokenResponse
from progress import Progress
from progress.bar import Bar
from typing import Optional, Any
from typing_extensions import Self
from argparse import ArgumentParser, Action
from .config import load_configuration, Config
@@ -123,24 +121,10 @@ class JpacrepoClient:
self.token: Optional[TokenResponse] = None
self.provider_config: ProviderConfig = fetch_provider_config(self.config.auth_server_url)
self.token_expiry: Optional[int] = None
self.cond = Condition()
self.thread: Optional[Thread] = None
self.verbose: bool = kwargs.get('verbose', False)
self.http2: bool = kwargs.get('http2', False)
self.http3: bool = kwargs.get('http3', False)
def __enter__(self) -> Self:
return self
def __exit__(self, exc_type: None, exc_val: None, exc_tb: None) -> None:
cond = self.cond
with cond:
cond.notify()
thread = self.thread
self.thread = None
if thread:
thread.join()
def authenticate(self) -> None:
token = oidc_client.login(
provider_config=self.provider_config,
@@ -151,20 +135,6 @@ class JpacrepoClient:
self.token = token
self.token_expiry = (token.created_at or int(time())) + (token.expires_in or 10)
def thread_callback() -> None:
cond = self.cond
with cond:
while self.thread:
expires_in = (self.token_expiry or 0) - int(time())
if expires_in < 30:
self.refresh_token()
else:
cond.wait(expires_in - 30)
thread = Thread(target=thread_callback)
self.thread = thread
thread.start()
def refresh_token(self) -> None:
token = self.token
if not token:
@@ -234,6 +204,9 @@ class JpacrepoClient:
progress = XferProgress(packages_to_upload=len(files), packages_total_size=total_size)
start_ts = monotonic()
for i, file in enumerate(files):
expires_in = (self.token_expiry or 0) - int(time())
if expires_in < 30:
self.refresh_token()
upload_size = file.stat().st_size
kwargs = dict(
width=64,
@@ -314,14 +287,14 @@ def main() -> None:
help="Enable HTTP/3 protocol")
args = parser.parse_args()
logging.basicConfig(encoding='utf-8', level=logging.INFO)
with JpacrepoClient(load_configuration(), **args.__dict__) as client:
client.authenticate()
files = client.packages_to_upload()
if len(files):
logger.debug(f'Files to be uploaded: {files}')
client.upload(files)
else:
logger.info('No packages will be uploaded')
client = JpacrepoClient(load_configuration(), **args.__dict__)
client.authenticate()
files = client.packages_to_upload()
if len(files):
logger.debug(f'Files to be uploaded: {files}')
client.upload(files)
else:
logger.info('No packages will be uploaded')
if __name__ == '__main__':