Skip to content

Commit

Permalink
First real steps in chain implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
alenz33 committed Mar 23, 2015
1 parent ede71a0 commit b42ce29
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 27 deletions.
1 change: 1 addition & 0 deletions conduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def main(argv=None):
initLogging(args.chain)

chain = Chain(args.chain)
chain.build()


#try:
Expand Down
1 change: 1 addition & 0 deletions conduct/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import logging

from conduct.util import systemCall
from conduct.buildsteps import *

log = None
cfg = None
18 changes: 11 additions & 7 deletions conduct/buildsteps.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from conduct.loggers import LOGLEVELS, INVLOGLEVELS
from conduct.param import Parameter, oneof, none_or

__all__ = ['BuildStep', 'SystemCallStep']


class BuildStepMeta(type):
'''
Expand All @@ -38,7 +40,7 @@ def __new__(mcls, name, bases, attrs):
mcls._mergeDictAttr('parameters', bases, attrs)
mcls._mergeDictAttr('outparameters', bases, attrs)

attrs['_params'] = {}
#attrs['_params'] = {}
mcls._createProperties(attrs['parameters'], attrs)
mcls._createProperties(attrs['outparameters'], attrs)

Expand Down Expand Up @@ -70,14 +72,14 @@ def _createProperty(mcls, paramName, paramDef, attrs):
capitalParamName = paramName.capitalize()

# set default value for parameter
if paramDef.default is not None:
attrs['_params'][paramName] = paramDef.default
#if paramDef.default is not None:
# attrs['_params'][paramName] = paramDef.default

# create parameter read function
def readFunc(self):
if hasattr(self, 'doRead%s' % capitalParamName):
return getattr(self, 'doRead%s' % capitalParamName)()
return self._params[paramName]
return self._params.get(paramName, paramDef.default)
readFunc.__name__ = '_readParam%s' % capitalParamName

# create parameter write function
Expand Down Expand Up @@ -113,6 +115,8 @@ class BuildStep(object):
def __init__(self, name, paramValues):
self.name = name

self._params = {}

self._initLogger()
self._applyParams(paramValues)

Expand All @@ -127,7 +131,7 @@ def build(self):
resultStr = 'SUCCESS'
try:
# execute actual build actions
self.run({})
self.run()
except Exception as exc:
resultStr = 'FAILED'
self.log.exception(exc)
Expand All @@ -141,7 +145,7 @@ def build(self):
return True


def run(self, args):
def run(self):
pass

def doWriteLoglevel(self, value):
Expand Down Expand Up @@ -180,7 +184,7 @@ class SystemCallStep(BuildStep):
default=None)
}

def run(self, args):
def run(self):
cwd = os.getcwd()

try:
Expand Down
60 changes: 57 additions & 3 deletions conduct/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,73 @@
#
# *****************************************************************************

import pprint
from os import path

import conduct
from conduct.param import Parameter
from conduct.util import AttrStringifier, ObjectiveOrderedDict

from os import path

class Chain(object):
def __init__(self, name):
self.name = name
self._chainDef = {}
self._steps = []

self._loadChainFile()

self. _loadConfig()

def build(self):
for step in self._steps:
step.build()

def _loadConfig(self):

def _loadChainFile(self):
# determine chain file location
chainDir = conduct.cfg['conduct']['chaindir']
chainFile = path.join(chainDir, '%s.py' % self.name)

if not path.exists(chainFile):
raise IOError('Chain file for \'%s\' not found (Should be: %s)'
% (self.name, chainFile))

content = open(chainFile).read()

# prepare exection namespace
ns = {
'Parameter' : Parameter,
'Step' : lambda cls, **params: ('step:%s' % cls, params),
'Chain' : lambda cls, **params: ('chain:%s' % cls, params),
'steps' : ObjectiveOrderedDict()
}

# execute and extract all the interesting data
exec content in ns

for entry in ['description', 'parameters']:
self._chainDef[entry] = ns[entry]

self._chainDef['steps'] = ns['steps'].entries

# create build steps
self._createSteps()

def _createSteps(self):
for name, definition in self._chainDef['steps'].iteritems():
# name should be step:name or chain:name
entryType, entryName = definition[0].split(':')

if entryType == 'step':
# for steps, the entryName should be a full path (mod.class)
clsMod, _, clsName = entryName.rpartition('.')
mod = __import__(clsMod)
cls = getattr(mod, clsName)

step = cls(name, definition[1])
self._steps.append(step)
else:
self._steps.append(Chain(entryName))



19 changes: 19 additions & 0 deletions conduct/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@
import logging
import subprocess

from collections import OrderedDict

## Utils classes

class AttrStringifier(object):
def __getattr__(self, name):
return name

# TODO: Better name
class ObjectiveOrderedDict(object):
def __init__(self):
self.entries = OrderedDict()

def __setattr__(self, name, value):
if name == 'entries':
return object.__setattr__(self, name, value)
self.entries[name] = value


## Util funcs

def systemCall(cmd, sh=True, captureOutput=False, log=None):
Expand Down
39 changes: 22 additions & 17 deletions etc/chains/compile_autotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,34 @@
#
# *****************************************************************************

# Docstring for full documentation of chain
'''
Simple chain to compile software thats build is based on autotools.
'''

import conduct

# Short description which will be displayed on command line help.
description = 'Simple chain to compile software thats build is based on autotools'

# Chain specific parameters
parameters = {
'sourcedir' : Parameter(type=str,
description='Path to the source directory'),
}

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


0 comments on commit b42ce29

Please sign in to comment.