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