Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.libnetworkcache
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
slapos.libnetworkcache
Commits
aa384e83
Commit
aa384e83
authored
Dec 02, 2022
by
Ophélie Gagnard
Committed by
Julien Muchembled
Mar 26, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upload: Support metadata in json file
parent
5c59ccb1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
slapos/libnetworkcache.py
slapos/libnetworkcache.py
+17
-5
No files found.
slapos/libnetworkcache.py
View file @
aa384e83
...
@@ -502,8 +502,10 @@ def cmd_upload(*args):
...
@@ -502,8 +502,10 @@ def cmd_upload(*args):
help
=
"Upload the contents of this file, overriding --url"
)
help
=
"Upload the contents of this file, overriding --url"
)
parser
.
add_argument
(
'--id'
,
parser
.
add_argument
(
'--id'
,
help
=
"Identifier used for the shadir URL. Overriding --prefix-key, --suffix-key and --url"
)
help
=
"Identifier used for the shadir URL. Overriding --prefix-key, --suffix-key and --url"
)
parser
.
add_argument
(
'--metadata'
,
help
=
"Take a file containing a json-serializable dictionary with shadir metadata."
)
parser
.
add_argument
(
'meta'
,
nargs
=
'*'
,
metavar
=
'KEY=VALUE'
,
parser
.
add_argument
(
'meta'
,
nargs
=
'*'
,
metavar
=
'KEY=VALUE'
,
help
=
"Extra metadata."
)
help
=
"Extra metadata.
Warning: interpreted as string.
"
)
args
=
parser
.
parse_args
(
args
or
sys
.
argv
[
1
:])
args
=
parser
.
parse_args
(
args
or
sys
.
argv
[
1
:])
nc
=
NetworkcacheClient
(
args
.
config
)
nc
=
NetworkcacheClient
(
args
.
config
)
f
=
None
f
=
None
...
@@ -517,15 +519,25 @@ def cmd_upload(*args):
...
@@ -517,15 +519,25 @@ def cmd_upload(*args):
f
=
(
nc
.
archive
if
os
.
path
.
isdir
(
args
.
url
)
else
urlopen
)(
args
.
url
)
f
=
(
nc
.
archive
if
os
.
path
.
isdir
(
args
.
url
)
else
urlopen
)(
args
.
url
)
else
:
else
:
parser
.
error
(
'either --file or --url is required'
)
parser
.
error
(
'either --file or --url is required'
)
kw
=
dict
(
x
.
split
(
'='
,
1
)
for
x
in
args
.
meta
)
if
args
.
metadata
:
with
open
(
args
.
metadata
)
as
g
:
try
:
metadata_dict
=
json
.
loads
(
g
.
read
())
if
type
(
metadata_dict
)
!=
dict
:
raise
NetworkcacheException
(
"Not a json-serializable dictionary: %s"
%
args
.
metadata
)
except
json
.
decoder
.
JSONDecodeError
:
raise
NetworkcacheException
(
"Invalid json in %s"
%
args
.
metadata
)
else
:
metadata_dict
=
dict
()
metadata_dict
.
update
(
dict
(
x
.
split
(
'='
,
1
)
for
x
in
args
.
meta
))
if
args
.
id
:
if
args
.
id
:
kw
.
setdefault
(
'id'
,
args
.
id
)
metadata_dict
.
setdefault
(
'id'
,
args
.
id
)
key
=
args
.
id
key
=
args
.
id
else
:
else
:
kw
.
setdefault
(
'url'
,
args
.
url
)
metadata_dict
.
setdefault
(
'url'
,
args
.
url
)
urlmd5
=
hashlib
.
md5
(
args
.
url
.
encode
()).
hexdigest
()
urlmd5
=
hashlib
.
md5
(
args
.
url
.
encode
()).
hexdigest
()
key
=
args
.
prefix_key
+
urlmd5
+
args
.
suffix_key
key
=
args
.
prefix_key
+
urlmd5
+
args
.
suffix_key
nc
.
upload
(
f
,
key
,
**
kw
)
nc
.
upload
(
f
,
key
,
**
metadata_dict
)
finally
:
finally
:
f
is
None
or
f
.
close
()
f
is
None
or
f
.
close
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment