From caaba34666354a8bfb1e1efa184d903a8752575f Mon Sep 17 00:00:00 2001 From: kageru Date: Wed, 22 Nov 2017 09:49:00 +0100 Subject: [PATCH] allow users to choose between escrotum and i3-scrot for screen capture --- config.py | 6 ++++++ pyshare.py | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/config.py b/config.py index 3c03ba9..5df1c30 100644 --- a/config.py +++ b/config.py @@ -17,6 +17,12 @@ curl_command = None # This is where the screenshots are saved locally local_directory = '/home/kageru/pyshare/' +# Use i3scrot for screen capture. Otherwise, escrotum will be used. +# You might have to install the capture tool you want to use via your package manager. +# i3scrot was much faster for me when working with multiple high-res displays. +# If you do use it, you manually need to set its save directory to your local_directory (above) + 'tmp' in ~/.config/i3-scrot.conf +use_i3scrot = False + # Directory on the ftp server where you want the screenshots to be sent remote_directory = '/usr/share/nginx/html/pyshare/' # Template for the link that the script will generate. {} is the filename diff --git a/pyshare.py b/pyshare.py index 83764c0..5961bfa 100755 --- a/pyshare.py +++ b/pyshare.py @@ -46,12 +46,19 @@ def upload_local_file(path: str) -> str: def take_screenshot() -> None: tmppath = os.path.join(config.local_directory, 'tmp') - tmpdir = os.listdir(tmppath) - for f in tmpdir: - os.remove(os.path.join(tmppath, f)) - # you can also use programs like escrotum here, but i3-scrot was much faster for me - call(['i3-scrot', '-s']) - file = os.path.join(config.local_directory, 'tmp', os.listdir(tmppath)[0]) + if not os.path.isdir(tmppath): + os.mkdir(tmppath) + else: + tmpdir = os.listdir(tmppath) + for f in tmpdir: + os.remove(os.path.join(tmppath, f)) + if config.use_i3scrot: + call(['i3-scrot', '-s']) + file = os.path.join(tmppath, os.listdir(tmppath)[0]) + else: + tempname = generate_filename(3, 'png') + call(['escrotum', '-s', tempname]) + file = os.path.join(tmppath, tempname) ftp_upload(ext='png', sourcefile=file) os.remove(file)