Ejemplo n.º 1
0
def getAttachableDatabases():
    global FILE_PATHS

    paths = getSearchPaths('eclectus')

    # include preset file paths
    for key in sorted(FILE_PATHS.keys()):
        for path in FILE_PATHS[key]:
            if path not in paths:
                paths.append(path)

    # add cjklib default paths
    paths.append('cjklib')

    return paths
Ejemplo n.º 2
0
    def _findAttachableDatabases(self, attachList, searchPaths=False):
        """
        Returns URLs for databases that can be attached to a given database.

        :type searchPaths: bool
        :param searchPaths: if ``True`` default search paths will be checked for
            attachable SQLite databases.
        """
        attachable = []
        for name in attachList:
            if '://' in name:
                # database url
                attachable.append(name)
            elif os.path.isabs(name):
                # path
                if not os.path.exists(name):
                    continue

                files = glob.glob(os.path.join(name, "*.db"))
                files.sort()
                attachable.extend([('sqlite:///%s' % f) for f in files])

            elif '/' not in name and '\\' not in name:
                # project name
                configuration = getDefaultConfiguration(name)

                # first add main database
                attachable.append(configuration['sqlalchemy.url'])

                # add attachables from the given project
                attach = configuration['attach']
                if name in attach:
                    # default search path
                    attach.remove(name)
                    if searchPaths:
                        attach.extend(getSearchPaths(name))

                attachable.extend(self._findAttachableDatabases(attach,
                    searchPaths))
            else:
                raise ValueError(("Invalid database reference '%s'."
                    " Check your 'attach' settings!")
                    % name)

        return attachable
Ejemplo n.º 3
0
    def _findAttachableDatabases(self, attachList, searchPaths=False):
        """
        Returns URLs for databases that can be attached to a given database.

        :type searchPaths: bool
        :param searchPaths: if ``True`` default search paths will be checked for
            attachable SQLite databases.
        """
        attachable = []
        for name in attachList:
            if '://' in name:
                # database url
                attachable.append(name)
            elif os.path.isabs(name):
                # path
                if not os.path.exists(name):
                    continue

                files = glob.glob(os.path.join(name, "*.db"))
                files.sort()
                attachable.extend([('sqlite:///%s' % f) for f in files])

            elif '/' not in name and '\\' not in name:
                # project name
                configuration = getDefaultConfiguration(name)

                # first add main database
                attachable.append(configuration['sqlalchemy.url'])

                # add attachables from the given project
                attach = configuration['attach']
                if name in attach:
                    # default search path
                    attach.remove(name)
                    if searchPaths:
                        attach.extend(getSearchPaths(name))

                attachable.extend(self._findAttachableDatabases(attach,
                    searchPaths))
            else:
                raise ValueError(("Invalid database reference '%s'."
                    " Check your 'attach' settings!")
                    % name)

        return attachable