diff options
author | Paul Sokolovsky <paul.sokolovsky@linaro.org> | 2013-04-17 00:34:56 +0300 |
---|---|---|
committer | Paul Sokolovsky <paul.sokolovsky@linaro.org> | 2013-04-17 00:34:56 +0300 |
commit | 1f92eb45236affb1e0d4a82a1f8d159c6c69fdf6 (patch) | |
tree | a9dfbc47c69e69be9fdbc9e499da88ce0ae3b845 /utils | |
parent | 351a5a1f4cc2be3bba917b0ff673fbf2c1fbc3bc (diff) |
Factor out func to perform SFTP upload, for reuse.
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/new-publish/publish.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/utils/new-publish/publish.py b/utils/new-publish/publish.py index 4e27279..459f86a 100755 --- a/utils/new-publish/publish.py +++ b/utils/new-publish/publish.py @@ -70,7 +70,7 @@ def create_dir_struct(dir_list, host, user, key): sftp.mkdir(d, 0755) -def upload_files(file_list, dir="", strip=0): +def make_upload_script(file_list, dir="", strip=0): script = [] # if dir and dir[0] != "/": # dir = "/" + dir @@ -88,6 +88,19 @@ def upload_files(file_list, dir="", strip=0): return script +def upload_files(upload_script, host, user, key, options): + with open("/tmp/sftp.script", "w") as f: + f.write("\n".join(upload_script) + "\n") + + cmd = "sftp -v -i %s -b /tmp/sftp.script %s@%s" % (key, user, host) + print cmd + sys.stdout.flush() + if not options.dry_run: + if os.system(cmd) != 0: + print "ERROR: sftp transfer finished with error" + sys.exit(1) + + if __name__ == "__main__": optparser = optparse.OptionParser(usage="%prog") optparser.add_option("-d", "--dest-dir", metavar="DIR", help="Destination directory") @@ -111,14 +124,5 @@ if __name__ == "__main__": dir_list = make_dir_struct(file_list, options.dest_dir, options.strip) print "Dir list:", dir_list create_dir_struct(dir_list, REMOTE_HOST, USER_NAME, options.identity) - upload_script = upload_files(file_list, options.dest_dir, options.strip) - with open("/tmp/sftp.script", "w") as f: - f.write("\n".join(upload_script) + "\n") - - cmd = "sftp -v -i %s -b /tmp/sftp.script %s@%s" % (options.identity, USER_NAME, REMOTE_HOST) - print cmd - sys.stdout.flush() - if not options.dry_run: - if os.system(cmd) != 0: - print "ERROR: sftp transfer finished with error" - sys.exit(1) + upload_script = make_upload_script(file_list, options.dest_dir, options.strip) + upload_files(upload_script, REMOTE_HOST, USER_NAME, options.identity, options) |