bug 455578: make sure upload.py always cleans up after itself. r=ted

This commit is contained in:
Ben Hearsum 2009-01-07 08:52:20 -05:00
Родитель 53e7324549
Коммит 4a974e30aa
1 изменённых файлов: 24 добавлений и 18 удалений

Просмотреть файл

@ -162,24 +162,30 @@ def UploadFiles(user, host, path, files, verbose=False, port=None, ssh_key=None,
if base_path is not None: if base_path is not None:
base_path = os.path.abspath(base_path) base_path = os.path.abspath(base_path)
remote_files = [] remote_files = []
for file in files: try:
file = os.path.abspath(file) for file in files:
if not os.path.isfile(file): file = os.path.abspath(file)
raise IOError("File not found: %s" % file) if not os.path.isfile(file):
# first ensure that path exists remotely raise IOError("File not found: %s" % file)
remote_path = GetRemotePath(path, file, base_path) # first ensure that path exists remotely
DoSSHCommand("mkdir -p " + remote_path, user, host, port=port, ssh_key=ssh_key) remote_path = GetRemotePath(path, file, base_path)
if verbose: DoSSHCommand("mkdir -p " + remote_path, user, host, port=port, ssh_key=ssh_key)
print "Uploading " + file if verbose:
DoSCPFile(file, remote_path, user, host, port=port, ssh_key=ssh_key) print "Uploading " + file
remote_files.append(remote_path + '/' + os.path.basename(file)) DoSCPFile(file, remote_path, user, host, port=port, ssh_key=ssh_key)
if post_upload_command is not None: remote_files.append(remote_path + '/' + os.path.basename(file))
if verbose: if post_upload_command is not None:
print "Running post-upload command: " + post_upload_command if verbose:
file_list = '"' + '" "'.join(remote_files) + '"' print "Running post-upload command: " + post_upload_command
DoSSHCommand('%s "%s" %s' % (post_upload_command, path, file_list), user, host, port=port, ssh_key=ssh_key) file_list = '"' + '" "'.join(remote_files) + '"'
if upload_to_temp_dir: DoSSHCommand('%s "%s" %s' % (post_upload_command, path, file_list), user, host, port=port, ssh_key=ssh_key)
DoSSHCommand("rm -rf %s" % path, user, host, port=port, ssh_key=ssh_key) except:
print "Encountered error while uploading"
raise
finally:
if upload_to_temp_dir:
DoSSHCommand("rm -rf %s" % path, user, host, port=port,
ssh_key=ssh_key)
if verbose: if verbose:
print "Upload complete" print "Upload complete"