Now builds with setuptools. Add some extra printing.

This commit is contained in:
Gnarwhal 2024-07-31 19:36:47 +00:00
parent ba53b71683
commit 3641174c18
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
2 changed files with 34 additions and 17 deletions

18
setup.py Normal file
View file

@ -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']
}
)

33
sshare → sshare/cli.py Executable file → Normal file
View file

@ -13,24 +13,28 @@ def main():
config = Config() config = Config()
file = _latest("/home/gnarwhal/Pictures/Screenshots") 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}'") print(f"=> Selected file '{file}'")
target_url = f"https://{config.ssh_target}/sshare/{target_file_name}" id = time.time_ns()
pyclip.copy(target_url) (_, extension) = os.path.splitext(file)
target_file_name = f"{id}{extension}"
subprocess.run([ 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", "scp",
f"-P {config.ssh_port}", f"-P {config.ssh_port}",
file, 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): def _latest(directory, key=os.path.getmtime):
@ -50,9 +54,4 @@ class Config:
self.ssh_port = 2222 self.ssh_port = 2222
self.ssh_user = getpass.getuser() self.ssh_user = getpass.getuser()
self.ssh_target = "monodon.me" self.ssh_target = "monodon.me"
self.ssh_dir = "~/sshare/" self.ssh_dir = "/srv/sshare"
if __name__ == '__main__':
main()