Exemple #1
0
    def add_remote(self, database, subtree):
        database = truepath(database)
        subtree  = hashdb_sql.normalize(truepath(subtree)) if subtree not in ['//' or '\\\\'] else None
        if subtree == '/':
            subtree = None

        data = self.get_remote_by_path(database)
        if data == None:
            data = HashDatabase2.AttachRemote('remotedb%02d' % len(self._remotes), database, set())
        self._subtrees_add(data.subtress, subtree)
Exemple #2
0
    def add_local(self, database, target, subtree):
        database = truepath(database)
        target   = hashdb_sql.normalize(truepath(target)) if target not in ['//' or '\\\\'] else None
        if target in ['/', '//']:
            target = None

        subtree  = hashdb_sql.normalize(truepath(subtree)) if subtree not in ['//' or '\\\\'] else None
        if subtree in ['/', '//']:
            subtree = None

        data = self.get_local_by_path(database)
        if data == None:
            data = HashDatabase2.AttachLocal('localdb%02d' % len(self.locals), database, {})
            self._locals.append(data)
        self._subtrees_add(data.grafts.setdefault(target, set()), subtree)
Exemple #3
0
    def build_selects(self, sources=[None], columns=[], filters=[]):
        for source in sources:
            if source == None:
                found = self.build_selects_primary(columns, filters)
            elif isinstance(source, list):
                found = self.build_selects(source, columns, filters)
            elif isinstance(source, HashDatabase2.AttachLocal):
                found = self.build_selects_local(source, columns, filters)
            elif isinstance(source, HashDatabase2.AttachRemote):
                found = self.build_selects_remote(source, columns, filters)
            elif isinstance(source, basestring):
                source = truepath(source)
                local = self.get_local_by_path(source)
                if local != None:
                    found = self.build_selects_local(local, columns, filters)
                else:
                    remote = self.get_remote_by_path(source)
                    if remote != None:
                        found = self.build_selects_remote(remote, columns, filters)
                    else:
                        log.error('error: unknown database %r' % source)
                        continue
            else:
                raise ValueError, 'invalid source specified in sources list'

            for result in found:
                yield result
Exemple #4
0
 def get_remote_by_path(self, path):
     path = truepath(path)
     for remote in self.remote:
         if remote.database == path:
             return remote
Exemple #5
0
 def get_local_by_path(self, path):
     path = truepath(path)
     for local in self.locals:
         if local.database == path:
             return local