Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
slapos.core
Commits
921d9325
Commit
921d9325
authored
May 28, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use requests package for 'slapos cache lookup'
parent
5ecc02c2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
8 deletions
+21
-8
setup.py
setup.py
+1
-0
slapos/cache.py
slapos/cache.py
+16
-8
slapos/cli/entry.py
slapos/cli/entry.py
+4
-0
No files found.
setup.py
View file @
921d9325
...
...
@@ -45,6 +45,7 @@ setup(name=name,
'zope.interface'
,
# slap library implementes interfaces
'zc.buildout'
,
'cliff'
,
'requests'
,
]
+
additional_install_requires
,
extra_requires
=
{
'docs'
:
(
'Sphinx'
,
'repoze.sphinx.autointerface'
),},
tests_require
=
[
...
...
slapos/cache.py
View file @
921d9325
...
...
@@ -4,35 +4,43 @@ import ast
import
hashlib
import
json
import
re
import
requests
import
sys
import
urllib2
from
slapos.grid
import
networkcache
from
slapos.grid.distribution
import
patched_linux_distribution
def
maybe_md5
(
s
):
def
looks_like_md5
(
s
):
"""
Return True if the parameter looks like an hashed value.
Not 100% precise, but we're actually more interested in filtering out URLs and pathnames.
"""
return
re
.
match
(
'[0-9a-f]{32}'
,
s
)
def
do_lookup
(
configp
,
software_url
):
cache_dir
=
configp
.
get
(
'networkcache'
,
'download-binary-dir-url'
)
if
mayb
e_md5
(
software_url
):
if
looks_lik
e_md5
(
software_url
):
md5
=
software_url
else
:
md5
=
hashlib
.
md5
(
software_url
).
hexdigest
()
try
:
response
=
urllib2
.
urlopen
(
'%s/%s'
%
(
cache_dir
,
md5
))
except
urllib2
.
HTTPError
as
e
:
if
e
.
code
==
404
:
req
=
requests
.
get
(
'%s/%s'
%
(
cache_dir
,
md5
))
except
requests
.
ConnectionError
:
print
'Cannot connect to cache at %s'
%
cache_dir
sys
.
exit
(
10
)
if
not
req
.
ok
:
if
req
.
status_code
==
404
:
print
'Object not in cache: %s'
%
software_url
else
:
print
'Error
during cache lookup: %s (%s)'
%
(
e
.
code
,
e
.
reason
)
print
'Error
while looking object %s: %s'
%
(
software_url
,
req
.
reason
)
sys
.
exit
(
10
)
entries
=
json
.
loads
(
response
.
read
()
)
entries
=
req
.
json
(
)
linux_distribution
=
patched_linux_distribution
()
...
...
slapos/cli/entry.py
View file @
921d9325
...
...
@@ -10,6 +10,10 @@ import cliff.commandmanager
import
slapos.version
# silence messages like 'Starting connection' that are logged with INFO
urllib3_logger
=
logging
.
getLogger
(
'requests.packages.urllib3'
)
urllib3_logger
.
setLevel
(
logging
.
WARNING
)
class
SlapOSCommandManager
(
cliff
.
commandmanager
.
CommandManager
):
...
...
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