Skip to content

Commit

Permalink
Change referencer infrastructure.
Browse files Browse the repository at this point in the history
  • Loading branch information
alenz33 committed Mar 27, 2015
1 parent 13b371b commit 81f672e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion conduct/buildsteps.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def readFunc(self):
# resolve references
if isinstance(value, Referencer):
# resolve and validate
value = paramDef.type(value.resolve(self.chain))
value = paramDef.type(value.evaluate(self.chain))

return value
readFunc.__name__ = '_readParam%s' % capitalParamName
Expand Down
16 changes: 13 additions & 3 deletions conduct/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#
# *****************************************************************************

import pprint
import re
from os import path
from collections import OrderedDict

import conduct
from conduct.param import Parameter
from conduct.util import loadChainDefinition
from conduct.util import loadChainDefinition, Referencer


class Chain(object):
Expand Down Expand Up @@ -75,10 +75,20 @@ def _createSteps(self):
mod = __import__(clsMod)
cls = getattr(mod, clsName)

self.steps[name] = cls(name, definition[1], self)
params = self._createReferencers(definition[1])
self.steps[name] = cls(name, params, self)
else:
# TODO parameter forwarding
self.steps[name] = Chain(entryName)

def _createReferencers(self, paramValues):
for paramName, paramValue in paramValues.iteritems():
if isinstance(paramValue, str) \
and re.match('.*?(\{(.*?)\})+.*?', paramValue):
paramValues[paramName] = Referencer(paramValue)

return paramValues




26 changes: 20 additions & 6 deletions conduct/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@
## Utils classes

class Referencer(object):
def __init__(self, adr):
self.adr = adr
def __init__(self, fmt):
self.fmt = fmt

def resolve(self, chain):
parts = self.adr.split('.')
def evaluate(self, chain):
result = self.fmt.format(chain=Dataholder(chain.params),
steps=chain.steps)

return result

def resolve(self, adr, chain):
parts = adr.split('.')
# chain.parameter
# or
# steps.stepname.parameter
Expand All @@ -48,7 +54,7 @@ def resolve(self, chain):
step = chain.steps[parts[1]]
return getattr(step, parts[2])

raise RuntimeError('Could not resolve reference: %s' % self.adr)
raise RuntimeError('Could not resolve reference: %s' % adr)

class AttrStringifier(object):
def __getattr__(self, name):
Expand All @@ -65,6 +71,15 @@ def __setattr__(self, name, value):
self.entries[name] = value


class Dataholder(object):
def __init__(self, modelDict):
self._modelDict = modelDict

def __getattr__(self, name):
if name in self._modelDict:
return self._modelDict[name]


## Util funcs

def systemCall(cmd, sh=True, captureOutput=False, log=None):
Expand Down Expand Up @@ -129,7 +144,6 @@ def loadChainDefinition(chainName):
'Step' : lambda cls, **params: ('step:%s' % cls, params),
'Chain' : lambda cls, **params: ('chain:%s' % cls, params),
'steps' : ObjectiveOrderedDict(),
'ref' : lambda refAdr: Referencer(refAdr),
}

# execute and extract all the interesting data
Expand Down
12 changes: 6 additions & 6 deletions etc/chains/compile_autotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@
}

# Build steps
steps.autogen = Step('conduct.SystemCallStep',
steps.autogen = Step('conduct.SystemCall',
description='Generate configure via autogen.sh',
workingdir=ref('chain.sourcedir'),
workingdir='{chain.sourcedir}',
command='./autogen.sh')
steps.configure = Step('conduct.SystemCallStep',
steps.configure = Step('conduct.SystemCall',
description='Execute configure script',
workingdir=ref('chain.sourcedir'),
workingdir='{chain.sourcedir}',
command='./configure')
steps.make = Step('conduct.SystemCallStep',
steps.make = Step('conduct.SystemCall',
description='Build software via make',
workingdir=ref('chain.sourcedir'),
workingdir='{chain.sourcedir}',
command='make')


0 comments on commit 81f672e

Please sign in to comment.