mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-08-28 12:56:28 -04:00
Added return codes
This commit is contained in:
+1
-1
@@ -63,7 +63,7 @@ def get_profile(_profile_dir):
|
||||
except (FileNotFoundError, IndexError):
|
||||
print('\nEither the profile does not exist, or it is corrupted.\n')
|
||||
_profile_data = None
|
||||
s_exit()
|
||||
s_exit(1)
|
||||
# extract data from profile
|
||||
_user = _profile_data[0].replace('\n', '')
|
||||
_ip = _profile_data[1].replace('\n', '')
|
||||
|
||||
@@ -125,7 +125,7 @@ def tweak(): # runs configuration wizard
|
||||
copy('/usr/bin/sshync.py', path.expanduser('~/'))
|
||||
copy('/usr/bin/sshypRemote.py', path.expanduser('~/sshypRemote.py'))
|
||||
print('\nMake sure the ssh service is running and properly configured.\n\nConfiguration complete!\n')
|
||||
s_exit()
|
||||
s_exit(0)
|
||||
else:
|
||||
# device type configuration
|
||||
_device_type = 'c' # ensure device type flag is properly set
|
||||
@@ -288,7 +288,7 @@ def sync(): # calls sshync to sync changes to the user's server
|
||||
except (FileNotFoundError, IndexError):
|
||||
print('\nThe deletion database does not exist or is corrupted.\n')
|
||||
_deletion_database = None
|
||||
s_exit()
|
||||
s_exit(1)
|
||||
for _file in _deletion_database:
|
||||
if _file[:-1].endswith('/'):
|
||||
try:
|
||||
@@ -316,7 +316,7 @@ def sync(): # calls sshync to sync changes to the user's server
|
||||
except (FileNotFoundError, IndexError):
|
||||
print('\nThe folder database does not exist or is corrupted.\n')
|
||||
_folder_database = None
|
||||
s_exit()
|
||||
s_exit(1)
|
||||
for _folder in _folder_database:
|
||||
if Path(f"{path.expanduser('~')}{_folder[:-1]}").is_dir():
|
||||
pass
|
||||
@@ -412,7 +412,7 @@ def edit(): # edits the contents of an entry
|
||||
_entry_name = _entry_name.replace('/', '', 1)
|
||||
if not Path(f"{directory}{_entry_name}.gpg").is_file():
|
||||
print("\nYou are trying to edit a file that does not exist!\n")
|
||||
s_exit()
|
||||
s_exit(1)
|
||||
if argument.startswith('edit username') or argument.startswith('edit -u'):
|
||||
_detail = str(input('New Username: '))
|
||||
_shm_folder, _shm_entry = shm_gen()
|
||||
@@ -459,7 +459,7 @@ def gen(): # generates a password for a new or an existing entry
|
||||
if argument.startswith('gen update') or argument.startswith('gen -u'):
|
||||
if not Path(f"{directory}{_entry_name}.gpg").is_file():
|
||||
print("\nYou are trying to edit a file that does not exist!\n")
|
||||
s_exit()
|
||||
s_exit(1)
|
||||
else:
|
||||
_username = str(input('Username: '))
|
||||
_password = pass_gen()
|
||||
@@ -498,7 +498,7 @@ def copy_data(): # copies a specified field of an entry to the clipboard
|
||||
_read_entry = ' '.join(_read_entry)
|
||||
if not Path(f"{directory}{_read_entry}.gpg").is_file():
|
||||
print("\nThe file does not exist!\n")
|
||||
s_exit()
|
||||
s_exit(1)
|
||||
_shm_folder, _shm_entry = shm_gen()
|
||||
system(f"gpg -qd --output {tmp_dir}{_shm_folder}/{_shm_entry} '{directory}{_read_entry}.gpg'")
|
||||
_copy_line = open(f"{tmp_dir}{_shm_folder}/{_shm_entry}", 'r').readlines()
|
||||
@@ -548,7 +548,7 @@ def remove_data(): # deletes an entry from the server and flags it for local de
|
||||
remove(f"{tmp_dir}sshyp.lock")
|
||||
except FileNotFoundError:
|
||||
print('\nAccess denied.\n')
|
||||
s_exit()
|
||||
s_exit(1)
|
||||
system(f"ssh -i '{path.expanduser('~/.ssh/sshyp')}' -p {port} {username_ssh}@{ip} \"python -c 'import sshypRemote"
|
||||
f"; sshypRemote.delete(\"'\"{_entry_name}\"'\")'\"")
|
||||
|
||||
@@ -582,14 +582,14 @@ if __name__ == "__main__":
|
||||
print('\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||||
print("Not all necessary configuration files are present. Please run 'sshyp tweak'!")
|
||||
print('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n')
|
||||
s_exit()
|
||||
s_exit(1)
|
||||
else:
|
||||
try:
|
||||
tweak()
|
||||
s_exit()
|
||||
s_exit(0)
|
||||
except KeyboardInterrupt:
|
||||
print('\n')
|
||||
s_exit()
|
||||
s_exit(0)
|
||||
|
||||
# run function based on argument
|
||||
error = 0 # create an error flag to determine if syncing should occur at end
|
||||
@@ -600,7 +600,7 @@ if __name__ == "__main__":
|
||||
no_arg()
|
||||
except KeyboardInterrupt:
|
||||
print('\n')
|
||||
s_exit()
|
||||
s_exit(0)
|
||||
elif argument == 'help' or argument == '--help' or argument == '-h' or argument == 'license' or \
|
||||
argument == 'version' or argument == '-v' or argument == 'add' or argument == 'edit' or argument == 'copy':
|
||||
print_info()
|
||||
@@ -610,20 +610,20 @@ if __name__ == "__main__":
|
||||
add_entry()
|
||||
except KeyboardInterrupt:
|
||||
print('\n')
|
||||
s_exit()
|
||||
s_exit(0)
|
||||
elif argument.startswith('add folder') or argument.startswith('add -f'):
|
||||
try:
|
||||
add_folder()
|
||||
except KeyboardInterrupt:
|
||||
print('\n')
|
||||
s_exit()
|
||||
s_exit(0)
|
||||
elif argument.startswith('edit rename') or argument.startswith('edit relocate') or argument.startswith('edit -r'):
|
||||
silent_sync = 1
|
||||
try:
|
||||
rename()
|
||||
except KeyboardInterrupt:
|
||||
print('\n')
|
||||
s_exit()
|
||||
s_exit(0)
|
||||
elif argument.startswith('edit username') or argument.startswith('edit -u') or argument.startswith('edit password')\
|
||||
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'):
|
||||
@@ -631,13 +631,13 @@ if __name__ == "__main__":
|
||||
edit()
|
||||
except KeyboardInterrupt:
|
||||
print('\n')
|
||||
s_exit()
|
||||
s_exit(0)
|
||||
elif argument.startswith('gen'):
|
||||
try:
|
||||
gen()
|
||||
except KeyboardInterrupt:
|
||||
print('\n')
|
||||
s_exit()
|
||||
s_exit(0)
|
||||
elif argument.startswith('copy username') or argument.startswith('copy -u') or argument.startswith('copy password')\
|
||||
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'):
|
||||
@@ -645,19 +645,19 @@ if __name__ == "__main__":
|
||||
copy_data()
|
||||
except KeyboardInterrupt:
|
||||
print('\n')
|
||||
s_exit()
|
||||
s_exit(0)
|
||||
elif argument.startswith('shear') or argument.startswith('-rm'):
|
||||
try:
|
||||
remove_data()
|
||||
except KeyboardInterrupt:
|
||||
print('\n')
|
||||
s_exit()
|
||||
s_exit(0)
|
||||
elif argument == 'sync' or argument == '-s':
|
||||
sync()
|
||||
else:
|
||||
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()
|
||||
s_exit(1)
|
||||
|
||||
# sync at end of program if any changes were made
|
||||
if argument != '' and argument != 'help' and argument != '--help' and argument != '-h' and argument != 'license' \
|
||||
|
||||
Reference in New Issue
Block a user