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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Justin
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
Show 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
...
@@ -28,6 +28,9 @@ import logging
import
os
import
os
import
sys
import
sys
import
inspect
import
inspect
import
re
import
urllib
import
urlparse
import
pkg_resources
import
pkg_resources
import
zc.buildout
import
zc.buildout
...
@@ -98,6 +101,14 @@ class GenericBaseRecipe(object):
...
@@ -98,6 +101,14 @@ class GenericBaseRecipe(object):
path
,
arguments
=
arguments
)[
0
]
path
,
arguments
=
arguments
)[
0
]
return
script
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
):
def
substituteTemplate
(
self
,
template_location
,
mapping_dict
):
"""Read from file template_location an substitute content with
"""Read from file template_location an substitute content with
mapping_dict doing a dummy python format."""
mapping_dict doing a dummy python format."""
...
@@ -123,3 +134,35 @@ class GenericBaseRecipe(object):
...
@@ -123,3 +134,35 @@ class GenericBaseRecipe(object):
if
default
is
not
None
and
optionname
not
in
self
.
options
:
if
default
is
not
None
and
optionname
not
in
self
.
options
:
return
default
return
default
return
self
.
isTrueValue
(
self
.
options
[
optionname
])
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 @@
...
@@ -26,9 +26,6 @@
##############################################################################
##############################################################################
from
slapos
import
slap
from
slapos
import
slap
import
time
import
time
import
re
import
urlparse
import
urllib
from
generic
import
GenericBaseRecipe
from
generic
import
GenericBaseRecipe
...
@@ -37,8 +34,8 @@ class GenericSlapRecipe(GenericBaseRecipe):
...
@@ -37,8 +34,8 @@ class GenericSlapRecipe(GenericBaseRecipe):
def
__init__
(
self
,
buildout
,
name
,
options
):
def
__init__
(
self
,
buildout
,
name
,
options
):
"""Default initialisation"""
"""Default initialisation"""
options
[
'eggs'
]
=
'slapos.cookbook'
GenericBaseRecipe
.
__init__
(
self
,
buildout
,
name
,
options
)
GenericBaseRecipe
.
__init__
(
self
,
buildout
,
name
,
options
)
options
[
'eggs'
]
=
'slapos.cookbook'
self
.
slap
=
slap
.
slap
()
self
.
slap
=
slap
.
slap
()
# SLAP related information
# SLAP related information
...
@@ -81,37 +78,5 @@ class GenericSlapRecipe(GenericBaseRecipe):
...
@@ -81,37 +78,5 @@ class GenericSlapRecipe(GenericBaseRecipe):
raise
NotImplementedError
(
'Shall be implemented by subclass'
)
raise
NotImplementedError
(
'Shall be implemented by subclass'
)
def
setConnectionUrl
(
self
,
*
args
,
**
kwargs
):
def
setConnectionUrl
(
self
,
*
args
,
**
kwargs
):
url
=
self
.
_
unparseUrl
(
*
args
,
**
kwargs
)
url
=
self
.
unparseUrl
(
*
args
,
**
kwargs
)
self
.
setConnectionDict
(
dict
(
url
=
url
))
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