Big single progress bar
Having the window open again and again is so boring!
This commit is contained in:
parent
2c4e62656d
commit
dbd663dcf0
1 changed files with 53 additions and 45 deletions
|
@ -11,6 +11,7 @@ import subprocess
|
|||
import tempfile
|
||||
import logging
|
||||
import random
|
||||
import contextlib
|
||||
|
||||
import requests
|
||||
|
||||
|
@ -37,6 +38,9 @@ class RcloneBackend:
|
|||
"""
|
||||
self.remote_name = remote_name
|
||||
|
||||
def __str__(self):
|
||||
return f"<{self.remote_name}>"
|
||||
|
||||
def actual_path(self, destination_path: str):
|
||||
return destination_path
|
||||
|
||||
|
@ -76,6 +80,9 @@ class ArchiveBackend:
|
|||
self.bucket = None # final available bucket to be used
|
||||
self.dl_url = None # final download URL
|
||||
|
||||
def __str__(self):
|
||||
return '<archive.org>'
|
||||
|
||||
@property
|
||||
def auth_headers(self):
|
||||
return {"authorization": f"LOW {self.accesskey}:{self.secret}"}
|
||||
|
@ -142,6 +149,9 @@ class ArkiwiBackend(RcloneBackend):
|
|||
super().__init__(remote_name)
|
||||
self.prefix: bytes = prefix.strip("/").encode("utf8")
|
||||
|
||||
def __str__(self):
|
||||
return '<www.arkiwi.org>'
|
||||
|
||||
def ftp_path(self, path: bytes) -> bytes:
|
||||
return b"ftp://upload.arkiwi.org/%s/" % (path.strip(b"/"),)
|
||||
|
||||
|
@ -204,6 +214,18 @@ BACKENDS = {
|
|||
}
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def zenity_pulsate(args):
|
||||
proc = subprocess.Popen(
|
||||
["zenity", "--auto-close", "--progress", "--pulsate", *args],
|
||||
text=True,
|
||||
stdin=subprocess.PIPE)
|
||||
try:
|
||||
yield proc.stdin
|
||||
finally:
|
||||
proc.stdin.close()
|
||||
|
||||
|
||||
class Carichello:
|
||||
def __init__(self):
|
||||
self.parser = self.get_parser()
|
||||
|
@ -245,7 +267,7 @@ class Carichello:
|
|||
self.args = self.parser.parse_args()
|
||||
with self.args.config.open() as buf:
|
||||
self.config = json.load(buf)
|
||||
backend_config = self.config['backends'][0]
|
||||
backend_config = self.config["backends"][0]
|
||||
backend_config.setdefault("type", "default")
|
||||
BackendCls = BACKENDS[backend_config["type"]]
|
||||
if self.args.file is None:
|
||||
|
@ -276,62 +298,48 @@ class Carichello:
|
|||
else:
|
||||
url = None
|
||||
LOG.info("file %s would be uploaded", str(self.args.file))
|
||||
zenity = Popen(
|
||||
[
|
||||
"zenity",
|
||||
"--auto-close",
|
||||
"--progress",
|
||||
"--pulsate",
|
||||
"--title=Caricamento su Arkiwi",
|
||||
f"--text=Verifiche file {self.args.file.name} in corso...",
|
||||
],
|
||||
stdin=PIPE,
|
||||
)
|
||||
try:
|
||||
exists = backend.exists(dest_file)
|
||||
zenity.stdin.close()
|
||||
|
||||
with zenity_pulsate([f"--title=Caricamento file su {backend}",
|
||||
f"--text=Verifiche file {self.args.file.name} in corso..."]) as zenity:
|
||||
try:
|
||||
exists = backend.exists(dest_file)
|
||||
except subprocess.CalledProcessError as exc:
|
||||
zenity.close()
|
||||
return self.error_exception(exc)
|
||||
if exists:
|
||||
zenity.close()
|
||||
subprocess.run(
|
||||
[
|
||||
"zenity",
|
||||
"--info",
|
||||
"--title=Caricamento su Arkiwi",
|
||||
f"--title=Caricamento su {backend}",
|
||||
f"--text=File {self.args.file.name} già presente:\n{url}",
|
||||
]
|
||||
)
|
||||
return 1
|
||||
except subprocess.CalledProcessError as exc:
|
||||
zenity.stdin.close()
|
||||
return self.error_exception(exc)
|
||||
|
||||
reserved_url = backend.reserve(self.args.file)
|
||||
if url is None:
|
||||
url = reserved_url
|
||||
else:
|
||||
assert url == reserved_url
|
||||
zenity.write(f"# Creazione item per {self.args.file.name}\n")
|
||||
zenity.flush()
|
||||
reserved_url = backend.reserve(self.args.file)
|
||||
if url is None:
|
||||
url = reserved_url
|
||||
else:
|
||||
assert url == reserved_url
|
||||
|
||||
if url:
|
||||
self.set_clipboard(url)
|
||||
text = f"Caricamento file {self.args.file.name} su {backend_config['type']} in corso...\n Copia l'indirizzo da usare <a href='#'>📋 </a>"
|
||||
else:
|
||||
text = f"Caricamento file {self.args.file.name} su {backend_config['type']} in corso..."
|
||||
zenity = Popen(
|
||||
[
|
||||
"zenity",
|
||||
"--auto-close",
|
||||
"--progress",
|
||||
"--pulsate",
|
||||
f"--text={text}",
|
||||
],
|
||||
stdin=PIPE,
|
||||
)
|
||||
try:
|
||||
url = backend.copy(self.args.file, dest_file)
|
||||
except Exception as exc:
|
||||
return self.error_exception(exc)
|
||||
finally:
|
||||
zenity.stdin.close()
|
||||
if url:
|
||||
self.set_clipboard(url)
|
||||
text = f"Caricamento su {url} in corso... Copia l'indirizzo da usare: 📋"
|
||||
else:
|
||||
text = f"Caricamento {self.args.file.name} in corso..."
|
||||
zenity.write(f"# {text}\n")
|
||||
zenity.flush()
|
||||
try:
|
||||
url = backend.copy(self.args.file, dest_file)
|
||||
except Exception as exc:
|
||||
zenity.close()
|
||||
return self.error_exception(exc)
|
||||
LOG.info("ready: %s", url)
|
||||
self.set_clipboard(url)
|
||||
subprocess.run(
|
||||
[
|
||||
"zenity",
|
||||
|
|
Loading…
Reference in a new issue