diff --git a/README.md b/README.md index f259241..753455d 100644 --- a/README.md +++ b/README.md @@ -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" }] } ``` @@ -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 diff --git a/SimpleSync.py b/SimpleSync.py index f5c902b..465058e 100644 --- a/SimpleSync.py +++ b/SimpleSync.py @@ -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) @@ -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='') # @@ -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()