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
Xiaowu Zhang
slapos
Commits
2ddec14e
Commit
2ddec14e
authored
Oct 06, 2021
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
recipe/promise_plugin: Improve options
parent
99837242
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
20 deletions
+53
-20
slapos/recipe/promise_plugin.py
slapos/recipe/promise_plugin.py
+53
-20
No files found.
slapos/recipe/promise_plugin.py
View file @
2ddec14e
...
@@ -24,15 +24,17 @@
...
@@ -24,15 +24,17 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
##############################################################################
##############################################################################
import
ast
import
re
import
re
import
logging
,
os
import
logging
,
os
import
zc.buildout.easy_install
import
zc.buildout.easy_install
from
pprint
import
pformat
from
pprint
import
pformat
from
slapos.recipe.librecipe
import
GenericBaseRecipe
from
slapos.recipe.librecipe
import
GenericBaseRecipe
from
zc.buildout
import
UserError
script_template
=
'''# This script is auto generated by slapgrid, do not edit!
script_template
=
'''# This script is auto generated by slapgrid, do not edit!
import sys
import sys
sys.path[0:0] = %(path)s
sys.path[0:0] = %(path
s
)s
extra_config_dict = %(config)s
extra_config_dict = %(config)s
...
@@ -54,6 +56,24 @@ for module in list(sys.modules):
...
@@ -54,6 +56,24 @@ for module in list(sys.modules):
%(content)s
%(content)s
'''
'''
execfile_template
=
"""
\
def _(path):
global _
del _
with open(path) as f:
return compile(f.read(), path, 'exec')
exec(_(%r))"""
def
isPythonName
(
name
):
try
:
x
,
=
ast
.
parse
(
name
).
body
if
type
(
x
)
is
ast
.
Expr
:
x
=
x
.
value
return
type
(
x
)
is
ast
.
Name
and
x
.
id
==
name
except
Exception
:
pass
class
Recipe
(
GenericBaseRecipe
):
class
Recipe
(
GenericBaseRecipe
):
_WORKING_SET_CACHE_NAME
=
"slapos.cookbook_pplugin_ws_cache"
_WORKING_SET_CACHE_NAME
=
"slapos.cookbook_pplugin_ws_cache"
...
@@ -64,6 +84,35 @@ class Recipe(GenericBaseRecipe):
...
@@ -64,6 +84,35 @@ class Recipe(GenericBaseRecipe):
options
[
'develop-eggs-directory'
]
=
buildout_section
[
'develop-eggs-directory'
]
options
[
'develop-eggs-directory'
]
=
buildout_section
[
'develop-eggs-directory'
]
super
(
Recipe
,
self
).
__init__
(
buildout
,
name
,
options
)
super
(
Recipe
,
self
).
__init__
(
buildout
,
name
,
options
)
filepath
=
options
.
get
(
'file'
)
module
=
options
.
get
(
'module'
)
klass
=
options
.
get
(
'class'
)
if
klass
==
'RunPromise'
:
klass
=
None
elif
klass
and
not
isPythonName
(
klass
):
raise
UserError
(
"%r is not valid class name"
%
klass
)
if
bool
(
module
)
==
bool
(
filepath
):
raise
UserError
(
"Either 'module' or 'file' is required but not both"
)
if
module
:
if
not
all
(
map
(
isPythonName
,
module
.
split
(
'.'
))):
raise
UserError
(
"%r is not a valid module name"
%
module
)
if
klass
:
content
=
'from %s import %s as RunPromise'
%
(
module
,
klass
)
else
:
content
=
'from %s import RunPromise'
%
module
else
:
content
=
execfile_template
%
filepath
if
klass
:
content
+=
'
\
n
\
n
RunPromise = '
+
klass
self
.
content
=
content
self
.
config_dict
=
{
key
[
7
:]:
options
[
key
]
for
key
in
options
if
key
.
startswith
(
'config-'
)}
def
_get_cache_storage
(
self
):
def
_get_cache_storage
(
self
):
"""Return a mapping where to store generated working sets.
"""Return a mapping where to store generated working sets.
from https://github.com/buildout/buildout/blob/master/zc.recipe.egg_/src/zc/recipe/egg/egg.py#L170
from https://github.com/buildout/buildout/blob/master/zc.recipe.egg_/src/zc/recipe/egg/egg.py#L170
...
@@ -111,26 +160,10 @@ class Recipe(GenericBaseRecipe):
...
@@ -111,26 +160,10 @@ class Recipe(GenericBaseRecipe):
else
:
else
:
working_set
=
set
()
working_set
=
set
()
regex
=
r"^[\
w_
\-\
.
\s]+$"
import_path
=
self
.
options
.
get
(
'import'
,
''
).
strip
()
if
import_path
:
if
not
re
.
search
(
regex
,
import_path
):
raise
ValueError
(
"Import path %r is not a valid"
%
import_path
)
content_string
=
"from %s import RunPromise"
%
import_path
else
:
# old parameter for compatibility
content_string
=
self
.
options
[
'content'
].
strip
()
if
not
re
.
search
(
regex
,
content_string
):
raise
ValueError
(
"Promise content %r is not valid"
%
content_string
)
config_dict
=
{
key
[
7
:]:
self
.
options
[
key
]
for
key
in
self
.
options
if
key
.
startswith
(
'config-'
)}
return
self
.
createFile
(
self
.
options
[
'output'
],
script_template
%
{
return
self
.
createFile
(
self
.
options
[
'output'
],
script_template
%
{
'path
'
:
pformat
([
dist
.
location
for
dist
in
working_set
]
,
indent
=
2
),
'path
s'
:
pformat
(
tuple
(
dist
.
location
for
dist
in
working_set
)
,
indent
=
2
),
'con
tent'
:
content_string
,
'con
fig'
:
pformat
(
self
.
config_dict
,
indent
=
2
)
,
'con
fig'
:
pformat
(
config_dict
,
indent
=
2
)
,
'con
tent'
:
self
.
content
,
},
int
(
self
.
options
.
get
(
'mode'
,
'0644'
),
8
)),
},
int
(
self
.
options
.
get
(
'mode'
,
'0644'
),
8
)),
update
=
install
update
=
install
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