Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
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
Valentin Benozillo
slapos
Commits
e441c05b
Commit
e441c05b
authored
Nov 03, 2011
by
Antoine Catton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move unparseUrl from genericslap to generic base recipe
parent
d1850916
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
37 deletions
+45
-37
slapos/recipe/librecipe/generic.py
slapos/recipe/librecipe/generic.py
+43
-0
slapos/recipe/librecipe/genericslap.py
slapos/recipe/librecipe/genericslap.py
+2
-37
No files found.
slapos/recipe/librecipe/generic.py
View file @
e441c05b
...
...
@@ -28,6 +28,9 @@ import logging
import
os
import
sys
import
inspect
import
re
import
urllib
import
urlparse
import
pkg_resources
import
zc.buildout
...
...
@@ -98,6 +101,14 @@ class GenericBaseRecipe(object):
path
,
arguments
=
arguments
)[
0
]
return
script
def
createDirectory
(
self
,
parent
,
name
,
mode
=
0700
):
path
=
os
.
path
.
join
(
parent
,
name
)
if
not
os
.
path
.
exists
(
path
):
os
.
mkdir
(
path
,
mode
)
elif
not
os
.
path
.
isdir
(
path
):
raise
OSError
(
"%r exists but is not a directory."
%
name
)
return
path
def
substituteTemplate
(
self
,
template_location
,
mapping_dict
):
"""Read from file template_location an substitute content with
mapping_dict doing a dummy python format."""
...
...
@@ -123,3 +134,35 @@ class GenericBaseRecipe(object):
if
default
is
not
None
and
optionname
not
in
self
.
options
:
return
default
return
self
.
isTrueValue
(
self
.
options
[
optionname
])
def
unparseUrl
(
self
,
scheme
,
host
,
path
=
''
,
params
=
''
,
query
=
''
,
fragment
=
''
,
port
=
None
,
auth
=
None
):
"""Join a url with auth, host, and port.
* auth can be either a login string or a tuple (login, password).
* if the host is an ipv6 address, brackets will be added to surround it.
"""
# XXX-Antoine: I didn't find any standard module to join an url with
# login, password, ipv6 host and port.
# So instead of copy and past in every recipe I factorized it right here.
netloc
=
''
if
auth
is
not
None
:
auth
=
tuple
(
auth
)
netloc
=
urllib
.
quote
(
str
(
auth
[
0
]))
# Login
if
len
(
auth
)
>
1
:
netloc
+=
':%s'
%
urllib
.
quote
(
auth
[
1
])
# Password
netloc
+=
'@'
# host is an ipv6 address whithout brackets
if
':'
in
host
and
not
re
.
match
(
r'^\
[.*
\]$'
,
host
):
netloc
+=
'[%s]'
%
host
else
:
netloc
+=
str
(
host
)
if
port
is
not
None
:
netloc
+=
':%s'
%
port
url
=
urlparse
.
urlunparse
((
scheme
,
netloc
,
path
,
params
,
query
,
fragment
))
return
url
slapos/recipe/librecipe/genericslap.py
View file @
e441c05b
...
...
@@ -26,9 +26,6 @@
##############################################################################
from
slapos
import
slap
import
time
import
re
import
urlparse
import
urllib
from
generic
import
GenericBaseRecipe
...
...
@@ -37,8 +34,8 @@ class GenericSlapRecipe(GenericBaseRecipe):
def
__init__
(
self
,
buildout
,
name
,
options
):
"""Default initialisation"""
options
[
'eggs'
]
=
'slapos.cookbook'
GenericBaseRecipe
.
__init__
(
self
,
buildout
,
name
,
options
)
options
[
'eggs'
]
=
'slapos.cookbook'
self
.
slap
=
slap
.
slap
()
# SLAP related information
...
...
@@ -81,37 +78,5 @@ class GenericSlapRecipe(GenericBaseRecipe):
raise
NotImplementedError
(
'Shall be implemented by subclass'
)
def
setConnectionUrl
(
self
,
*
args
,
**
kwargs
):
url
=
self
.
_
unparseUrl
(
*
args
,
**
kwargs
)
url
=
self
.
unparseUrl
(
*
args
,
**
kwargs
)
self
.
setConnectionDict
(
dict
(
url
=
url
))
def
_unparseUrl
(
self
,
scheme
,
host
,
path
=
''
,
params
=
''
,
query
=
''
,
fragment
=
''
,
port
=
None
,
auth
=
None
):
"""Join a url with auth, host, and port.
* auth can be either a login string or a tuple (login, password).
* if the host is an ipv6 address, brackets will be added to surround it.
"""
# XXX-Antoine: I didn't find any standard module to join an url with
# login, password, ipv6 host and port.
# So instead of copy and past in every recipe I factorized it right here.
netloc
=
''
if
auth
is
not
None
:
auth
=
tuple
(
auth
)
netloc
=
urllib
.
quote
(
str
(
auth
[
0
]))
# Login
if
len
(
auth
)
>
1
:
netloc
+=
':%s'
%
urllib
.
quote
(
auth
[
1
])
# Password
netloc
+=
'@'
# host is an ipv6 address whithout brackets
if
':'
in
host
and
not
re
.
match
(
r'^\
[.*
\]$'
,
host
):
netloc
+=
'[%s]'
%
host
else
:
netloc
+=
str
(
host
)
if
port
is
not
None
:
netloc
+=
':%s'
%
port
url
=
urlparse
.
urlunparse
((
scheme
,
netloc
,
path
,
params
,
query
,
fragment
))
return
url
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