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
80c85d82
Commit
80c85d82
authored
Jul 03, 2013
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New scripts to download & upload manually from command line
parent
ac8463ad
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
setup.py
setup.py
+2
-0
slapos/libnetworkcache.py
slapos/libnetworkcache.py
+52
-0
No files found.
setup.py
View file @
80c85d82
...
@@ -42,6 +42,8 @@ setup(
...
@@ -42,6 +42,8 @@ setup(
entry_points
=
{
entry_points
=
{
'console_scripts'
:
[
'console_scripts'
:
[
'generate-signature-key = slapos.signature:run'
,
'generate-signature-key = slapos.signature:run'
,
'networkcache-download = slapos.libnetworkcache:download'
,
'networkcache-upload = slapos.libnetworkcache:upload'
,
]
]
},
},
zip_safe
=
True
,
zip_safe
=
True
,
...
...
slapos/libnetworkcache.py
View file @
80c85d82
...
@@ -12,10 +12,15 @@
...
@@ -12,10 +12,15 @@
#
#
##############################################################################
##############################################################################
import
argparse
import
ConfigParser
import
hashlib
import
hashlib
import
httplib
import
httplib
import
json
import
json
import
os
import
os
import
shutil
import
sys
import
tarfile
import
tempfile
import
tempfile
import
traceback
import
traceback
import
urllib2
import
urllib2
...
@@ -62,6 +67,10 @@ class NetworkcacheClient(object):
...
@@ -62,6 +67,10 @@ class NetworkcacheClient(object):
},
signature_certificate_list
)
},
signature_certificate_list
)
def
__new_init
(
self
,
config
,
signature_certificate_list
=
None
):
def
__new_init
(
self
,
config
,
signature_certificate_list
=
None
):
if
not
hasattr
(
config
,
'get'
):
parser
=
ConfigParser
.
SafeConfigParser
()
parser
.
readfp
(
config
)
config
=
dict
(
parser
.
items
(
'networkcache'
))
self
.
config
=
config
self
.
config
=
config
path
=
config
.
get
(
'signature-private-key-file'
)
path
=
config
.
get
(
'signature-private-key-file'
)
if
path
:
if
path
:
...
@@ -278,3 +287,46 @@ class DirectoryNotFound(Exception):
...
@@ -278,3 +287,46 @@ class DirectoryNotFound(Exception):
class
UploadError
(
Exception
):
class
UploadError
(
Exception
):
pass
pass
def
_newArgumentParser
():
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'slapos_config'
,
type
=
argparse
.
FileType
(
'r'
),
help
=
'SlapOS configuration file.'
)
return
parser
def
cmd_upload
(
*
args
):
parser
=
_newArgumentParser
()
parser
.
add_argument
(
'--prefix-key'
,
default
=
''
,
help
=
"Key will be concatenation of PREFIX_KEY and md5(URL)."
)
parser
.
add_argument
(
'--url'
,
required
=
True
,
help
=
"Upload data pointed to by this argument, unless --file is specified."
" If argument is not a local path, contents is first downloaded"
" in a temporary file."
)
parser
.
add_argument
(
'--file'
,
help
=
"Upload the contents of this file, overriding --url"
)
args
=
parser
.
parse_args
(
args
or
sys
.
argv
[
1
:])
nc
=
NetworkcacheClient
(
args
.
slapos_config
)
f
=
None
try
:
if
args
.
file
:
f
=
open
(
args
.
file
)
elif
os
.
path
.
isdir
(
args
.
url
):
f
=
nc
.
archive
(
args
.
url
)
else
:
f
=
urllib2
.
urlopen
(
args
.
url
)
urlmd5
=
hashlib
.
md5
(
args
.
url
).
hexdigest
()
nc
.
upload
(
f
,
args
.
prefix_key
+
urlmd5
,
urlmd5
=
urlmd5
,
file_name
=
os
.
path
.
basename
(
args
.
url
))
finally
:
f
is
None
or
f
.
close
()
def
cmd_download
(
*
args
):
parser
=
_newArgumentParser
()
parser
.
add_argument
(
'--prefix-key'
,
default
=
''
,
help
=
"Key will be concatenation of PREFIX_KEY and md5(URL)."
)
parser
.
add_argument
(
'--url'
,
required
=
True
,
help
=
"URL of data to download."
)
args
=
parser
.
parse_args
(
args
or
sys
.
argv
[
1
:])
nc
=
NetworkcacheClient
(
args
.
slapos_config
)
key
=
args
.
prefix_key
+
hashlib
.
md5
(
args
.
url
).
hexdigest
()
shutil
.
copyfileobj
(
nc
.
download
(
nc
.
select
(
key
).
next
()[
'sha512'
]),
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