コード例 #1
0
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
コード例 #2
0
ファイル: dbconnector.py プロジェクト: KentVu/cjklib
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
コード例 #3
0
ファイル: dbconnector.py プロジェクト: Phil-V/cjklib
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
コード例 #4
0
ファイル: __init__.py プロジェクト: KentVu/cjklib
    def __init__(self, **options):
        """
        To modify the behaviour of :class:`~cjklib.build.builder.TableBuilder`
        instances, global or local options can be specified, see
        :meth:`~cjklib.build.builder.TableBuilder.getBuilderOptions`.

        :keyword databaseUrl: database connection setting in the format
            ``driver://user:pass@host/database``.
        :keyword dbConnectInst: instance of a
            :class:`~cjklib.dbconnector.DatabaseConnector`
        :keyword dataPath: optional list of paths to the data file(s)
        :keyword quiet: if ``True`` no status information will be printed to
            stderr
        :keyword rebuildDepending: if ``True`` existing tables that depend on
            updated tables will be dropped and built from scratch
        :keyword rebuildExisting: if ``True`` existing tables will be
            dropped and built from scratch
        :keyword noFail: if ``True`` build process won't terminate even if one
            table fails to build
        :keyword prefer: list of :class:`~cjklib.build.builder.TableBuilder`
            names to prefer in conflicting cases
        :keyword additionalBuilders: list of externally provided TableBuilders
        :raise ValueError: if two different options from two different builder
            collide.
        """
        if "dataPath" not in options:
            # look for data underneath the build module
            projectDataPath = locateProjectFile("cjklib/data", "cjklib")
            if not projectDataPath:
                projectDataPath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../data")
            options["dataPath"] = [projectDataPath]

        elif isinstance(options["dataPath"], basestring):
            # wrap as list
            options["dataPath"] = [options["dataPath"]]

        self.quiet = options.get("quiet", False)
        """Controls status information printed to stderr"""
        self.rebuildDepending = options.pop("rebuildDepending", True)
        """Controls if tables that depend on updated tables will be rebuilt."""
        self.rebuildExisting = options.pop("rebuildExisting", True)
        """Controls if existing tables will be rebuilt."""
        self.noFail = options.pop("noFail", False)
        """Controls if build process terminate on failed tables."""
        # get connector to database
        databaseUrl = options.pop("databaseUrl", None)
        if "dbConnectInst" in options:
            self.db = options.pop("dbConnectInst")
        else:
            self.db = dbconnector.getDBConnector({"sqlalchemy.url": databaseUrl})
            """:class:`~cjklib.dbconnector.DatabaseConnector` instance"""

        # get TableBuilder classes
        tableBuilderClasses = DatabaseBuilder.getTableBuilderClasses(
            set(options.pop("prefer", [])), quiet=self.quiet, additionalBuilders=options.pop("additionalBuilders", [])
        )

        # build lookup
        self._tableBuilderLookup = {}
        for tableBuilder in tableBuilderClasses:
            if tableBuilder.PROVIDES in self._tableBuilderLookup:
                raise Exception("Table '%s' provided by several builders" % tableBuilder.PROVIDES)
            self._tableBuilderLookup[tableBuilder.PROVIDES] = tableBuilder

        # options for TableBuilders
        self.options = options
        """Table builder options dictionary"""
コード例 #5
0
ファイル: __init__.py プロジェクト: ninchanese/cjklib
    def __init__(self, **options):
        """
        To modify the behaviour of :class:`~cjklib.build.builder.TableBuilder`
        instances, global or local options can be specified, see
        :meth:`~cjklib.build.builder.TableBuilder.getBuilderOptions`.

        :keyword databaseUrl: database connection setting in the format
            ``driver://user:pass@host/database``.
        :keyword dbConnectInst: instance of a
            :class:`~cjklib.dbconnector.DatabaseConnector`
        :keyword dataPath: optional list of paths to the data file(s)
        :keyword quiet: if ``True`` no status information will be printed to
            stderr
        :keyword rebuildDepending: if ``True`` existing tables that depend on
            updated tables will be dropped and built from scratch
        :keyword rebuildExisting: if ``True`` existing tables will be
            dropped and built from scratch
        :keyword noFail: if ``True`` build process won't terminate even if one
            table fails to build
        :keyword prefer: list of :class:`~cjklib.build.builder.TableBuilder`
            names to prefer in conflicting cases
        :keyword additionalBuilders: list of externally provided TableBuilders
        :raise ValueError: if two different options from two different builder
            collide.
        """
        if 'dataPath' not in options:
            # look for data underneath the build module
            projectDataPath = locateProjectFile('cjklib/data', 'cjklib')
            if not projectDataPath:
                projectDataPath = os.path.join(
                    os.path.dirname(os.path.abspath(__file__)), '../data')
            options['dataPath'] = [projectDataPath]

        elif isinstance(options['dataPath'], str):
            # wrap as list
            options['dataPath'] = [options['dataPath']]

        self.quiet = options.get('quiet', False)
        """Controls status information printed to stderr"""
        self.rebuildDepending = options.pop('rebuildDepending', True)
        """Controls if tables that depend on updated tables will be rebuilt."""
        self.rebuildExisting = options.pop('rebuildExisting', True)
        """Controls if existing tables will be rebuilt."""
        self.noFail = options.pop('noFail', False)
        """Controls if build process terminate on failed tables."""
        # get connector to database
        databaseUrl = options.pop('databaseUrl', None)
        if 'dbConnectInst' in options:
            self.db = options.pop('dbConnectInst')
        else:
            self.db = dbconnector.getDBConnector(
                {'sqlalchemy.url': databaseUrl})
            """:class:`~cjklib.dbconnector.DatabaseConnector` instance"""

        # get TableBuilder classes
        tableBuilderClasses = DatabaseBuilder.getTableBuilderClasses(
            set(options.pop('prefer', [])), quiet=self.quiet,
            additionalBuilders=options.pop('additionalBuilders', []))

        # build lookup
        self._tableBuilderLookup = {}
        for tableBuilder in tableBuilderClasses:
            if tableBuilder.PROVIDES in self._tableBuilderLookup:
                raise Exception("Table '%s' provided by several builders" \
                    % tableBuilder.PROVIDES)
            self._tableBuilderLookup[tableBuilder.PROVIDES] = tableBuilder

        # options for TableBuilders
        self.options = options
        """Table builder options dictionary"""