Reduced lines used for KeyboardInterrupt exception

This commit is contained in:
2022-05-22 23:43:34 -04:00
parent 7aa9ea63e2
commit 13d466bb21
+79 -106
View File
@@ -619,123 +619,96 @@ def remove_data(): # deletes an entry from the server and flags it for local de
if __name__ == "__main__": if __name__ == "__main__":
silent_sync = 0 try:
# retrieve typed argument silent_sync = 0
argument_list, argument = argv, '' # retrieve typed argument
del argument_list[0] argument_list, argument = argv, ''
for _argument in argument_list: del argument_list[0]
argument += _argument + ' ' for _argument in argument_list:
argument = argument[:-1] argument += _argument + ' '
if uname()[0] == 'Haiku': # set proper gpg command for OS argument = argument[:-1]
gpg = 'gpg --pinentry-mode loopback' if uname()[0] == 'Haiku': # set proper gpg command for OS
else: gpg = 'gpg --pinentry-mode loopback'
gpg = 'gpg' else:
gpg = 'gpg'
# import saved userdata # import saved userdata
if argument != 'tweak': if argument != 'tweak':
device_type = '' device_type = ''
tmp_dir = path.expanduser('~/.config/sshyp/tmp/') tmp_dir = path.expanduser('~/.config/sshyp/tmp/')
try: try:
device_type = open(path.expanduser('~/.config/sshyp/sshyp-device')).read().strip() device_type = open(path.expanduser('~/.config/sshyp/sshyp-device')).read().strip()
if device_type == 'c': if device_type == 'c':
gpg_id = open(path.expanduser('~/.config/sshyp/sshyp-gpg')).read().strip() gpg_id = open(path.expanduser('~/.config/sshyp/sshyp-gpg')).read().strip()
ssh_info = sshync.get_profile(path.expanduser('~/.config/sshyp/sshyp.sshync')) ssh_info = sshync.get_profile(path.expanduser('~/.config/sshyp/sshyp.sshync'))
username_ssh = ssh_info[0].replace('\n', '') username_ssh = ssh_info[0].replace('\n', '')
ip = ssh_info[1].replace('\n', '') ip = ssh_info[1].replace('\n', '')
port = ssh_info[2].replace('\n', '') port = ssh_info[2].replace('\n', '')
directory = str(ssh_info[3].replace('\n', '')) directory = str(ssh_info[3].replace('\n', ''))
directory_ssh = '/home/' + username_ssh + '/.password-pasture/' directory_ssh = '/home/' + username_ssh + '/.password-pasture/'
client_device_name = listdir(path.expanduser('~/.config/sshyp/devices'))[0] client_device_name = listdir(path.expanduser('~/.config/sshyp/devices'))[0]
except FileNotFoundError: except FileNotFoundError:
if device_type.lower() != 's': if device_type.lower() != 's':
print('\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') print('\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
print("Not all necessary configuration files are present. Please run 'sshyp tweak'!") print("Not all necessary configuration files are present. Please run 'sshyp tweak'!")
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n') print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n')
s_exit(1) s_exit(1)
else: else:
try:
tweak() tweak()
s_exit(0) s_exit(0)
except KeyboardInterrupt:
print('\n')
s_exit(0)
# run function based on argument # run function based on argument
error = 0 # create an error flag to determine if syncing should occur at end error = 0 # create an error flag to determine if syncing should occur at end
if argument.startswith('/'): if argument.startswith('/'):
read_shortcut() read_shortcut()
elif argument == '': elif argument == '':
try:
no_arg() no_arg()
except KeyboardInterrupt: elif argument == 'help' or argument == '--help' or argument == '-h' or argument == 'license' or argument \
print('\n') == 'version' or argument == '-v' or argument == 'add' or argument == 'edit' or argument == 'copy':
s_exit(0) print_info()
elif argument == 'help' or argument == '--help' or argument == '-h' or argument == 'license' or \ elif argument.startswith('add note') or argument.startswith('add -n') or argument.startswith('add password') \
argument == 'version' or argument == '-v' or argument == 'add' or argument == 'edit' or argument == 'copy': or argument.startswith('add -p'):
print_info()
elif argument.startswith('add note') or argument.startswith('add -n') or argument.startswith('add password') \
or argument.startswith('add -p'):
try:
add_entry() add_entry()
except KeyboardInterrupt: elif argument.startswith('add folder') or argument.startswith('add -f'):
print('\n')
s_exit(0)
elif argument.startswith('add folder') or argument.startswith('add -f'):
try:
add_folder() add_folder()
except KeyboardInterrupt: elif argument.startswith('edit rename') or argument.startswith('edit relocate') or argument.startswith(
print('\n') 'edit -r'):
s_exit(0) silent_sync = 1
elif argument.startswith('edit rename') or argument.startswith('edit relocate') or argument.startswith('edit -r'):
silent_sync = 1
try:
rename() rename()
except KeyboardInterrupt: elif argument.startswith('edit username') or argument.startswith('edit -u') or argument.startswith(
print('\n') 'edit password') \
s_exit(0) or argument.startswith('edit -p') or argument.startswith('edit url') or argument.startswith(
elif argument.startswith('edit username') or argument.startswith('edit -u') or argument.startswith('edit password')\ 'edit -l') or \
or argument.startswith('edit -p') or argument.startswith('edit url') or argument.startswith('edit -l') or \ argument.startswith('edit note') or argument.startswith('edit -n'):
argument.startswith('edit note') or argument.startswith('edit -n'):
try:
edit() edit()
except KeyboardInterrupt: elif argument.startswith('gen'):
print('\n')
s_exit(0)
elif argument.startswith('gen'):
try:
gen() gen()
except KeyboardInterrupt: elif argument.startswith('copy username') or argument.startswith('copy -u') or argument.startswith(
print('\n') 'copy password') \
s_exit(0) or argument.startswith('copy -p') or argument.startswith('copy url') or argument.startswith('copy -l') \
elif argument.startswith('copy username') or argument.startswith('copy -u') or argument.startswith('copy password')\ or argument.startswith('copy note') or argument.startswith('copy -n'):
or argument.startswith('copy -p') or argument.startswith('copy url') or argument.startswith('copy -l') \
or argument.startswith('copy note') or argument.startswith('copy -n'):
try:
copy_data() copy_data()
except KeyboardInterrupt: elif argument.startswith('shear') or argument.startswith('-rm'):
print('\n')
s_exit(0)
elif argument.startswith('shear') or argument.startswith('-rm'):
try:
remove_data() remove_data()
except KeyboardInterrupt: elif argument == 'sync' or argument == '-s':
print('\n') sync()
s_exit(0) else:
elif argument == 'sync' or argument == '-s': error = 1 # set error flag to 1 to stop syncing
sync() print("\nArgument error! Please run 'sshyp help' for a list of usable commands.\n")
else: s_exit(1)
error = 1 # set error flag to 1 to stop syncing
print("\nArgument error! Please run 'sshyp help' for a list of usable commands.\n")
s_exit(1)
# sync at end of program if any changes were made # sync at end of program if any changes were made
if argument != '' and argument != 'help' and argument != '--help' and argument != '-h' and argument != 'license' \ if argument != '' and argument != 'help' and argument != '--help' and argument != '-h' and argument != \
and argument != 'add' and argument != 'sync' and argument != 'edit' and not argument. \ 'license' and argument != 'add' and argument != 'sync' and argument != 'edit' and not argument\
startswith('copy username') and not argument.startswith('copy -u') and not argument. \ .startswith('copy username') and not argument.startswith('copy -u') and not argument\
startswith('copy password') and not argument.startswith('copy -p') and not argument. \ .startswith('copy password') and not argument.startswith('copy -p') and not argument\
startswith('copy url') and not argument.startswith('copy -l') and not argument. \ .startswith('copy url') and not argument.startswith('copy -l') and not argument.startswith('copy note')\
startswith('copy note') and not argument.startswith('copy -n') and argument != 'copy' and argument \ and not argument.startswith('copy -n') and argument != 'copy' and argument != 'version' and argument \
!= 'version' and argument != '-v' and error == 0 and argument.startswith('/') is False: != '-v' and error == 0 and argument.startswith('/') is False:
sync() sync()
s_exit(0) s_exit(0)
except KeyboardInterrupt:
print('\n')
s_exit(0)