def getBuilderConfigSettings(cls): """ Gets the builder settings from the section ``Builder`` from cjklib.conf. :rtype: dict :return: dictionary of builder options .. todo:: * Impl: Refactor, shares a lot of code with :mod:`cjklib.build.cli` """ configOptions = getConfigSettings('Builder') # don't convert to lowercase configparser.RawConfigParser.optionxform = lambda self, x: x config = configparser.RawConfigParser(configOptions) dictionaryTables = [clss.PROVIDES for clss in getDownloaderClasses()] options = {} for builder in build.DatabaseBuilder.getTableBuilderClasses( resolveConflicts=False): if builder.PROVIDES not in dictionaryTables: continue for option in builder.getDefaultOptions(): try: metadata = builder.getOptionMetaData(option) optionType = metadata.get('type', None) except KeyError: optionType = None for opt in [ option, '--%s-%s' % (builder.__name__, option), '--%s-%s' % (builder.PROVIDES, option) ]: if config.has_option(None, opt): if optionType == 'bool': value = config.getboolean(configparser.DEFAULTSECT, opt) elif optionType == 'int': value = config.getint(configparser.DEFAULTSECT, opt) elif optionType == 'float': value = config.getfloat(configparser.DEFAULTSECT, opt) else: value = config.get(configparser.DEFAULTSECT, opt) options[opt] = value return options
def getBuilderConfigSettings(cls): """ Gets the builder settings from the section ``Builder`` from cjklib.conf. :rtype: dict :return: dictionary of builder options .. todo:: * Impl: Refactor, shares a lot of code with :mod:`cjklib.build.cli` """ configOptions = getConfigSettings('Builder') # don't convert to lowercase configparser.RawConfigParser.optionxform = lambda self, x: x config = configparser.RawConfigParser(configOptions) dictionaryTables = [clss.PROVIDES for clss in getDownloaderClasses()] options = {} for builder in build.DatabaseBuilder.getTableBuilderClasses( resolveConflicts=False): if builder.PROVIDES not in dictionaryTables: continue for option in builder.getDefaultOptions(): try: metadata = builder.getOptionMetaData(option) optionType = metadata.get('type', None) except KeyError: optionType = None for opt in [option, '--%s-%s' % (builder.__name__, option), '--%s-%s' % (builder.PROVIDES, option)]: if config.has_option(None, opt): if optionType == 'bool': value = config.getboolean(configparser.DEFAULTSECT, opt) elif optionType == 'int': value = config.getint(configparser.DEFAULTSECT, opt) elif optionType == 'float': value = config.getfloat(configparser.DEFAULTSECT, opt) else: value = config.get(configparser.DEFAULTSECT, opt) options[opt] = value return options
def getBuilderConfigSettings(cls): """ Gets the builder settings from the section ``Builder`` from ```cjklib.conf```. :rtype: dict :return: dictionary of builder options """ configOptions = getConfigSettings('Builder') # don't convert to lowercase ConfigParser.RawConfigParser.optionxform = lambda self, x: x config = ConfigParser.RawConfigParser(configOptions) options = {} for builder in build.DatabaseBuilder.getTableBuilderClasses( resolveConflicts=False): if not builder.PROVIDES: continue for option in builder.getDefaultOptions(): try: metadata = builder.getOptionMetaData(option) optionType = metadata.get('type', None) except KeyError: optionType = None for opt in [ option, '--%s-%s' % (builder.__name__, option), '--%s-%s' % (builder.PROVIDES, option) ]: if config.has_option(None, opt): if optionType == 'bool': value = config.getboolean(ConfigParser.DEFAULTSECT, opt) elif optionType == 'int': value = config.getint(ConfigParser.DEFAULTSECT, opt) elif optionType == 'float': value = config.getfloat(ConfigParser.DEFAULTSECT, opt) else: value = config.get(ConfigParser.DEFAULTSECT, opt) options[opt] = value return options
def getBuilderConfigSettings(cls): """ Gets the builder settings from the section ``Builder`` from ```cjklib.conf```. :rtype: dict :return: dictionary of builder options """ configOptions = getConfigSettings('Builder') # don't convert to lowercase ConfigParser.RawConfigParser.optionxform = lambda self, x: x config = ConfigParser.RawConfigParser(configOptions) options = {} for builder in build.DatabaseBuilder.getTableBuilderClasses( resolveConflicts=False): if not builder.PROVIDES: continue for option in builder.getDefaultOptions(): try: metadata = builder.getOptionMetaData(option) optionType = metadata.get('type', None) except KeyError: optionType = None for opt in [option, '--%s-%s' % (builder.__name__, option), '--%s-%s' % (builder.PROVIDES, option)]: if config.has_option(None, opt): if optionType == 'bool': value = config.getboolean(ConfigParser.DEFAULTSECT, opt) elif optionType == 'int': value = config.getint(ConfigParser.DEFAULTSECT, opt) elif optionType == 'float': value = config.getfloat(ConfigParser.DEFAULTSECT, opt) else: value = config.get(ConfigParser.DEFAULTSECT, opt) options[opt] = value return options
def getDefaultConfiguration(projectName='cjklib'): """ Gets the default configuration for the given project. Settings are read from a configuration file. By default an URL to a database ``PROJECTNAME.db`` in the project's folder is returned and the project's default directories are searched for attachable databases. .. versionadded:: 0.3 :type projectName: str :param projectName: name of project which will be used in search for the configuration and as the name of the default database """ # try to read from config configuration = getConfigSettings('Connection', projectName) if 'url' in configuration: url = configuration.pop('url') if 'sqlalchemy.url' not in configuration: configuration['sqlalchemy.url'] = url if 'sqlalchemy.url' not in configuration: dbFile = locateProjectFile( '%(proj)s/%(proj)s.db' % {'proj': projectName}, projectName) if not dbFile: # fall back to the directory of this file, only works for cjklib libdir = os.path.dirname(os.path.abspath(__file__)) dbFile = os.path.join(libdir, '%(proj)s.db' % {'proj': projectName}) configuration['sqlalchemy.url'] = 'sqlite:///%s' % dbFile if 'attach' in configuration: configuration['attach'] = [ name for name in configuration['attach'].split('\n') if name ] else: configuration['attach'] = [projectName] return configuration
def getDefaultConfiguration(projectName='cjklib'): """ Gets the default configuration for the given project. Settings are read from a configuration file. By default an URL to a database ``PROJECTNAME.db`` in the project's folder is returned and the project's default directories are searched for attachable databases. .. versionadded:: 0.3 :type projectName: str :param projectName: name of project which will be used in search for the configuration and as the name of the default database """ # try to read from config configuration = getConfigSettings('Connection', projectName) if 'url' in configuration: url = configuration.pop('url') if 'sqlalchemy.url' not in configuration: configuration['sqlalchemy.url'] = url if 'sqlalchemy.url' not in configuration: dbFile = locateProjectFile( '%(proj)s/%(proj)s.db' % {'proj': projectName}, projectName) if not dbFile: # fall back to the directory of this file, only works for cjklib libdir = os.path.dirname(os.path.abspath(__file__)) dbFile = os.path.join(libdir, '%(proj)s.db' % {'proj': projectName}) configuration['sqlalchemy.url'] = 'sqlite:///%s' % dbFile if 'attach' in configuration: configuration['attach'] = [name for name in configuration['attach'].split('\n') if name] else: configuration['attach'] = [projectName] return configuration
def getDefaultConfiguration(projectName="cjklib"): """ Gets the default configuration for the given project. Settings are read from a configuration file. By default an URL to a database ``PROJECTNAME.db`` in the project's folder is returned and the project's default directories are searched for attachable databases. .. versionadded:: 0.3 :type projectName: str :param projectName: name of project which will be used in search for the configuration and as the name of the default database """ # try to read from config configuration = getConfigSettings("Connection", projectName) if "url" in configuration: url = configuration.pop("url") if "sqlalchemy.url" not in configuration: configuration["sqlalchemy.url"] = url if "sqlalchemy.url" not in configuration: dbFile = locateProjectFile("%(proj)s/%(proj)s.db" % {"proj": projectName}, projectName) if not dbFile: # fall back to the directory of this file, only works for cjklib libdir = os.path.dirname(os.path.abspath(__file__)) dbFile = os.path.join(libdir, "%(proj)s.db" % {"proj": projectName}) configuration["sqlalchemy.url"] = "sqlite:///%s" % dbFile if "attach" in configuration: configuration["attach"] = [name for name in configuration["attach"].split("\n") if name] else: configuration["attach"] = [projectName] return configuration