Skip to content

Commit

Permalink
Fix meta class and doReadLogLevel.
Browse files Browse the repository at this point in the history
  • Loading branch information
alenz33 committed Mar 20, 2015
1 parent 0f759de commit e13bd25
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions conduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def main(argv=None):
BuildStep('s2', {}).build()
BuildStep('s3', {}).build()
bs = CopyBS('copysth', {})
bs.loglevel = 'debug'
bs.description = 'Some description'
bs.build()
except Exception as e:
conduct.log.exception(e)
Expand Down
20 changes: 15 additions & 5 deletions conduct/buildsteps.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import conduct
from conduct.util import systemCall
from conduct.loggers import LOGLEVELS
from conduct.loggers import LOGLEVELS, INVLOGLEVELS
from conduct.param import Parameter, oneof


Expand All @@ -38,9 +38,11 @@ def __new__(mcls, name, bases, attrs):
mcls._mergeDictAttr('parameters', bases, attrs)
mcls._mergeDictAttr('outparameters', bases, attrs)

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


cls = type.__new__(mcls, name, bases, attrs)

return cls
Expand All @@ -59,8 +61,6 @@ def _mergeDictAttr(mcls, name, bases, attrs):

@classmethod
def _createProperties(mcls, paramDict, attrs):
attrs['_params'] = {}

for name, definition in paramDict.iteritems():
mcls._createProperty(name, definition, attrs)

Expand Down Expand Up @@ -99,7 +99,12 @@ class BuildStep(object):
__metaclass__ = BuildStepMeta

parameters = {
'loglevel' : Parameter(type=oneof(LOGLEVELS.keys()), helpStr='Log level', default='info'),
'description' : Parameter(type=str,
helpStr='Build step description',
default='Undescribed'),
'loglevel' : Parameter(type=oneof(LOGLEVELS.keys()),
helpStr='Log level',
default='info'),
}

outparameters = {
Expand All @@ -116,7 +121,8 @@ def __init__(self, name, paramCfg):
def build(self):
# log some bs stuff
self.log.info('=' * 80)
self.log.info('Start build step: %s ...' % self.name)
self.log.info('Start build step: %s' % self.name)
self.log.info(self.description)
self.log.info('-' * 80)

resultStr = 'SUCCESS'
Expand All @@ -142,6 +148,10 @@ def run(self, args):
def doWriteLoglevel(self, value):
self.log.setLevel(LOGLEVELS[value])

def doReadLoglevel(self):
level = self.log.getEffectiveLevel()
return INVLOGLEVELS[level]


def _initLogger(self):
self.log = conduct.log.getChild(self.name)
Expand Down
1 change: 1 addition & 0 deletions conduct/loggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
SECONDS_PER_DAY = 60 * 60 * 24

LOGLEVELS = {'debug': DEBUG, 'info': INFO, 'warning': WARNING, 'error': ERROR}
INVLOGLEVELS = {value : key for key, value in LOGLEVELS.iteritems()}


class ConsoleFormatter(Formatter):
Expand Down

0 comments on commit e13bd25

Please sign in to comment.