diff --git a/icinga-build-upload-aptly b/icinga-build-upload-aptly index 51d7442ae713128b93bc543e85f4654e0f2e4058..594b635ad720b3b3ebaab7e0cb7fcc64a9dcafbd 100755 --- a/icinga-build-upload-aptly +++ b/icinga-build-upload-aptly @@ -1,6 +1,8 @@ #!/usr/bin/env python -import sys, os +import sys +import os +import os.path import argparse import fnmatch from hashlib import sha1 @@ -69,7 +71,8 @@ def upload_checksum(files): h = sha1() d = dict() for file in files: - d[file] = fh = sha1_file(file) + name = os.path.basename(file) + d[name] = fh = sha1_file(file) h.update(fh) return (h.hexdigest(), d) @@ -152,7 +155,7 @@ def aptly_url(url): parser = argparse.ArgumentParser(description='Uploading build results to an Aptly server') parser.add_argument('--server', help='APTLY API service to talk to (e.g. http://127.0.0.1:8080/api)', - default=os.environ.get('APTLY_SERVER'), metavar='APTLY_SERVER') + default=os.environ.get('APTLY_SERVER', 'http://127.0.0.1:8080/api'), metavar='APTLY_SERVER') parser.add_argument('--username', help='APTLY API username', default=os.environ.get('APTLY_USERNAME'), metavar='APTLY_USERNAME') parser.add_argument('--password', help='APTLY API password', @@ -170,9 +173,11 @@ parser.add_argument('--architectures', metavar='list', help=('Specify list of architectures to publish the repo with,' 'separated by comma (e.g. amd64,i386 or armhf)')) parser.add_argument('--insecure', action='store_true', help='Disable SSL verification') +parser.add_argument('--noop', action='store_true', help='Only prepare upload') + args = parser.parse_args() -if not args.server: +if not args.server and not args.noop: raise StandardError, "Specifying an aptly server is required (--server or APTLY_SERVER)" if not os.path.exists(args.result): @@ -233,6 +238,14 @@ if args.architectures: if 'amd64' in upload_meta['architectures'] and not 'i386' in upload_meta['architectures']: upload_meta['architectures'].append('i386') +print "Prepared upload to: %s" % (aptly_url('/files/' + upload_name)) +print "Metadata is:" + json.dumps(upload_meta, sort_keys=True, indent=4) +print + +if args.noop: + print "Running in noop mode, stopping here!" + sys.exit(0) + # ensure target is absent r = aptly_session().delete(aptly_url('/files/' + upload_name)) if r.status_code == requests.codes.ok: