Add the capability to declare the function inside the state dec

This is likey to be changed to the default means of declaring the
function. The original intent of having the function as a string in the
state dec list was to declare multiple functions, but this turned out to
be a non scalable concept and was hard locked out quietly in 0.9.4.

Fix #1042
This commit is contained in:
Thomas S Hatch 2012-04-03 18:02:26 -06:00
parent b0d8635c9e
commit 77d1213781

View File

@ -354,6 +354,8 @@ class State(object):
errors.append(err) errors.append(err)
else: else:
fun = 0 fun = 0
if '.' in state:
fun += 1
for arg in body[state]: for arg in body[state]:
if isinstance(arg, basestring): if isinstance(arg, basestring):
fun += 1 fun += 1
@ -508,8 +510,15 @@ class State(object):
if name.startswith('__'): if name.startswith('__'):
continue continue
for state, run in body.items(): for state, run in body.items():
funcs = set()
names = set()
if state.startswith('__'): if state.startswith('__'):
continue continue
if '.' in state:
# the function is formatted as part of the state dec
comps = state.split('.')
state = comps[0]
funcs.add(comps[1])
chunk = {'state': state, chunk = {'state': state,
'name': name} 'name': name}
if '__sls__' in body: if '__sls__' in body:
@ -517,8 +526,6 @@ class State(object):
if '__env__' in body: if '__env__' in body:
chunk['__env__'] = body['__env__'] chunk['__env__'] = body['__env__']
chunk['__id__'] = name chunk['__id__'] = name
funcs = set()
names = set()
for arg in run: for arg in run:
if isinstance(arg, basestring): if isinstance(arg, basestring):
funcs.add(arg) funcs.add(arg)
@ -1204,6 +1211,14 @@ class BaseHighState(object):
if not isinstance(state[name], dict): if not isinstance(state[name], dict):
if name == '__extend__': if name == '__extend__':
continue continue
if isinstance(state[name], basestring):
# Is this is a short state, it needs to be padded
if '.' in state[name]:
state[name] = {'__sls__': sls,
'__env__': env,
state[name]: []}
continue
errors.append(('Name {0} in sls {1} is not a dictionary' errors.append(('Name {0} in sls {1} is not a dictionary'
.format(name, sls))) .format(name, sls)))
continue continue