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): ...@@ -330,8 +330,7 @@ class NetworkcacheClient(object):
finally: finally:
f is None or f.close() f is None or f.close()
def upload(self, file_descriptor, key=None, urlmd5=None, file_name=None, def upload(self, file_descriptor, key=None, **kw):
valid_until=None, architecture=None, **kw):
''' Upload the file to the server. ''' Upload the file to the server.
If key is None it must only upload to SHACACHE. If key is None it must only upload to SHACACHE.
Otherwise, it must create a new entry on SHADIR. Otherwise, it must create a new entry on SHADIR.
...@@ -374,16 +373,9 @@ class NetworkcacheClient(object): ...@@ -374,16 +373,9 @@ class NetworkcacheClient(object):
f is None or f.close() f is None or f.close()
if key is not None: if key is not None:
kw['sha512'] = sha512sum # always update sha512sum if not kw:
file_name = kw.pop('file', file_name) raise NetworkcacheException('metadata should not be empty')
if file_name is None or urlmd5 is None: self.index(key, sha512=sha512sum, **kw)
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)
return sha512sum return sha512sum
...@@ -504,15 +496,13 @@ def cmd_upload(*args): ...@@ -504,15 +496,13 @@ def cmd_upload(*args):
nc.upload(f) nc.upload(f)
return return
elif args.url: elif args.url:
parser.error('either --file or --url is required') f = (nc.archive if os.path.isdir(args.url) else urlopen)(args.url)
elif os.path.isdir(args.url):
f = nc.archive(args.url)
else: 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() urlmd5 = hashlib.md5(args.url.encode()).hexdigest()
nc.upload(f, args.prefix_key + urlmd5 + args.suffix_key, urlmd5=urlmd5, nc.upload(f, args.prefix_key + urlmd5 + args.suffix_key, **kw)
file_name=os.path.basename(args.url) or "file",
**dict(x.split('=', 1) for x in args.meta))
finally: finally:
f is None or f.close() 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