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
Carlos Ramos Carreño
slapos
Commits
73baf7a1
Commit
73baf7a1
authored
Oct 24, 2012
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
createWrapper()
parent
ea9f28cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
0 deletions
+42
-0
slapos/recipe/librecipe/generic.py
slapos/recipe/librecipe/generic.py
+21
-0
slapos/recipe/librecipe/shlex.py
slapos/recipe/librecipe/shlex.py
+21
-0
No files found.
slapos/recipe/librecipe/generic.py
View file @
73baf7a1
...
@@ -35,6 +35,8 @@ import urlparse
...
@@ -35,6 +35,8 @@ import urlparse
import
pkg_resources
import
pkg_resources
import
zc.buildout
import
zc.buildout
from
slapos.recipe.librecipe
import
shlex
class
GenericBaseRecipe
(
object
):
class
GenericBaseRecipe
(
object
):
"""Boilerplate class for all Buildout recipes providing helpful methods like
"""Boilerplate class for all Buildout recipes providing helpful methods like
creating configuration file, creating wrappers, generating passwords, etc.
creating configuration file, creating wrappers, generating passwords, etc.
...
@@ -107,6 +109,25 @@ class GenericBaseRecipe(object):
...
@@ -107,6 +109,25 @@ class GenericBaseRecipe(object):
path
,
arguments
=
arguments
)[
0
]
path
,
arguments
=
arguments
)[
0
]
return
script
return
script
def
createWrapper
(
self
,
name
,
command
,
parameters
):
"""Creates a very simple (one command) shell script. Takes care of quoting."""
q
=
shlex
.
quote
lines
=
[
'#!/bin/sh'
,
shlex
.
quote
(
command
)
]
for
param
in
parameters
:
if
len
(
lines
[
-
1
])
<
30
:
lines
[
-
1
]
+=
' '
+
shlex
.
quote
(
param
)
else
:
lines
[
-
1
]
+=
'
\
\
'
lines
.
append
(
'
\
t
'
+
shlex
.
quote
(
param
))
content
=
'
\
n
'
.
join
(
lines
)
+
'
\
n
'
return
self
.
createFile
(
name
,
content
,
0700
)
def
createDirectory
(
self
,
parent
,
name
,
mode
=
0700
):
def
createDirectory
(
self
,
parent
,
name
,
mode
=
0700
):
path
=
os
.
path
.
join
(
parent
,
name
)
path
=
os
.
path
.
join
(
parent
,
name
)
if
not
os
.
path
.
exists
(
path
):
if
not
os
.
path
.
exists
(
path
):
...
...
slapos/recipe/librecipe/shlex.py
0 → 100644
View file @
73baf7a1
# -*- coding: utf-8 -*-
"""
backported part of shlex.py from Python 3.3
"""
import
re
_find_unsafe
=
re
.
compile
(
r'[^\
w@%+=:,./-]
', 256).search
def quote(s):
"""Return a shell-escaped version of the string *s*."""
if not s:
return "''"
if _find_unsafe(s) is None:
return s
# use single quotes, and put single quotes into double quotes
# the string $'
b
is
then
quoted
as
'$'"'"'b'
return
"'"
+
s
.
replace
(
"'"
,
"'
\
"
'
\
"
'"
)
+
"'"
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