예제 #1
0
파일: base.py 프로젝트: abhi-bit/tsdb
    def __init__(self, root, mode="r+" ):
        """Load the TSDB located at ``path``.

            ``mode`` control the mode used by open() 
        """

        TSDBBase.__init__(self)
        self.path = "/"
        self.mode = mode
        self.fs = get_fs(root, [])
        self.load_metadata()
        self.chunk_prefixes = self.metadata.get('CHUNK_PREFIXES', [])
        if self.chunk_prefixes:
            # the root is listed as the first prefix, don't add it again
            self.fs = get_fs(root, self.chunk_prefixes[1:])

        if self.metadata.has_key('MEMCACHED_URI'):
            self.memcache = True
            try:
                import cmemcache as memcache
            except ImportError:
                try:
                    import memcache
                except:
                    self.memcache = False

            if self.memcache:
                self.memcache = memcache.Client([self.metadata['MEMCACHED_URI']])
예제 #2
0
파일: base.py 프로젝트: abhi-bit/tsdb
    def create(klass, path, metadata=None, chunk_prefixes=[]):
        """Create a new TSDB.

            ``chunk_prefixes``
                a list of alternate prefixes to locate chunks
        """

        if metadata is None:
            metadata = {}

        if os.path.exists(os.path.join(path, "TSDB")):
            raise TSDBAlreadyExistsError("database already exists")

        metadata["CREATION_TIME"] = time.time()
        metadata["CHUNK_PREFIXES"] = chunk_prefixes

        if not os.path.exists(path):
            os.mkdir(path)

        fs = get_fs(path, [])
        write_dict(fs, os.path.join("/", klass.tag), metadata)

        return klass(path)