removed multithreading
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,4 +2,4 @@ dist
|
|||||||
.idea
|
.idea
|
||||||
*.pyc
|
*.pyc
|
||||||
*.egg-info
|
*.egg-info
|
||||||
env
|
venv
|
||||||
|
@@ -1,26 +1,24 @@
|
|||||||
import urllib.parse
|
|
||||||
import re
|
|
||||||
import math
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import pycurl
|
import re
|
||||||
import certifi
|
import urllib.parse
|
||||||
from time import time, monotonic
|
from argparse import ArgumentParser
|
||||||
from threading import Thread, Condition
|
|
||||||
from dataclasses import dataclass, fields
|
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 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 import Progress
|
||||||
from progress.bar import Bar
|
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
|
from .config import load_configuration, Config
|
||||||
|
|
||||||
@@ -123,24 +121,10 @@ class JpacrepoClient:
|
|||||||
self.token: Optional[TokenResponse] = None
|
self.token: Optional[TokenResponse] = None
|
||||||
self.provider_config: ProviderConfig = fetch_provider_config(self.config.auth_server_url)
|
self.provider_config: ProviderConfig = fetch_provider_config(self.config.auth_server_url)
|
||||||
self.token_expiry: Optional[int] = None
|
self.token_expiry: Optional[int] = None
|
||||||
self.cond = Condition()
|
|
||||||
self.thread: Optional[Thread] = None
|
|
||||||
self.verbose: bool = kwargs.get('verbose', False)
|
self.verbose: bool = kwargs.get('verbose', False)
|
||||||
self.http2: bool = kwargs.get('http2', False)
|
self.http2: bool = kwargs.get('http2', False)
|
||||||
self.http3: bool = kwargs.get('http3', 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:
|
def authenticate(self) -> None:
|
||||||
token = oidc_client.login(
|
token = oidc_client.login(
|
||||||
provider_config=self.provider_config,
|
provider_config=self.provider_config,
|
||||||
@@ -151,20 +135,6 @@ class JpacrepoClient:
|
|||||||
self.token = token
|
self.token = token
|
||||||
self.token_expiry = (token.created_at or int(time())) + (token.expires_in or 10)
|
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:
|
def refresh_token(self) -> None:
|
||||||
token = self.token
|
token = self.token
|
||||||
if not token:
|
if not token:
|
||||||
@@ -234,6 +204,9 @@ class JpacrepoClient:
|
|||||||
progress = XferProgress(packages_to_upload=len(files), packages_total_size=total_size)
|
progress = XferProgress(packages_to_upload=len(files), packages_total_size=total_size)
|
||||||
start_ts = monotonic()
|
start_ts = monotonic()
|
||||||
for i, file in enumerate(files):
|
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
|
upload_size = file.stat().st_size
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
width=64,
|
width=64,
|
||||||
@@ -314,14 +287,14 @@ def main() -> None:
|
|||||||
help="Enable HTTP/3 protocol")
|
help="Enable HTTP/3 protocol")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
logging.basicConfig(encoding='utf-8', level=logging.INFO)
|
logging.basicConfig(encoding='utf-8', level=logging.INFO)
|
||||||
with JpacrepoClient(load_configuration(), **args.__dict__) as client:
|
client = JpacrepoClient(load_configuration(), **args.__dict__)
|
||||||
client.authenticate()
|
client.authenticate()
|
||||||
files = client.packages_to_upload()
|
files = client.packages_to_upload()
|
||||||
if len(files):
|
if len(files):
|
||||||
logger.debug(f'Files to be uploaded: {files}')
|
logger.debug(f'Files to be uploaded: {files}')
|
||||||
client.upload(files)
|
client.upload(files)
|
||||||
else:
|
else:
|
||||||
logger.info('No packages will be uploaded')
|
logger.info('No packages will be uploaded')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Reference in New Issue
Block a user