Skip to content

Commit

Permalink
Create SystemCallStep.
Browse files Browse the repository at this point in the history
  • Loading branch information
alenz33 committed Mar 20, 2015
1 parent c5188eb commit 1373d49
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 deletions.
13 changes: 9 additions & 4 deletions conduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import conduct

from conduct import loggers, config
from conduct.buildsteps import CopyBS, BuildStep
from conduct.buildsteps import SystemCallStep, BuildStep

def parseArgv(argv):
parser = argparse.ArgumentParser(description='conduct - CONvenient Construction Tool',
Expand Down Expand Up @@ -92,10 +92,15 @@ def main(argv=None):
BuildStep('s1', {}).build()
BuildStep('s2', {}).build()
BuildStep('s3', {}).build()
bs = CopyBS('copysth', {})
bs.loglevel = 'debug'
bs.description = 'Some description'
bs = SystemCallStep('scs', {
'command' : 'ls',
'captureoutput' : True
})
bs.build()
#bs = CopyBS('copysth', {})
#bs.loglevel = 'debug'
#bs.description = 'Some description'
#bs.build()
except Exception as e:
conduct.log.exception(e)
conduct.log.error('')
Expand Down
60 changes: 42 additions & 18 deletions conduct/buildsteps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import conduct
from conduct.util import systemCall
from conduct.loggers import LOGLEVELS, INVLOGLEVELS
from conduct.param import Parameter, oneof
from conduct.param import Parameter, oneof, none_or


class BuildStepMeta(type):
Expand Down Expand Up @@ -110,12 +110,11 @@ class BuildStep(object):
outparameters = {
}

def __init__(self, name, paramCfg):
self._paramCfg = paramCfg

def __init__(self, name, paramValues):
self.name = name

self._initLogger()
self._applyParams(paramValues)


def build(self):
Expand Down Expand Up @@ -152,28 +151,53 @@ def doReadLoglevel(self):
level = self.log.getEffectiveLevel()
return INVLOGLEVELS[level]


def _initLogger(self):
self.log = conduct.log.getChild(self.name)
self.log.setLevel(LOGLEVELS[self.loglevel])

def _applyParams(self, paramValues):
for name, value in paramValues.iteritems():
setattr(self, name, value)

loglevel = self._paramCfg.get('loglevel',
self.parameters['loglevel'].default)
self.log.setLevel(LOGLEVELS[loglevel])


class CopyBS(BuildStep):

class SystemCallStep(BuildStep):
parameters = {
'source' : Parameter(type=str, description='Source to copy'),
'destination' : Parameter(type=str, description='Destination of copy'),
'recursive' : Parameter(type=bool, description='Copy directories recursively'),
'command' : Parameter(type=str,
description='command to execute'),
'captureoutput' : Parameter(type=bool,
description='Capture command output',
default=True)
}

outparameters = {
'commandoutput' : Parameter(type=none_or(str),
description='Command output (if captured)',
default=None)
}

def run(self, args):
fromPath = args['source']
toPath = args['destination']
recursive = args['recursive']
self.commandoutput = systemCall(self.command,
captureOutput=self.captureoutput,
log=self.log)



cpArgs = '-r' if recursive else ''
cmd = 'cp %s %s %s' % (cpArgs, fromPath, toPath)

systemCall(cmd,log=self.log)
#class CopyBS(BuildStep):
# parameters = {
# 'source' : Parameter(type=str, description='Source to copy'),
# 'destination' : Parameter(type=str, description='Destination of copy'),
# 'recursive' : Parameter(type=bool, description='Copy directories recursively'),
# }
#
# def run(self, args):
# fromPath = args['source']
# toPath = args['destination']
# recursive = args['recursive']
#
# cpArgs = '-r' if recursive else ''
# cmd = 'cp %s %s %s' % (cpArgs, fromPath, toPath)
#
# systemCall(cmd,log=self.log)
5 changes: 3 additions & 2 deletions conduct/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

## Util funcs

def systemCall(cmd, sh=True, captureOutput=False, log=logging):
log.debug('System call [sh:%s][captureOutput:%s]: %s' \
def systemCall(cmd, sh=True, captureOutput=False, log=None):
if log is not None:
log.debug('System call [sh:%s][captureOutput:%s]: %s' \
% (sh, captureOutput, cmd))

if captureOutput:
Expand Down

0 comments on commit 1373d49

Please sign in to comment.