summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFathi Boudra <fathi.boudra@linaro.org>2014-05-22 15:48:00 +0300
committerFathi Boudra <fathi.boudra@linaro.org>2014-05-22 15:48:00 +0300
commit7ae259fc32fdfebb749e0b4f87efc34f5fd1b388 (patch)
tree3d3e9deac1a267eff8ca052c56ee180ac7b1ebed
Add a simple python script used to upload files to snapshots.linaro.org
Signed-off-by: Fathi Boudra <fathi.boudra@linaro.org>
-rwxr-xr-xlinaro-cp.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/linaro-cp.py b/linaro-cp.py
new file mode 100755
index 0000000..63ee420
--- /dev/null
+++ b/linaro-cp.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+
+import argparse
+import cStringIO
+import os
+import pycurl
+import sys
+
+# Snapshots base URL
+snapshots_url = 'http://snapshots.linaro.org/'
+# Public artifacts BUILD-INFO.txt
+build_info = 'Format-Version: 0.5\n\nFiles-Pattern: *\nLicense-Type: open\n'
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ description='Copy file(s) from source to destination')
+ parser.add_argument('-k', '--key', help='key used for the copy')
+ parser.add_argument('src', help='source file(s) to copy')
+ parser.add_argument('dst', help='destination to copy the file(s)')
+
+ arguments = parser.parse_args()
+ src = arguments.src
+ dst = arguments.dst
+ # Publish key is required. Fallback to PUBLISH_KEY environment
+ # variable when it isn't passed as an argument
+ if arguments.key:
+ key = arguments.key
+ else:
+ key = os.environ.get('PUBLISH_KEY')
+ if key is None:
+ sys.exit('Key is not defined.')
+
+ # Write BUILD-INFO.txt file on the filesystem
+ # A better solution is available in PycURL HEAD,
+ # using FORM_BUFFER/FORM_BUFFERPTR
+ with open('BUILD-INFO.txt', 'w') as f:
+ f.write(build_info)
+
+ transfer_queue = {}
+ src_dir = os.path.abspath(src)
+ for root, dirs, files in os.walk(src_dir):
+ for f in files:
+ src_file = os.path.join(root, f)
+ dst_file = os.path.join(root, f)[len(src_dir):]
+ dst_file = '%s%s%s' % (snapshots_url, dst, dst_file)
+ build_info_file = dst_file.replace(f, 'BUILD-INFO.txt')
+ transfer_queue[dst_file] = src_file
+ transfer_queue[build_info_file] = 'BUILD-INFO.txt'
+
+ # Buffer to receive the server response
+ response = cStringIO.StringIO()
+ curl = pycurl.Curl()
+
+ for transfer_item in transfer_queue:
+ send = [
+ ('file', (pycurl.FORM_FILE, transfer_queue[transfer_item])),
+ ('key', (pycurl.FORM_CONTENTS, key)),
+ ]
+ curl.setopt(pycurl.URL, transfer_item)
+ curl.setopt(pycurl.HTTPPOST, send)
+ curl.setopt(pycurl.WRITEFUNCTION, response.write)
+ curl.perform()
+
+ curl.close()
+
+ # Remove temporary BUILD-INFO.txt file
+ os.remove('BUILD-INFO.txt')
+
+
+if __name__ == '__main__':
+ main()