mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-08-31 06:16:29 -04:00
Optimized UNAME.py port-job script
Former-commit-id: 3b4e2b105fab3bb555dd4c6be3f421e68b808633 Former-commit-id: bd560b680c70bfb7a19d66ee0ad8eee4d99f3465
This commit is contained in:
+14
-44
@@ -10,53 +10,23 @@ if len(arguments) > 0:
|
|||||||
if arguments[0] == 'TMP':
|
if arguments[0] == 'TMP':
|
||||||
replacement = 'symlink("/tmp", f"{home}/.config/sshyp/tmp")'
|
replacement = 'symlink("/tmp", f"{home}/.config/sshyp/tmp")'
|
||||||
elif arguments[0] == 'TERMUX':
|
elif arguments[0] == 'TERMUX':
|
||||||
replacement = 'symlink("/data/data/com.termux/files/usr/tmp", f"{home}/.config/sshyp/tmp")'
|
replacement = 'symlink("/data/data/com.termux/files/usr/tmp", f"{home}/.config/sshyp/tmp")\n'
|
||||||
elif arguments[0] == 'LINUX':
|
elif arguments[0] == 'LINUX':
|
||||||
replacement = 'symlink("/dev/shm", f"{home}/.config/sshyp/tmp")'
|
replacement = 'symlink("/dev/shm", f"{home}/.config/sshyp/tmp")'
|
||||||
else:
|
else:
|
||||||
s_exit()
|
s_exit()
|
||||||
|
|
||||||
# UNAME-IMPORT-SSHYP
|
targets = (('UNAME-IMPORT-SSHYP', 'sshyp.py', ''), ('UNAME-IMPORT-STWEAK', 'stweak.py', ''),
|
||||||
# define PORT target
|
('UNAME-TMP', 'stweak.py', replacement))
|
||||||
string1 = '# PORT START UNAME-IMPORT-SSHYP'
|
|
||||||
string2 = '# PORT END UNAME-IMPORT-SSHYP'
|
|
||||||
|
|
||||||
# read input file
|
for target in targets:
|
||||||
text = open('working/sshyp.py', 'r').read()
|
# read text from target file
|
||||||
|
text, special = open(f"working/{target[1]}", 'r').read(), ''
|
||||||
# find and replace the defined PORT target
|
# determine text to end regex with
|
||||||
regex = re.compile(f"{string1}.*?{string2}\n", re.DOTALL)
|
if target[2] == '':
|
||||||
new_text = re.sub(regex, '', text)
|
regend = '\n'
|
||||||
|
# compile regex and modify text
|
||||||
# write updated text
|
regex = re.compile(f"# PORT START {target[0]}.*?# PORT END {target[0]}{regend}", re.DOTALL)
|
||||||
open('working/sshyp.py', 'w').write(new_text)
|
new_text = re.sub(regex, target[2], text)
|
||||||
|
# write updated text to target file
|
||||||
# UNAME-IMPORT-STWEAK
|
open(f"working/{target[1]}", 'w').write(new_text)
|
||||||
# define PORT target
|
|
||||||
string1 = '# PORT START UNAME-IMPORT-STWEAK'
|
|
||||||
string2 = '# PORT END UNAME-IMPORT-STWEAK'
|
|
||||||
|
|
||||||
# read input file
|
|
||||||
text = open('working/stweak.py', 'r').read()
|
|
||||||
|
|
||||||
# find and replace the defined PORT target
|
|
||||||
regex = re.compile(f"{string1}.*?{string2}\n", re.DOTALL)
|
|
||||||
new_text = re.sub(regex, '', text)
|
|
||||||
|
|
||||||
# write updated text
|
|
||||||
open('working/stweak.py', 'w').write(new_text)
|
|
||||||
|
|
||||||
# UNAME-TMP
|
|
||||||
# define PORT target
|
|
||||||
string1 = '# PORT START UNAME-TMP'
|
|
||||||
string2 = '# PORT END UNAME-TMP'
|
|
||||||
|
|
||||||
# read input file
|
|
||||||
text = open('working/stweak.py', 'r').read()
|
|
||||||
|
|
||||||
# find and replace the defined PORT target
|
|
||||||
regex = re.compile(f"{string1}.*?{string2}", re.DOTALL)
|
|
||||||
new_text = re.sub(regex, replacement, text)
|
|
||||||
|
|
||||||
# write updated text
|
|
||||||
open('working/stweak.py', 'w').write(new_text)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user