Files
sshyp/port-jobs/CLIPTOOL.py
T
RandyTheSilly a89b201fc7 Added warning if relevant clipboard tool is not installed
Former-commit-id: 2d89d7954a6d1c0133f235862e78b1bcfdcef9ff
Former-commit-id: 988a751409f02e2b065c461d4c3f723472ee725a
2023-05-11 12:11:30 -04:00

37 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
import re
from sys import argv, exit as s_exit
# read arguments
arguments = argv[1:]
# define PORT target
string1 = '# PORT START CLIPTOOL'
string2 = '# PORT END CLIPTOOL'
# define replacement text depending on arguments
if len(arguments) > 0:
regex = re.compile(f"{string1}.*?{string2}", re.DOTALL)
replacement = """# check for clipboard tool and display warning if missing
if 'WAYLAND_DISPLAY' in environ:
_display_server, _clipboard_tool = 'Wayland', 'wl-clipboard'
else:
_display_server, _clipboard_tool = 'X11', 'xclip'
from shutil import which
if which(_clipboard_tool) is None:
print(f'''\u001b[38;5;9mwarning: you are using {_display_server} and "{_clipboard_tool}" is not present -
copying entry fields will not function until "{_clipboard_tool}" is installed\u001b[0m
''')"""
else:
regex = re.compile(f"{string1}.*?{string2}\n\n", re.DOTALL)
replacement = ''
# read input file
text = open('working/sshyp.py', 'r').read()
# find and replace the defined PORT target
new_text = re.sub(regex, replacement, text)
# write updated text
open('working/sshyp.py', 'w').write(new_text)