summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2014-09-08 18:15:27 -0500
committerAndy Doan <andy.doan@linaro.org>2014-09-10 13:15:20 -0500
commit80036f7796497f884026e8915f7762f2a87ded8d (patch)
treec0e78e0dc96b0b28227298337b8c5a40fcf6acf9
parent2f30f07e59ea53fbcb3b776057bdd588cdef6f69 (diff)
Allow more flexibility with build-info file.
This provides 2 new features: 1) you can specify your own custom build-info file to be used to handle more complex licenses. 2) if a BUILD-INFO.txt file already exists, it will be used rather than the default (or specified build-info file) Change-Id: I023f08056b2ca540a3073fffc92f88a995d9de4e
-rwxr-xr-xlinaro-cp.py39
1 files changed, 23 insertions, 16 deletions
diff --git a/linaro-cp.py b/linaro-cp.py
index 0e23bd6..3dd351c 100755
--- a/linaro-cp.py
+++ b/linaro-cp.py
@@ -1,27 +1,36 @@
#!/usr/bin/env python
import argparse
+import atexit
import cStringIO
import os
import pycurl
import sys
+import tempfile
import time
# Public artifacts BUILD-INFO.txt
build_info = 'Format-Version: 0.5\n\nFiles-Pattern: *\nLicense-Type: open\n'
-def _get_transfer_queue(server_base, src, dst):
+def _get_transfer_queue(server_base, def_build_info, src, dst):
+ if server_base[-1] != '/' and dst[0] != '/':
+ # one of these needs to be a slash to produce a url
+ dst = '/' + dst
+
transfer_queue = {}
src_dir = os.path.abspath(src)
for root, dirs, files in os.walk(src_dir):
+ dst_dir = dst
+ if not root.endswith(dst): # in sub directory
+ dst_dir = os.path.join(dst, root[len(src_dir) + 1:])
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' % (server_base, 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'
+ dst_file = '%s%s/%s' % (server_base, dst_dir, f)
+ transfer_queue[dst_file] = os.path.join(root, f)
+ build_info_file = os.path.join(root, 'BUILD-INFO.txt')
+ if not os.path.exists(build_info_file):
+ dst_file = '%s%s/%s' % (server_base, dst_dir, 'BUILD-INFO.txt')
+ transfer_queue[dst_file] = def_build_info
return transfer_queue
@@ -67,6 +76,7 @@ def main():
parser.add_argument('-k', '--key', help='key used for the copy')
parser.add_argument('--server', default='http://snapshots.linaro.org/',
help='Publishing API server. default=%(default)s')
+ parser.add_argument('-b', '--build-info', help='Custom build-info file')
parser.add_argument('src', help='source file(s) to copy')
parser.add_argument('dst', help='destination to copy the file(s)')
@@ -82,18 +92,15 @@ def main():
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)
+ if not arguments.build_info:
+ fd, arguments.build_info = tempfile.mkstemp(prefix='BUILD-INFO.txt')
+ atexit.register(os.unlink, arguments.build_info)
+ os.write(fd, build_info)
- transfer_queue = _get_transfer_queue(arguments.server, src, dst)
+ transfer_queue = _get_transfer_queue(
+ arguments.server, arguments.build_info, src, dst)
transfer_failures = _upload_transfer_queue(key, transfer_queue)
- # Remove temporary BUILD-INFO.txt file
- os.remove('BUILD-INFO.txt')
-
if len(transfer_failures) > 0:
sys.exit('Failed to transfer:\n %s' % '\n '.join(transfer_failures))