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
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 @
673842a9
...
@@ -486,8 +486,10 @@ def _newArgumentParser(url_help):
...
@@ -486,8 +486,10 @@ def _newArgumentParser(url_help):
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'--config'
,
type
=
argparse
.
FileType
(
'r'
),
required
=
True
,
parser
.
add_argument
(
'--config'
,
type
=
argparse
.
FileType
(
'r'
),
required
=
True
,
help
=
'SlapOS configuration file.'
)
help
=
'SlapOS configuration file.'
)
parser
.
add_argument
(
'--prefix-key'
,
default
=
''
)
parser
.
add_argument
(
'--prefix-key'
,
default
=
''
,
parser
.
add_argument
(
'--suffix-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
)
parser
.
add_argument
(
'--url'
,
help
=
url_help
)
return
parser
return
parser
...
@@ -498,6 +500,8 @@ def cmd_upload(*args):
...
@@ -498,6 +500,8 @@ def cmd_upload(*args):
"%s If not given, the uploaded data is not indexed."
%
key_help
)
"%s If not given, the uploaded data is not indexed."
%
key_help
)
parser
.
add_argument
(
'--file'
,
parser
.
add_argument
(
'--file'
,
help
=
"Upload the contents of this file, overriding --url"
)
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'
,
parser
.
add_argument
(
'meta'
,
nargs
=
'*'
,
metavar
=
'KEY=VALUE'
,
help
=
"Extra metadata."
)
help
=
"Extra metadata."
)
args
=
parser
.
parse_args
(
args
or
sys
.
argv
[
1
:])
args
=
parser
.
parse_args
(
args
or
sys
.
argv
[
1
:])
...
@@ -506,7 +510,7 @@ def cmd_upload(*args):
...
@@ -506,7 +510,7 @@ def cmd_upload(*args):
try
:
try
:
if
args
.
file
:
if
args
.
file
:
f
=
open
(
args
.
file
,
'rb'
)
f
=
open
(
args
.
file
,
'rb'
)
if
not
args
.
url
:
if
not
args
.
url
and
not
args
.
id
:
nc
.
upload
(
f
)
nc
.
upload
(
f
)
return
return
elif
args
.
url
:
elif
args
.
url
:
...
@@ -514,21 +518,31 @@ def cmd_upload(*args):
...
@@ -514,21 +518,31 @@ def cmd_upload(*args):
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
)
kw
=
dict
(
x
.
split
(
'='
,
1
)
for
x
in
args
.
meta
)
kw
.
setdefault
(
'url'
,
args
.
url
)
if
args
.
id
:
urlmd5
=
hashlib
.
md5
(
args
.
url
.
encode
()).
hexdigest
()
kw
.
setdefault
(
'id'
,
args
.
id
)
nc
.
upload
(
f
,
args
.
prefix_key
+
urlmd5
+
args
.
suffix_key
,
**
kw
)
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
:
finally
:
f
is
None
or
f
.
close
()
f
is
None
or
f
.
close
()
def
cmd_download
(
*
args
):
def
cmd_download
(
*
args
):
parser
=
_newArgumentParser
(
"URL of data to download."
+
key_help
)
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'
,
parser
.
add_argument
(
'meta'
,
nargs
=
'*'
,
metavar
=
'KEY=VALUE'
,
help
=
"Extra metadata."
)
help
=
"Extra metadata."
)
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
)
kw
=
dict
(
x
.
split
(
'='
,
1
)
for
x
in
args
.
meta
)
kw
=
dict
(
x
.
split
(
'='
,
1
)
for
x
in
args
.
meta
)
urlmd5
=
hashlib
.
md5
(
args
.
url
.
encode
()).
hexdigest
()
if
args
.
id
:
key
=
args
.
prefix_key
+
urlmd5
+
args
.
suffix_key
key
=
args
.
id
else
:
urlmd5
=
hashlib
.
md5
(
args
.
url
.
encode
()).
hexdigest
()
key
=
args
.
prefix_key
+
urlmd5
+
args
.
suffix_key
f
=
sys
.
stdout
f
=
sys
.
stdout
shutil
.
copyfileobj
(
nc
.
download
(
next
(
nc
.
select
(
key
,
kw
))[
'sha512'
]),
shutil
.
copyfileobj
(
nc
.
download
(
next
(
nc
.
select
(
key
,
kw
))[
'sha512'
]),
getattr
(
f
,
'buffer'
,
f
))
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