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
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Ophélie Gagnard
slapos.libnetworkcache
Commits
673842a9
Commit
673842a9
authored
Nov 23, 2022
by
Ophélie Gagnard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add identifier for direct URL (don't force md5sum).
parent
c9337a3b
Changes
1
Show 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 @
673842a9
...
...
@@ -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,19 +518,29 @@ def cmd_upload(*args):
else
:
parser
.
error
(
'either --file or --url is required'
)
kw
=
dict
(
x
.
split
(
'='
,
1
)
for
x
in
args
.
meta
)
if
args
.
id
:
kw
.
setdefault
(
'id'
,
args
.
id
)
key
=
args
.
id
else
:
kw
.
setdefault
(
'url'
,
args
.
url
)
urlmd5
=
hashlib
.
md5
(
args
.
url
.
encode
()).
hexdigest
()
nc
.
upload
(
f
,
args
.
prefix_key
+
urlmd5
+
args
.
suffix_key
,
**
kw
)
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
)
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
...
...
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