Now builds with setuptools. Add some extra printing.
This commit is contained in:
parent
ba53b71683
commit
3641174c18
2 changed files with 34 additions and 17 deletions
18
setup.py
Normal file
18
setup.py
Normal 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
33
sshare → sshare/cli.py
Executable file → Normal file
|
@ -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"
|
Loading…
Reference in a new issue