Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for identity files. #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ Sample settings:
``` javascript
{
"sync": [{
"type" : "ssh",
"host" : "tnhu-ld",
"port" : "22",
"username" : "tnhu",
"local" : "/Users/tnhu/workspace/trunk",
"remote" : "/home/tnhu/workspace/trunk"
"type" : "ssh",
"host" : "tnhu-ld",
"port" : "22",
"username" : "tnhu",
"local" : "/Users/tnhu/workspace/trunk",
"remote" : "/home/tnhu/workspace/trunk",
"identity_file" : "/Users/tnhu/.ssh/optional_rsa"
}, {
"type" : "local",
"local" : "/Users/tnhu/Library/Application Support/Sublime Text 2/Packages/SimpleSync",
"remote" : "/Users/tnhu/Dropbox/projects/SimpleSync"
"type" : "local",
"local" : "/Users/tnhu/Library/Application Support/Sublime Text 2/Packages/SimpleSync",
"remote" : "/Users/tnhu/Dropbox/projects/SimpleSync"
}]
}
```
Expand All @@ -60,6 +61,7 @@ Files are saved to remote server automatically when you save them locally. In ca

* [tnhu](https://github.com/tnhu)
* [gfreezy](https://github.com/gfreezy)
* [dbtlr](https://github.com/dbtlr)

## License

Expand Down
30 changes: 22 additions & 8 deletions SimpleSync.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ def getSyncItem(local_file):
# ScpCopier does actual copying using threading to avoid UI blocking
#
class ScpCopier(threading.Thread):
def __init__(self, host, username, local_file, remote_file, port=22):
self.host = host
self.port = port
self.username = username
self.local_file = local_file
self.remote_file = remote_file
def __init__(self, host, username, local_file, remote_file, port=22, identity_file=None):
self.host = host
self.port = port
self.username = username
self.local_file = local_file
self.remote_file = remote_file
self.identity_file = identity_file

threading.Thread.__init__(self)

Expand All @@ -66,7 +67,16 @@ def run(self):

print("SimpleSync: ", self.local_file, " -> ", remote)

for line in runProcess(["scp", "-r", "-P", str(self.port) , self.local_file, remote]):
process_options = ["scp", "-r", "-P", str(self.port)]

if self.identity_file:
process_options.append("-i")
process_options.append(self.identity_file)

process_options.append(self.local_file)
process_options.append(remote)

for line in runProcess(process_options):
print(line, end='')

#
Expand Down Expand Up @@ -97,6 +107,10 @@ def on_post_save(self, view):
remote_file = local_file.replace(item["local"], item["remote"])

if (item["type"] == "ssh"):
ScpCopier(item["host"], item["username"], local_file, remote_file, port=item["port"]).start()
identity_file = None
if "identity_file" in item:
identity_file = item["identity_file"]

ScpCopier(item["host"], item["username"], local_file, remote_file, port=item["port"], identity_file=identity_file).start()
elif (item["type"] == "local"):
LocalCopier(local_file, remote_file).start()