def test_export_site_with_subfolders(self): from Products.GenericSetup.utils import _getDottedName self._setUpAdapters() FOLDER_IDS = ('foo', 'bar', 'baz') site = _makeFolder('site') site.title = 'AAA' site._setProperty('description', 'BBB') aside = _makeFolder('aside') dotted = _getDottedName(aside.__class__) for id in FOLDER_IDS: folder = _makeFolder(id) folder.title = 'Title: %s' % id site._setObject(id, folder) context = DummyExportContext(site) exporter = self._getExporter() exporter(context) self.assertEqual(len(context._wrote), 2 + (2 *len(FOLDER_IDS))) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'structure/.objects') self.assertEqual(content_type, 'text/comma-separated-values') objects = [x for x in reader(StringIO(text))] self.assertEqual(len(objects), 3) for index in range(len(FOLDER_IDS)): id = FOLDER_IDS[index] self.assertEqual(objects[index][0], id) self.assertEqual(objects[index][1], dotted) filename, text, content_type = context._wrote[2 + (2 * index)] self.assertEqual(filename, '/'.join(('structure', id, '.objects'))) self.assertEqual(content_type, 'text/comma-separated-values') subobjects = [x for x in reader(StringIO(text))] self.assertEqual(len(subobjects), 0) filename, text, content_type = context._wrote[2 + (2 * index) + 1] self.assertEqual(filename, '/'.join(('structure', id, '.properties'))) self.assertEqual(content_type, 'text/plain') parser = ConfigParser() parser.readfp(StringIO(text)) defaults = parser.defaults() self.assertEqual(len(defaults), 1) self.assertEqual(defaults['title'], 'Title: %s' % id) filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'structure/.properties') self.assertEqual(content_type, 'text/plain') parser = ConfigParser() parser.readfp(StringIO(text)) defaults = parser.defaults() self.assertEqual(len(defaults), 2) self.assertEqual(defaults['title'], 'AAA') self.assertEqual(defaults['description'], 'BBB')
def __init__(self): if not os.path.exists("BAG.conf"): print "*** FOUT *** Kan configuratiebestand 'BAG.conf' niet openen." print "" raw_input("Druk <enter> om af te sluiten") sys.exit() configdict = ConfigParser() configdict.read("BAG.conf") try: self.database = configdict.defaults()["database"] self.host = configdict.defaults()["host"] self.user = configdict.defaults()["user"] self.password = configdict.defaults()["password"] self.download = configdict.defaults()["download"] self.extract = configdict.defaults()["extract"] self.logging = configdict.defaults()["logging"] except: print "*** FOUT *** Inhoud van configuratiebestand 'BAG.conf' is niet volledig." print "" raw_input("Druk <enter> om af te sluiten") sys.exit() try: self.bestand = configdict.defaults()["bestand"] except: pass
def __init__(self): if not os.path.exists('BAG.conf'): print "*** FOUT *** Kan configuratiebestand 'BAG.conf' niet openen." print "" #raw_input("Druk <enter> om af te sluiten") sys.exit() configdict = ConfigParser() configdict.read('BAG.conf') try: self.database = configdict.defaults()['database'] self.host = configdict.defaults()['host'] self.user = configdict.defaults()['user'] self.password = configdict.defaults()['password'] self.download = configdict.defaults()['download'] self.extract = configdict.defaults()['extract'] self.logging = configdict.defaults()['logging'] # TODO controleer of er commandline parameters zijn meegegeven die de instellingen overrulen except: print "*** FOUT *** Inhoud van configuratiebestand 'BAG.conf' is niet volledig." print "" raw_input("Druk <enter> om af te sluiten") sys.exit() try: self.bestand = configdict.defaults()['bestand'] except: pass
def __init__(self, args): # Derive home dir from script location self.bagextract_home = os.path.realpath(os.path.dirname(sys.argv[0]) + '/..') # Default config file config_file = os.path.realpath(self.bagextract_home + '/extract.conf') # Option: overrule config file with command line arg pointing to config file if args.config: config_file = args.config Log.log.info("Configuratiebestand is " + str(config_file)) if not os.path.exists(config_file): Log.log.fatal("ik kan het configuratiebestand '" + str(config_file) + "' ech niet vinden.") configdict = ConfigParser() try: configdict.read(config_file) except: Log.log.fatal("ik kan " + str(config_file) + " wel vinden maar niet inlezen.") try: # Zet parameters uit config bestand self.database = configdict.defaults()['database'] self.schema = configdict.defaults()['schema'] self.host = configdict.defaults()['host'] self.user = configdict.defaults()['user'] self.password = configdict.defaults()['password'] self.port = configdict.defaults()['port'] except: Log.log.fatal(" de inhoud van configuratiebestand " + str(config_file) + " is niet volledig.") try: # Optioneel: overrulen met (commandline) args if args.database: self.database = args.database if args.host: self.host = args.host if args.schema: self.schema = args.schema # default to public schema if not self.schema: self.schema = 'public' if args.username: self.user = args.username if args.port: self.port = args.port if args.no_password: # Gebruik geen wachtwoord voor de database verbinding self.password = None else: if args.password: self.password = args.password # Assign Singleton (of heeft Python daar namespaces voor?) (Java achtergrond) BAGConfig.config = self except: Log.log.fatal(" het overrulen van configuratiebestand " + str(config_file) + " via commandline loopt spaak")
def load_app(filename): filename = os.path.abspath(filename) parser = ConfigParser() parser.read([filename]) parser.filename = filename parser.defaults()['here'] = os.path.dirname(filename) parser.defaults()['__file__'] = filename return load_app_from_parser(parser)
def raw_configurator(ini_file, local_conf_key='app:mailcone', here=__file__, zope_conf=''): configparser = ConfigParser() configparser.read(ini_file) configparser.defaults().update(dict(here=here)) configurator(dict(here=here, __file__=ini_file, zope_conf=zope_conf), **dict(configparser.items(local_conf_key)))
def test_export_empty_site(self): self._setUpAdapters() site = _makeFolder('site') site.title = 'test_export_empty_site' site.description = 'Testing export of an empty site.' context = DummyExportContext(site) exporter = self._getExporter() exporter(context) self.assertEqual(len(context._wrote), 2) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'structure/.objects') self.assertEqual(content_type, 'text/comma-separated-values') objects = [x for x in reader(StringIO(text))] self.assertEqual(len(objects), 0) filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'structure/.properties') self.assertEqual(content_type, 'text/plain') parser = ConfigParser() parser.readfp(StringIO(text)) defaults = parser.defaults() self.assertEqual(len(defaults), 1) self.assertEqual(defaults['title'], site.title)
def options(self): # If all fails we will always have default values configuration = self.defaults() try: if self.config == None or isfile(self.config) == False: configuration = self.defaults() return configuration except TypeError: # if we are getting a ready-to-go dict then we still try # to do our little translation-and-map thing and if that # comes out as empty, then we assume keys are already # translated if type(self.config) is dict: configuration = self.key_matcher(self.config, return_empty=True) if not configuration: configuration = self.defaults(self.config) return configuration # we could get an object that is dict-like but type(object) # doesn't recognize it as a dict else: configuration = self.key_matcher(self.config) return configuration else: # this will get executed *only* if we are seeing a file try: parser = ConfigParser() parser.read(self.config) file_options = parser.defaults() configuration = self.key_matcher(file_options) except Exception, error: raise OptionConfigurationError(error)
def test_export_empty_site_with_setup_tool(self): self._setUpAdapters() site = _makeFolder('site') site._setObject('setup_tool', self._makeSetupTool()) site._updateProperty('title', 'test_export_empty_site_with_setup_tool') site._setProperty('description', 'Testing export of an empty site with setup tool.') context = DummyExportContext(site) exporter = self._getExporter() exporter(context) self.assertEqual(len(context._wrote), 2) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'structure/.objects') self.assertEqual(content_type, 'text/comma-separated-values') objects = [x for x in reader(StringIO(text))] self.assertEqual(len(objects), 0) filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'structure/.properties') self.assertEqual(content_type, 'text/plain') parser = ConfigParser() parser.readfp(StringIO(text)) defaults = parser.defaults() self.assertEqual(len(defaults), 2) self.assertEqual(defaults['title'], site.title) self.assertEqual(defaults['description'], site.description)
def load_environment(global_conf, app_conf): """Configure the Pylons environment via the ``pylons.config`` object """ config = PylonsConfig() # Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) paths = dict(root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, 'public'), templates=[os.path.join(root, 'templates')]) # import our private.ini that holds keys, etc imp = global_conf.get('import') if imp: cp = ConfigParser() cp.read(imp) global_conf.update(cp.defaults()) if cp.has_section('APP'): app_conf.update(cp.items('APP')) # Initialize config with the basic options config.init_app(global_conf, app_conf, package='linkdrop', paths=paths) config['routes.map'] = make_map(config) config['pylons.app_globals'] = app_globals.Globals(config) import linkdrop.lib.helpers as h config['pylons.h'] = h # Setup cache object as early as possible import pylons pylons.cache._push_object(config['pylons.app_globals'].cache) # Create the Mako TemplateLookup, with the default auto-escaping config['pylons.app_globals'].mako_lookup = TemplateLookup( directories=paths['templates'], error_handler=handle_mako_error, module_directory=os.path.join(app_conf['cache_dir'], 'templates'), input_encoding='utf-8', default_filters=['escape'], imports=['from webhelpers.html import escape']) # Setup the SQLAlchemy database engine engine = engine_from_config(config, 'sqlalchemy.') init_model(engine) # sqlalchemy auto migration if asbool(config.get('migrate.auto')): try: # managed upgrades cschema = schema.ControlledSchema.create(engine, config['migrate.repository']) cschema.update_db_from_model(meta.Base.metadata) except exceptions.InvalidRepositoryError, e: # unmanaged upgrades diff = schemadiff.getDiffOfModelAgainstDatabase( meta.Base.metadata, engine, excludeTables=None) genmodel.ModelGenerator(diff).applyModel()
def parse_config(self): """ Reads the config file (default in /etc/vcscommit/vcscommit.cfg :rtype: ConfigParser object """ cfg = ConfigParser() cfg.read('/etc/vcscommit/vcscommit.cfg') return cfg.defaults()
def defaults(self): """Return the defaults, with their values interpolated (with the defaults dict itself) Mainly to support defaults using values such as %(here)s """ defaults = ConfigParser.defaults(self).copy() for key, val in iteritems(defaults): defaults[key] = self.get('DEFAULT', key) or val return defaults
def test_as_ini_no_properties(self): context = _makePropertied('no_properties') context._properties = () adapter = self._getTargetClass()(context) text = adapter.as_ini() parser = ConfigParser() parser.readfp(StringIO(text)) self.failIf(parser.sections()) default_options = parser.defaults() self.assertEqual(len(default_options), 0)
def put_ini(self, text): """ """ context = self.context parser = ConfigParser() parser.readfp(StringIO(text)) for option, value in parser.defaults().items(): prop_type = context.getPropertyType(option) if prop_type is None: context._setProperty(option, value, 'string') else: context._updateProperty(option, value)
class Config(object): def __init__(self): self._parser = ConfigParser() self._parser._defaults = IncludeDict(self._parser) # Copy attributes from the parser to avoid one additional # function call on each access. for attr in ["has_section", "remove_section"]: setattr(self, attr, getattr(self._parser, attr)) def read_configs(self, configs): for config in configs: match = re.match("(.*)/([^/]+)=(.*)", config) if not match: raise Exception, "Invalid config string: %s" % config (name, option, value) = match.groups() if not self._parser.has_section(name): self._parser.add_section(name) self._parser.set(name, option, value) def read_file(self, file, filename="<stream>"): logging.info("Reading configurations from: %s", filename) self._parser.readfp(file, filename) def read_filename(self, filename): if not posixpath.exists(filename): raise Exception, "No such configuration file: %s" % filename file = open(filename, "r") return self.read_file(file, filename) def get_defaults(self): attributes = self._parser.defaults() return ConfigDefaults(self, 'DEFAULT', attributes) def get_section(self, name): if self._parser.has_section(name): attributes = dict(self._parser.items(name)) return ConfigSection(self, name, attributes) return None def get_section_names(self): return self._parser.sections() def add_section(self, name): self._parser.add_section(name) return self.get_section(name)
def handle_config_option(option, opt, value, parser, *args, **kwargs): fp = open(value, 'r') del fp parser.values.config_file = value config = ConfigParser() parser.values.config = config config.read(value) for k, v in config.defaults().iteritems(): try: v = config.getboolean('DEFAULT', k) except ValueError: pass setattr(parser.values, k, v)
def test_export_site_with_csvaware(self): from Products.GenericSetup.utils import _getDottedName self._setUpAdapters() site = _makeFolder('site') site.title = 'test_export_site_with_csvaware' site._setProperty('description', 'Testing export of an site with CSV-aware content.') aware = _makeCSVAware('aware') site._setObject('aware', aware) context = DummyExportContext(site) exporter = self._getExporter() exporter(context) self.assertEqual(len(context._wrote), 3) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'structure/.objects') self.assertEqual(content_type, 'text/comma-separated-values') objects = [x for x in reader(StringIO(text))] self.assertEqual(len(objects), 1) self.assertEqual(objects[0][0], 'aware') self.assertEqual(objects[0][1], _getDottedName(aware.__class__)) filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'structure/.properties') self.assertEqual(content_type, 'text/plain') parser = ConfigParser() parser.readfp(StringIO(text)) defaults = parser.defaults() self.assertEqual(len(defaults), 2) self.assertEqual(defaults['title'], site.title) self.assertEqual(defaults['description'], site.description) filename, text, content_type = context._wrote[2] self.assertEqual(filename, 'structure/aware.csv') self.assertEqual(content_type, 'text/comma-separated-values') rows = [x for x in reader(StringIO(text))] self.assertEqual(len(rows), 2) self.assertEqual(rows[0][0], 'one') self.assertEqual(rows[0][1], 'two') self.assertEqual(rows[0][2], 'three') self.assertEqual(rows[1][0], 'four') self.assertEqual(rows[1][1], 'five') self.assertEqual(rows[1][2], 'six')
def ini2keys(fp): cp = ConfigParser() cp.optionxform = str cp.readfp(fp) default_keys = [x for x in cp.defaults()] keys = {'DEFAULT': default_keys} for section in cp.sections(): keys[section] = [ o for o in cp.options(section) if o not in default_keys ] del cp return keys
def test_as_ini_string_property(self): TITLE = 'String Property' DESCR = 'Another property' context = _makePropertied('string_property') context.title = TITLE context._setProperty('description', DESCR) adapter = self._getTargetClass()(context) text = adapter.as_ini() parser = ConfigParser() parser.readfp(StringIO(text)) self.failIf(parser.sections()) default_options = parser.defaults() self.assertEqual(len(default_options), 2) self.assertEqual(default_options['title'].strip(), TITLE) self.assertEqual(default_options['description'].strip(), DESCR)
def configurator(global_conf, **local_conf): config.here = global_conf.get('here') config.ini_file = global_conf.get('__file__') config.zope_conf = global_conf.get('zope_conf') configparser = ConfigParser() configparser.read(config.ini_file) # building 2D dicts parsed = dict() for key, value in local_conf.iteritems(): if configparser.has_section(value): parsed[key] = dict([(o, configparser.get(value, o),) for o in configparser.options(value) if not o in configparser.defaults().keys()]) config.local_configuration = local_conf config.local_configuration.update(parsed)
def parse_config(self): """ Parses the config file """ cfg = ConfigParser() cfg.read('/etc/vcs-post-receive/post-receive.cfg') defaults = cfg.defaults() self.bugzilla_url = defaults['bugzilla_url'] self.rest_uri = defaults['rest_uri'] self.netrc = defaults['netrc'] self.vcsopts.proxy = defaults['proxy'] self.vcs_conf = {} for vcs in self.supported_vcs: self.__dict__[vcs] = {} self.__dict__[vcs]['vcsurl'] = cfg.get(vcs, 'vcsurl') self.__dict__[vcs]['rootdir'] = cfg.get(vcs, 'rootdir')
def load_environment(global_conf, app_conf): """Configure the Pylons environment via the ``pylons.config`` object """ config = PylonsConfig() # Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) paths = dict(root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, 'public'), templates=[os.path.join(root, 'templates')]) # import our private.ini that holds keys, etc imp = global_conf.get('import') if imp: cp = ConfigParser() cp.read(imp) global_conf.update(cp.defaults()) if cp.has_section('APP'): app_conf.update(cp.items('APP')) # Initialize config with the basic options config.init_app(global_conf, app_conf, package='linkdrop', paths=paths) config['routes.map'] = make_map(config) config['pylons.app_globals'] = app_globals.Globals(config) import linkdrop.lib.helpers as h config['pylons.h'] = h # Setup cache object as early as possible import pylons pylons.cache._push_object(config['pylons.app_globals'].cache) # Create the Mako TemplateLookup, with the default auto-escaping config['pylons.app_globals'].mako_lookup = TemplateLookup( directories=paths['templates'], error_handler=handle_mako_error, module_directory=os.path.join(app_conf['cache_dir'], 'templates'), input_encoding='utf-8', default_filters=['escape'], imports=['from webhelpers.html import escape']) # CONFIGURATION OPTIONS HERE (note: all config options will override # any Pylons config options) return config
def test_export_site_with_exportable_simple_items(self): from Products.GenericSetup.utils import _getDottedName self._setUpAdapters() ITEM_IDS = ('foo', 'bar', 'baz') site = _makeFolder('site') site.title = 'AAA' site._setProperty('description', 'BBB') aware = _makeINIAware('aside') dotted = _getDottedName(aware.__class__) for id in ITEM_IDS: site._setObject(id, _makeINIAware(id)) context = DummyExportContext(site) exporter = self._getExporter() exporter(context) self.assertEqual(len(context._wrote), 2 + len(ITEM_IDS)) filename, text, content_type = context._wrote[0] self.assertEqual(filename, 'structure/.objects') self.assertEqual(content_type, 'text/comma-separated-values') objects = [x for x in reader(StringIO(text))] self.assertEqual(len(objects), 3) for index in range(len(ITEM_IDS)): self.assertEqual(objects[index][0], ITEM_IDS[index]) self.assertEqual(objects[index][1], dotted) filename, text, content_type = context._wrote[index+2] self.assertEqual(filename, 'structure/%s.ini' % ITEM_IDS[index]) object = site._getOb(ITEM_IDS[index]) self.assertEqual(text.strip(), object.as_ini().strip()) self.assertEqual(content_type, 'text/plain') filename, text, content_type = context._wrote[1] self.assertEqual(filename, 'structure/.properties') self.assertEqual(content_type, 'text/plain') parser = ConfigParser() parser.readfp(StringIO(text)) defaults = parser.defaults() self.assertEqual(len(defaults), 2) self.assertEqual(defaults['title'], 'AAA') self.assertEqual(defaults['description'], 'BBB')
def parse(parser, args = None): parser.add_option("-o", "--output", action = "store", help="write output to file") parser.add_option("-i", "--ini", action = "store", help="load settings from INI file") parser.add_option("-j", "--json", action = "store", help="load settings from JSON file") parser.add_option("-y", "--yaml", action = "store", help="load settings from YAML file") (options, args) = parser.parse_args(args) d = {} if options.ini: from ConfigParser import ConfigParser conf = ConfigParser() if options.ini == '-': cfg = sys.stdin else: cfg = file(options.ini) conf.readfp(cfg) d.update(conf.defaults()) for sect in conf.sections(): d[sect] = dict(conf.items(sect)) if options.json: import json if options.json == '-': cfg = sys.stdin else: cfg = file(options.json) d.update(json.load(cfg)) if options.yaml: import yaml if options.yaml == '-': cfg = sys.stdin else: cfg = file(options.yaml) d.update(yaml.load(cfg)) for arg in args: key, val = [s.strip() for s in arg.split('=', 1)] d[key] = val options.data = d return options
def test_as_ini_other_properties(self): from DateTime.DateTime import DateTime INTPROP = 42 FLOATPROP = 3.1415926 DATESTR = '2005-11-07T12:00:00.000Z' context = _makePropertied('string_property') context._properties = () context._setProperty('int_prop', INTPROP, 'int') context._setProperty('float_prop', FLOATPROP, 'float') context._setProperty('date_prop', DateTime(DATESTR), 'date') adapter = self._getTargetClass()(context) text = adapter.as_ini() parser = ConfigParser() parser.readfp(StringIO(text)) self.failIf(parser.sections()) default_options = parser.defaults() self.assertEqual(len(default_options), 3) self.assertEqual(default_options['int_prop'], str(INTPROP)) self.assertEqual(default_options['float_prop'], str(FLOATPROP)) self.assertEqual(default_options['date_prop'], str(DateTime(DATESTR)))
def from_file(file_name): conf = ConfigParser(defaults=DEFAULT_CONF) try: conf.read(file_name) except Error: stderr.write("Error reading config file. Please ensure that the file exists, has correct permissions," "and is a valid python config file") stderr.flush() raise conf_dict = conf.defaults() typed_config_list = [] # The ugly try-catch is required due to a quirk in literal_eval of plain strings for k,v in conf_dict.items(): try: typed_val = literal_eval(v) except ValueError: typed_val = "'" + v + "'" typed_config_list.append((k,typed_val)) merged_dict = OrderedDict(dict(DEFAULT_CONF.items() + typed_config_list)) return namedtuple_from_dict(merged_dict)
def makeone(self, xtra=None, index_name='test-func-index', count=None): from cheeseprism.wsgiapp import main cp = ConfigParser(dict(here=self.base)) with open(resource_spec(self.devini)) as fp: cp.readfp(fp) defaults = dict((x, cp.get('DEFAULT', x)) for x in cp.defaults()) count = count is None and self.count or count self.idxpath = index_path = self.base / ("%s-%s" %(count, index_name)) settings = { 'cheeseprism.file_root': index_path, 'cheeseprism.data_json': 'data.json' } settings = xtra and dict(settings, **xtra) or settings app = main(defaults, **settings) self.executor = app.registry['cp.executor'] from webtest import TestApp return TestApp(app)
class ConfigDict: """Singleton style/static initialisation wrapper thing""" def __init__(self): self.configdict = ConfigParser() foundini = False paths = (os.path.expanduser('~/.uploadr.ini'), os.path.abspath('uploadr.ini')) for filename in paths: if os.path.exists(filename): print 'using uploadr.ini file "%s"' % os.path.abspath(filename) self.configdict.read(filename) foundini = True break if not foundini: raise IOError('Missing configuration file: ' + ' '.join(paths)) def get(self, configparam, default=None): """get the value from the ini file's default section.""" defaults = self.configdict.defaults() if configparam in defaults: return defaults[configparam] if default: return default raise KeyError(configparam)
import logging import logging.config import os from ConfigParser import ConfigParser DEBUG = True log_conf_path = os.path.dirname(os.path.abspath(__file__)) logging.config.fileConfig(log_conf_path + "/logging.cfg") logger = logging.getLogger("root") if DEBUG else logging.getLogger("Test") conf = ConfigParser() conf.read(log_conf_path + "/project.cfg") if __name__ == "__main__": print conf.get("DEFAULT", "test") print conf.defaults() print conf.sections()
def main(conffile, logs, legends, outdir, verbose): """ Produce plots from given """ dataset = [d for f, d in logs] config = ConfigParser() config.read(conffile) for s in config.sections(): p = Plot(name = s, outdir = outdir) # defaults for d, v in config.defaults().items(): if d != 'encoding': p.__dict__[d] = v else: encoding = v # stats # conf: 200.count, 400.count # result: [["200", "count"], ["400", "count"]] try: stats = [x.strip().rsplit('.', 1) for x in config.get(s, 'stats').split(' ')] except: print 'error: unable to read plot "%s" stats' % s continue if config.has_option(s, 'styles'): p.styles = [x.strip() for x in config.get(s, 'styles').split(' ')] if config.has_option(s, 'legend'): # this is the legend prefix$ l = [] count = 0 clegends = config.get(s, 'legend').decode(encoding).split(',') for f in logs: l += ['%s %s' % (x.strip(), legends[count]) \ for x in clegends] count += 1 p.legends = l if config.has_option(s, 'position'): # legend position according to matplotlib standard values (1-10) val = config.get(s, 'position').decode(encoding) if val.isdigit(): p.position = int(val) else: p.position = val if config.has_option(s, 'yfactor'): try: p.__dict__['yfactor'] = map(float,config.get(s, 'yfactor').decode(encoding).split(',')) except ValueError: print 'warning: %s yfactor not a number: %s' \ % (p.name, config.get(s, yfactor)) # Text parameters - to decode into specified encoding for attr in ['title', 'xlabel', 'ylabel', 'plottype', 'yscale']: if config.has_option(s, attr): cstring = config.get(s, attr).decode(encoding) p.__dict__[attr] = cstring # Numerical parameters for attr in ['xfactor', 'dpi', 'tn_dpi']: if config.has_option(s, attr): try: p.__dict__[attr] = config.getfloat(s, attr) except ValueError: print 'warning: %s %s not a number: %s' \ % (p.name, attr, config.get(s, attr)) outfile = p.plot(stats, dataset) if verbose: print 'Generated plot %s' % outfile