From 3641174c18ef94d99936957d3e7a79abb080e8c1 Mon Sep 17 00:00:00 2001 From: Gnarwhal Date: Wed, 31 Jul 2024 19:36:47 +0000 Subject: [PATCH] Now builds with setuptools. Add some extra printing. --- setup.py | 18 ++++++++++++++++++ sshare => sshare/cli.py | 33 ++++++++++++++++----------------- 2 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 setup.py rename sshare => sshare/cli.py (72%) mode change 100755 => 100644 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..de7ee60 --- /dev/null +++ b/setup.py @@ -0,0 +1,18 @@ +from setuptools import setup + +setup( + name='sshare', + version='0.1.0', + license='GPL-3.0-or-later', + url='https://forge.monodon.me/Gnarwhal/sshare', + description=' Convenience script for uploading files to a server via ssh', + author='Gnarwhal', + author_email='git.aspect893@passmail.net', + packages=['sshare'], + install_requires=[ + 'pyclip', + ], + entry_points={ + 'console_scripts': ['sshare = sshare.cli:main'] + } +) diff --git a/sshare b/sshare/cli.py old mode 100755 new mode 100644 similarity index 72% rename from sshare rename to sshare/cli.py index 30f2c6b..f1b308a --- a/sshare +++ b/sshare/cli.py @@ -13,24 +13,28 @@ def main(): config = Config() file = _latest("/home/gnarwhal/Pictures/Screenshots") - (_, extension) = os.path.splitext(file) - - id = time.time_ns() - target_file_name = f"{id}{extension}" - print(f"=> Selected file '{file}'") - target_url = f"https://{config.ssh_target}/sshare/{target_file_name}" - pyclip.copy(target_url) - - subprocess.run([ + id = time.time_ns() + (_, extension) = os.path.splitext(file) + target_file_name = f"{id}{extension}" + target_destination = f"{config.ssh_user}@{config.ssh_target}:{config.ssh_dir}/{target_file_name}" + print(f"=> Uploading to '{target_destination}'") + process = subprocess.run([ "scp", f"-P {config.ssh_port}", file, - f"{config.ssh_user}@{config.ssh_target}:{config.ssh_dir}/{target_file_name}", + target_destination, ]) + if process.returncode != 0: + print("=> Error: failed to upload file") + sys.exit(1) - print(f"=> File uploaded to {target_url}") + target_url = f"https://{config.ssh_target}/sshare/{target_file_name}" + pyclip.copy(target_url) + print(f"=> File available at '{target_url}'") + + sys.exit(0) def _latest(directory, key=os.path.getmtime): @@ -50,9 +54,4 @@ class Config: self.ssh_port = 2222 self.ssh_user = getpass.getuser() self.ssh_target = "monodon.me" - self.ssh_dir = "~/sshare/" - - -if __name__ == '__main__': - main() - + self.ssh_dir = "/srv/sshare"