Commit 4dee0c16 by Julien Muchembled

cli: add necessary options to upload a pypi-index file

The commands remain difficult to use. Maybe we should move some slapos.buildout
code here so that the required information can be computed automatically.
1 parent 1fa91b70
......@@ -348,24 +348,26 @@ class NetworkcacheException(Exception):
DirectoryNotFound = UploadError = NetworkcacheException # BBB
def _newArgumentParser():
def _newArgumentParser(url_help):
parser = argparse.ArgumentParser()
parser.add_argument('slapos_config', type=argparse.FileType('r'),
parser.add_argument('--config', type=argparse.FileType('r'), required=True,
help='SlapOS configuration file.')
parser.add_argument('--prefix-key', default='')
parser.add_argument('--suffix-key', default='')
parser.add_argument('--url', required=True, help=url_help
+ " The key will be concatenation of PREFIX_KEY, md5(URL) and SUFFIX_KEY.")
return parser
def cmd_upload(*args):
parser = _newArgumentParser()
parser.add_argument('--prefix-key', default='',
help="Key will be concatenation of PREFIX_KEY and md5(URL).")
parser.add_argument('--url', required=True,
help="Upload data pointed to by this argument, unless --file is specified."
" If argument is not a local path, contents is first downloaded"
" in a temporary file.")
parser = _newArgumentParser("Upload data pointed to by this argument,"
" unless --file is specified. If argument is not a local path, contents"
" is first downloaded in a temporary file.")
parser.add_argument('--file',
help="Upload the contents of this file, overriding --url")
parser.add_argument('meta', nargs='*', metavar='KEY=VALUE',
help="Extra metadata.")
args = parser.parse_args(args or sys.argv[1:])
nc = NetworkcacheClient(args.slapos_config)
nc = NetworkcacheClient(args.config)
f = None
try:
if args.file:
......@@ -375,18 +377,15 @@ def cmd_upload(*args):
else:
f = urllib2.urlopen(args.url)
urlmd5 = hashlib.md5(args.url).hexdigest()
nc.upload(f, args.prefix_key + urlmd5, urlmd5=urlmd5,
file_name=os.path.basename(args.url))
nc.upload(f, args.prefix_key + urlmd5 + args.suffix_key, urlmd5=urlmd5,
file_name=os.path.basename(args.url) or "file",
**dict(x.split('=', 1) for x in args.meta))
finally:
f is None or f.close()
def cmd_download(*args):
parser = _newArgumentParser()
parser.add_argument('--prefix-key', default='',
help="Key will be concatenation of PREFIX_KEY and md5(URL).")
parser.add_argument('--url', required=True,
help="URL of data to download.")
parser = _newArgumentParser("URL of data to download.")
args = parser.parse_args(args or sys.argv[1:])
nc = NetworkcacheClient(args.slapos_config)
key = args.prefix_key + hashlib.md5(args.url).hexdigest()
nc = NetworkcacheClient(args.config)
key = args.prefix_key + hashlib.md5(args.url).hexdigest() + args.suffix_key
shutil.copyfileobj(nc.download(nc.select(key).next()['sha512']), sys.stdout)
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!