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
c0b9a92e
Commit
c0b9a92e
authored
Nov 23, 2022
by
Ophélie Gagnard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New --id command-line option for download & upload
parent
c9337a3b
Pipeline
#24986
passed with stage
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
8 deletions
+22
-8
slapos/libnetworkcache.py
slapos/libnetworkcache.py
+22
-8
No files found.
slapos/libnetworkcache.py
View file @
c0b9a92e
...
...
@@ -486,8 +486,10 @@ def _newArgumentParser(url_help):
parser
=
argparse
.
ArgumentParser
()
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
(
'--prefix-key'
,
default
=
''
,
help
=
"Prefix used for the shadir URL, not a cryptografic key."
)
parser
.
add_argument
(
'--suffix-key'
,
default
=
''
,
help
=
"Suffix used for the shadir URL, not a cryptografic key."
)
parser
.
add_argument
(
'--url'
,
help
=
url_help
)
return
parser
...
...
@@ -498,6 +500,8 @@ def cmd_upload(*args):
"%s If not given, the uploaded data is not indexed."
%
key_help
)
parser
.
add_argument
(
'--file'
,
help
=
"Upload the contents of this file, overriding --url"
)
parser
.
add_argument
(
'--id'
,
help
=
"Identifier used for the shadir URL. Overriding --prefix-key, --suffix-key and --url"
)
parser
.
add_argument
(
'meta'
,
nargs
=
'*'
,
metavar
=
'KEY=VALUE'
,
help
=
"Extra metadata."
)
args
=
parser
.
parse_args
(
args
or
sys
.
argv
[
1
:])
...
...
@@ -506,7 +510,7 @@ def cmd_upload(*args):
try
:
if
args
.
file
:
f
=
open
(
args
.
file
,
'rb'
)
if
not
args
.
url
:
if
not
args
.
url
and
not
args
.
id
:
nc
.
upload
(
f
)
return
elif
args
.
url
:
...
...
@@ -514,21 +518,31 @@ def cmd_upload(*args):
else
:
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
,
**
kw
)
if
args
.
id
:
kw
.
setdefault
(
'id'
,
args
.
id
)
key
=
args
.
id
else
:
kw
.
setdefault
(
'url'
,
args
.
url
)
urlmd5
=
hashlib
.
md5
(
args
.
url
.
encode
()).
hexdigest
()
key
=
args
.
prefix_key
+
urlmd5
+
args
.
suffix_key
nc
.
upload
(
f
,
key
,
**
kw
)
finally
:
f
is
None
or
f
.
close
()
def
cmd_download
(
*
args
):
parser
=
_newArgumentParser
(
"URL of data to download."
+
key_help
)
parser
.
add_argument
(
'--id'
,
help
=
"Identifier of the shadir URL, overriding --prefix-key and --suffix-key."
)
parser
.
add_argument
(
'meta'
,
nargs
=
'*'
,
metavar
=
'KEY=VALUE'
,
help
=
"Extra metadata."
)
args
=
parser
.
parse_args
(
args
or
sys
.
argv
[
1
:])
nc
=
NetworkcacheClient
(
args
.
config
)
kw
=
dict
(
x
.
split
(
'='
,
1
)
for
x
in
args
.
meta
)
urlmd5
=
hashlib
.
md5
(
args
.
url
.
encode
()).
hexdigest
()
key
=
args
.
prefix_key
+
urlmd5
+
args
.
suffix_key
if
args
.
id
:
key
=
args
.
id
else
:
urlmd5
=
hashlib
.
md5
(
args
.
url
.
encode
()).
hexdigest
()
key
=
args
.
prefix_key
+
urlmd5
+
args
.
suffix_key
f
=
sys
.
stdout
shutil
.
copyfileobj
(
nc
.
download
(
next
(
nc
.
select
(
key
,
kw
))[
'sha512'
]),
getattr
(
f
,
'buffer'
,
f
))
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