summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Hesketh <josh@nitrotech.org>2014-01-22 14:53:17 +1100
committerJoshua Hesketh <josh@nitrotech.org>2014-01-22 14:53:17 +1100
commit7859fde57f53936f6a973f07687c9040f6e1e06d (patch)
treee58060d50c16f8fee3e1436cca6b1614e3e9c36e
parentf0c5519f33d2a58b4de418746cbdee47f37eb675 (diff)
downloadturbo-hipster-7859fde57f53936f6a973f07687c9040f6e1e06d.tar.gz
Make the push files utils handle recursing dirs
Change-Id: I45daa1d5771e380f0c251f380fae7a0780e6cbaf
-rw-r--r--turbo_hipster/lib/utils.py39
1 files changed, 27 insertions, 12 deletions
diff --git a/turbo_hipster/lib/utils.py b/turbo_hipster/lib/utils.py
index 424baab..4a012ae 100644
--- a/turbo_hipster/lib/utils.py
+++ b/turbo_hipster/lib/utils.py
@@ -207,17 +207,28 @@ def push_file(job_log_dir, file_path, publish_config):
def swift_push_file(job_log_dir, file_path, swift_config):
""" Push a log file to a swift server. """
- with open(file_path, 'r') as fd:
- name = os.path.join(job_log_dir, os.path.basename(file_path))
- con = swiftclient.client.Connection(
- authurl=swift_config['authurl'],
- user=swift_config['user'],
- key=swift_config['password'],
- os_options={'region_name': swift_config['region']},
- tenant_name=swift_config['tenant'],
- auth_version=2.0)
- con.put_object(swift_config['container'], name, fd)
- return swift_config['prepend_url'] + name
+ def _push_individual_file(job_log_dir, file_path, swift_config):
+ with open(file_path, 'r') as fd:
+ name = os.path.join(job_log_dir, os.path.basename(file_path))
+ con = swiftclient.client.Connection(
+ authurl=swift_config['authurl'],
+ user=swift_config['user'],
+ key=swift_config['password'],
+ os_options={'region_name': swift_config['region']},
+ tenant_name=swift_config['tenant'],
+ auth_version=2.0)
+ con.put_object(swift_config['container'], name, fd)
+
+ if os.path.isfile(file_path):
+ _push_individual_file(job_log_dir, file_path, swift_config)
+ elif os.path.isdir(file_path):
+ for path, folders, files in os.walk(file_path):
+ for f in files:
+ f_path = os.path.join(path, f)
+ _push_individual_file(job_log_dir, f_path, swift_config)
+
+ return (swift_config['prepend_url'] +
+ os.path.join(job_log_dir, os.path.basename(file_path)))
def local_push_file(job_log_dir, file_path, local_config):
@@ -229,13 +240,17 @@ def local_push_file(job_log_dir, file_path, local_config):
dest_file = os.path.join(dest_dir, dest_filename)
- shutil.copyfile(file_path, dest_file)
+ if os.path.isfile(file_path):
+ shutil.copyfile(file_path, dest_file)
+ elif os.path.isdir(file_path):
+ shutil.copytree(file_path, dest_file)
return local_config['prepend_url'] + os.path.join(job_log_dir,
dest_filename)
def scp_push_file(job_log_dir, file_path, local_config):
""" Copy the file remotely over ssh """
+ # TODO!
pass