Commit 8a582cc3 authored by Julien Muchembled's avatar Julien Muchembled

Do not require useless metadata

url would be more useful than file+urlmd5
(slapos.buildout will be changed this way)

However, prevent the user from passing empty metadata inadvertently.
Of course, that won't reject dummy information but it's unlikely there's
nothing useful to add.
parent 1130d381
......@@ -330,8 +330,7 @@ class NetworkcacheClient(object):
finally:
f is None or f.close()
def upload(self, file_descriptor, key=None, urlmd5=None, file_name=None,
valid_until=None, architecture=None, **kw):
def upload(self, file_descriptor, key=None, **kw):
''' Upload the file to the server.
If key is None it must only upload to SHACACHE.
Otherwise, it must create a new entry on SHADIR.
......@@ -374,16 +373,9 @@ class NetworkcacheClient(object):
f is None or f.close()
if key is not None:
kw['sha512'] = sha512sum # always update sha512sum
file_name = kw.pop('file', file_name)
if file_name is None or urlmd5 is None:
raise NetworkcacheException(
'file_name and urlmd5 are required for non-generic upload')
if valid_until is not None:
kw['valid-until'] = valid_until
if architecture is not None:
kw['architecture'] = architecture
self.index(key, file=file_name, urlmd5=urlmd5, **kw)
if not kw:
raise NetworkcacheException('metadata should not be empty')
self.index(key, sha512=sha512sum, **kw)
return sha512sum
......@@ -504,15 +496,13 @@ def cmd_upload(*args):
nc.upload(f)
return
elif args.url:
parser.error('either --file or --url is required')
elif os.path.isdir(args.url):
f = nc.archive(args.url)
f = (nc.archive if os.path.isdir(args.url) else urlopen)(args.url)
else:
f = urlopen(args.url)
parser.error('either --file or --url is required')
kw = dict(x.split('=', 1) for x in args.meta)
kw.setdefault('url', args.url)
urlmd5 = hashlib.md5(args.url.encode()).hexdigest()
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))
nc.upload(f, args.prefix_key + urlmd5 + args.suffix_key, **kw)
finally:
f is None or f.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment