Package: btssh
OverviewThis module was inspired by theSFTP for Sublime Textplugin.As such, it facilitates interacting with remote hosts via ssh,with the added bonus of providing a means to mirror your localworking directory to the specified path on the remote host in orderto facilitate local-edit/remote-build.With this module you can:Edit and manipulate your scripts locally and execute them remotely,with file synchronization capabilitiesMap a local folder to a remote folderPrerequisites:Python 3.7+paramikoIf working with git repos, the module requires that git be installed locally and remotelyInstallationFrom pypi:pip3 install bertdotsshFrom this git repo:pip3 install git+https://github.com/berttejeda/bert.sshutil.gitNote: To install a specific version of the library from this git repo,suffix the git URL in the above command with @{ tag name }, e.g.:git+https://github.com/berttejeda/bert.sshutil.git@1.0.0Usage ExamplesGet process status for a remote host via sshfrombertdotssh.providerimportRemoteCLIProvidersettings={'host':'myhost.example.local','remote_path':'/home/myusername','port':22,'ssh_key_file':'~/.ssh/id_rsa','user':'myusername'}remote=RemoteCLIProvider(settings)remote.run('ps')Syncronize local files to remote and run a local script against the same hostGiven:Local working directory: /home/myusername/some/pathLocal script: myscript.shfrombertdotssh.providerimportRemoteCLIProvidersettings={'host':'myhost.example.local','remote_path':'/home/myusername','port':22,'ssh_key_file':'~/.ssh/id_rsa','user':'myusername','sync_no_clobber':True,'sync_on':True}remote=RemoteCLIProvider(settings)remote.run('myscript.sh')Syncronize local git repo to remote and run a local script against the same hostGiven:Local working directory (a git repo) at: /home/myusername/some/git/myrepoLocal script at: /home/myusername/some/git/myrepo/myscript.shGit repo on remote host at: /home/myusername/some/other/path/git/myrepofrombertdotssh.providerimportRemoteCLIProvidersettings={'host':'myhost.example.local','remote_path':'/home/myusername/some/other/path/git/myrepo','port':22,'ssh_key_file':'~/.ssh/id_rsa','user':'myusername','sync_no_clobber':True,'sync_on':True}remote=RemoteCLIProvider(settings)remote.run('myscript.sh',git_username='my_git_username',git_password='my_git_password')File syncrhonization behaviorThe above example scenarios exhibit the following programmatic behavior upon sync:Determine if local working directory is a git repoIf TrueDetermine the URL for the git remote via commandgit config --get remote.origin.urlDetermine the paths for any locally changed files via commandgit diff-index HEAD --name-statusDetermine the paths for any untracked files via commandgit ls-files --others --exclude-standardProduce a list of files to sync by combining the output of the above two commandsIf FalseProduce a list of files to sync that have changed within the last 5 minutesDetermine if remote path existsIf FalseIf local is a git repoPerform a git clone of the git repo against the remote pathElse, create the remote directory and synchronize the file list across the remoteIf True, determines if remote path is a git repoDetermine set of files that have changed in the remote pathIf True & sync_no_clobber == True, synchronize locally changedfiles to remote path, skipping any files that have also changed on the remoteIf True & sync_no_clobber == False, synchronize locally changedfiles to remote path, overwriting any files that have also changed on the remote