From 4443bd116899e3e62bbd3e4ec8e3e767a08b0c9c Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Sun, 20 Mar 2016 12:49:41 +0000 Subject: fix code for tests Change-Id: I5106328eab0c7b472f6e5058787623bd049d1b8c --- gear/worker.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'gear/worker.py') diff --git a/gear/worker.py b/gear/worker.py index 55b4fa4c..222a5297 100644 --- a/gear/worker.py +++ b/gear/worker.py @@ -45,19 +45,25 @@ def upload_files(cache_key, suffixes): print "DEBUG: start upload_files" cache_dir = '/src/cache/artifacts' remote_cache_dir = '/src/cache_server/' - files_to_upload = [os.path.join(cache_dir, cache_key + '.' + suffix) for suffix in suffixes] - with ssh_manager('127.0.0.1', 22, 'root', '/root/gerritbot/gerritbot_rsa') as client: + files_to_upload = [os.path.join(cache_dir, + cache_key + '.' + suffix) + for suffix in suffixes] + with ssh_manager('127.0.0.1', 22, 'root', + '/root/gerritbot/gerritbot_rsa') as client: sftp = client.open_sftp() for single_file in files_to_upload: - remote_dest = os.path.join(remote_cache_dir, os.path.basename(single_file)) - remote_dest_tmp = os.path.join(remote_cache_dir, os.path.basename(single_file) + '.tmp') + remote_dest = os.path.join(remote_cache_dir, + os.path.basename(single_file)) + remote_dest_tmp = os.path.join(remote_cache_dir, + os.path.basename(single_file) + + '.tmp') print "DEBUG: going to upload %s" % single_file print "DEBUG: upload destination %s" % remote_dest try: sftp.stat(remote_dest) print "DEBUG: file already exists" return - except: + except IOError: print "DEBUG: file not found in cache, uploading" sftp.put(single_file, remote_dest_tmp) sftp.rename(remote_dest_tmp, remote_dest) @@ -78,10 +84,12 @@ while True: bg_request['ref'], bg_request['system']) # TODO: There should be another way of doing this. - cmd = ['morph', 'calculate-build-graph', '--quiet', bg_request['repo'], bg_request['ref'], bg_request['system']] + cmd = ['morph', 'calculate-build-graph', '--quiet', + bg_request['repo'], bg_request['ref'], bg_request['system']] p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) output = p.stdout.read() - # TODO: catch errors calculating build-graph here instead of sending the error as build-graph :) + # TODO: catch errors calculating build-graph here instead of sending + # the error as build-graph :) print "DEBUG: finished computing build graph" job.sendWorkComplete(output) elif job.name == "build-artifact": -- cgit v1.2.1