mirror of
https://github.com/rwinkhart/sshyp.git
synced 2026-08-30 13:56:31 -04:00
Moved comments to dedicated lines for easier port-job removal
Former-commit-id: 674876366fda7898f6723a7aa255b4785d2b5cdd Former-commit-id: dc0213e06fbc2bceedf7cc8d7bcc7d8737f795d8
This commit is contained in:
+24
-13
@@ -8,7 +8,8 @@ home = expanduser("~")
|
||||
|
||||
# REMOTE
|
||||
|
||||
def remote_list_gen(_client_device_name, _remote_dir): # prints all necessary remote data to stdout
|
||||
# prints all necessary remote data to stdout
|
||||
def remote_list_gen(_client_device_name, _remote_dir):
|
||||
# deletions
|
||||
for _file in listdir(f"{home}/.config/sshyp/deleted"):
|
||||
_file_path, _sep, _device = _file.partition('\x1f')
|
||||
@@ -25,12 +26,14 @@ def remote_list_gen(_client_device_name, _remote_dir): # prints all necessary r
|
||||
for _dir in _directories:
|
||||
print(f"{_root.replace(home, '')}/{_dir}")
|
||||
print('\x1d')
|
||||
get_local_data(_remote_dir, 'server') # titles and mod times
|
||||
# titles and mod times
|
||||
get_local_data(_remote_dir, 'server')
|
||||
|
||||
|
||||
# HYBRID
|
||||
|
||||
def delete(_file_path, _target_database): # deletes a file or folder and/or marks it for deletion upon syncing
|
||||
# deletes a file or folder and/or marks it for deletion upon syncing
|
||||
def delete(_file_path, _target_database):
|
||||
from shutil import rmtree
|
||||
_directory = f"{home}/.local/share/sshyp/"
|
||||
try:
|
||||
@@ -45,7 +48,8 @@ def delete(_file_path, _target_database): # deletes a file or folder and/or mar
|
||||
open(f"{home}/.config/sshyp/deleted/" + _file_path.replace('/', '\x1e') + '\x1f' + _device_name, 'w')
|
||||
|
||||
|
||||
def get_local_data(_directory, _device): # retrieves and returns titles and mod times from the local device
|
||||
# retrieves and returns titles and mod times from the local device
|
||||
def get_local_data(_directory, _device):
|
||||
_title_list, _mod_list = [], []
|
||||
for _root, _directories, _files in walk(_directory):
|
||||
for _filename in _files:
|
||||
@@ -61,7 +65,8 @@ def get_local_data(_directory, _device): # retrieves and returns titles and mod
|
||||
|
||||
# LOCAL
|
||||
|
||||
def remote_list_fetch(_user_data): # captures and returns all necessary data from the remote server
|
||||
# captures and returns all necessary data from the remote server
|
||||
def remote_list_fetch(_user_data):
|
||||
try:
|
||||
_remote_data = run(['ssh', '-i', _user_data[5], '-p', _user_data[2], f"{_user_data[0]}@{_user_data[1]}",
|
||||
f'cd /lib/sshyp; python3 -c \'from sshync import remote_list_gen; remote_list_gen'
|
||||
@@ -78,7 +83,8 @@ def remote_list_fetch(_user_data): # captures and returns all necessary data fr
|
||||
_titles_mods[len(_titles_mods)//2:]
|
||||
|
||||
|
||||
def deletion_sync(_deletion_database, _silent): # checks for and acts upon files and folders marked for deletion
|
||||
# checks for and acts upon files and folders marked for deletion
|
||||
def deletion_sync(_deletion_database, _silent):
|
||||
for _file in _deletion_database:
|
||||
if _file != '':
|
||||
if not _silent:
|
||||
@@ -86,7 +92,8 @@ def deletion_sync(_deletion_database, _silent): # checks for and acts upon file
|
||||
delete(_file, 'locally')
|
||||
|
||||
|
||||
def folder_sync(_folder_database): # creates matches of remote folders on the local client
|
||||
# creates matches of remote folders on the local client
|
||||
def folder_sync(_folder_database):
|
||||
from pathlib import Path
|
||||
for _folder in _folder_database:
|
||||
if _folder != '' and not isdir(home + _folder):
|
||||
@@ -95,8 +102,8 @@ def folder_sync(_folder_database): # creates matches of remote folders on the l
|
||||
Path(home + _folder).mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||
|
||||
|
||||
def sort_titles_mods(_list_1, _list_2): # creates and returns two lists (of titles and mod times) generated by sorting
|
||||
# information from two provided 2D lists
|
||||
# creates and returns two lists (of titles and mod times) generated by sorting information from two provided 2D lists
|
||||
def sort_titles_mods(_list_1, _list_2):
|
||||
_title_list_2_sorted, _mod_list_2_sorted = [], []
|
||||
# title sorting
|
||||
for _title in _list_1[0]:
|
||||
@@ -111,11 +118,13 @@ def sort_titles_mods(_list_1, _list_2): # creates and returns two lists (of tit
|
||||
return _title_list_2_sorted, _mod_list_2_sorted
|
||||
|
||||
|
||||
def make_profile(_profile_dir, _local_dir, _remote_dir, _identity, _ip, _port, _user): # creates a sshync job profile
|
||||
# creates a sshync job profile
|
||||
def make_profile(_profile_dir, _local_dir, _remote_dir, _identity, _ip, _port, _user):
|
||||
open(_profile_dir, 'w').write(f"{_user}\n{_ip}\n{_port}\n{_local_dir}\n{_remote_dir}\n{_identity}\n")
|
||||
|
||||
|
||||
def get_profile(_profile_dir): # returns a list of data read from a sshync job profile
|
||||
# returns a list of data read from a sshync job profile
|
||||
def get_profile(_profile_dir):
|
||||
try:
|
||||
_profile_data = open(_profile_dir).readlines()
|
||||
except (FileNotFoundError, IndexError):
|
||||
@@ -132,8 +141,10 @@ def get_profile(_profile_dir): # returns a list of data read from a sshync job
|
||||
return _user, _ip, _port, _local_dir, _remote_dir, _identity, _client_device_id
|
||||
|
||||
|
||||
def run_profile(_profile_dir, _silent): # runs a sshync job profile
|
||||
_user_data = get_profile(_profile_dir) # import profile data
|
||||
# runs a sshync job profile
|
||||
def run_profile(_profile_dir, _silent):
|
||||
# import profile data
|
||||
_user_data = get_profile(_profile_dir)
|
||||
# fetch remote lists
|
||||
_deletion_database, _folder_database, _remote_titles, _remote_mods = remote_list_fetch(_user_data)
|
||||
_remote_titles_mods = (_remote_titles, _remote_mods)
|
||||
|
||||
Reference in New Issue
Block a user