Exemplo n.º 1
0
    def __init__(self, prefixes=None, isMonolithic = True, indexerQueueSize = 0):
        """Create a new Thawab instance given a user writable directory and an optional system-wide read-only directory

    prefixes a list of directories all are read-only except the first
    the first writable directory can be 
        os.path.expanduser('~/.thawab')
        os.path.join([os.path.dirname(sys.argv[0]),'..','data'])
    
    isMonolithic = True if we should use locks and reconnect to sqlite
    
    indexerQueueSize is the size of threaded index queue (0 infinite, -1 disabled)

the first thing you should do is to call loadMCache()
"""
        if not prefixes:
            prefixes = guess_prefixes()
        try:
            if not os.path.isdir(prefixes[0]):
                os.makedirs(prefixes[0])
        except:
            raise OSError
        self.prefixes = filter(lambda i:os.path.isdir(i),
                               [os.path.realpath(os.path.abspath(p)) for p in prefixes])
        # make sure it's unique
        p = self.prefixes[0]
        s = set(self.prefixes[1:])
        if p in s:
            s.remove(p)
        if len(s)<len(self.prefixes)-1:
            self.prefixes=[p]+sorted(list(s))
        #print self.prefixes
        self.othman = othman
        self.__meta = None
        self.read_only = self.assertManagedTree()
        self.conf = self.prase_conf()
        self.searchEngine = SearchEngine(self)
        self.user_db = UserDb(self, os.path.join(self.prefixes[0], "user.db"))
        if indexerQueueSize >= 0:
            self.asyncIndexer = AsyncIndex(self.searchEngine, indexerQueueSize)
        else:
            self.asyncIndexer = None

        self.isMonolithic = isMonolithic
        if not self.isMonolithic:
            import threading
            lock1 = threading.Lock()
        else:
            lock1 = None
        self.kutubCache = ObjectsCache(lock = lock1)