script changes
This commit is contained in:
parent
1745e834af
commit
eaa112e0a8
2 changed files with 11 additions and 11 deletions
|
@ -30,8 +30,14 @@ def notify(
|
|||
|
||||
|
||||
def read_secret_file(secret: str) -> str:
|
||||
path = f"/run/secrets/{secret}"
|
||||
if not os.path.exists(path):
|
||||
raise FileNotFoundError(f"Secret file {path} does not exist.")
|
||||
with open(f"/run/secrets/{secret}", "r") as f:
|
||||
return f.read().strip()
|
||||
secret = f.read().strip()
|
||||
if not secret:
|
||||
raise ValueError(f"Secret file {path} is empty.")
|
||||
return secret
|
||||
|
||||
|
||||
def does_desktop_entry_exist(desktop_entry: str) -> bool:
|
||||
|
|
|
@ -20,23 +20,17 @@ def zipline(
|
|||
desktop_entry: str = None,
|
||||
) -> Any:
|
||||
token = read_secret_file("zipline")
|
||||
if not token:
|
||||
raise FileNotFoundError(
|
||||
"Secret file at /run/secrets/zipline either does not exist or is empty."
|
||||
)
|
||||
|
||||
if not os.path.isfile(file_path):
|
||||
raise FileNotFoundError(f"File at {file_path} does not exist.")
|
||||
|
||||
use_send_notify = False
|
||||
use_notify_send = False
|
||||
if application_name and desktop_entry:
|
||||
if not does_desktop_entry_exist(desktop_entry=desktop_entry):
|
||||
raise FileNotFoundError("Desktop entry does not exist.")
|
||||
|
||||
if not which("notify-send"):
|
||||
raise FileNotFoundError("notify-send is not installed.")
|
||||
|
||||
use_send_notify = True
|
||||
use_notify_send = True
|
||||
|
||||
content_type = mimetypes.guess_type(file_path)[0] or "application/octet-stream"
|
||||
|
||||
|
@ -57,7 +51,7 @@ def zipline(
|
|||
copy(text=link)
|
||||
print(f"Link copied to clipboard: {link}")
|
||||
|
||||
if use_send_notify:
|
||||
if use_notify_send:
|
||||
notify(
|
||||
application_name=application_name,
|
||||
title="Upload Successful",
|
||||
|
@ -73,7 +67,7 @@ def zipline(
|
|||
raise Exception(error_message)
|
||||
|
||||
except Exception as e:
|
||||
if use_send_notify:
|
||||
if use_notify_send:
|
||||
notify(
|
||||
application_name=application_name,
|
||||
title="Upload Failed",
|
||||
|
|
Loading…
Reference in a new issue