예제 #1
0
def open_tc(filename, flag='c'):
    if has_db(filename):
        return get_db(filename)
    db = pytc.HDB()
    if flag == 'c':
        bflag = pytc.HDBOCREAT | pytc.HDBOWRITER | pytc.HDBOREADER | pytc.HDBONOLCK
    elif flag == 'r':
        bflag = pytc.HDBOREADER | pytc.HDBONOLCK
    else:
        raise Exception("need flag")
    db.open(filename, bflag)
    set_db(filename, db)
    return db
예제 #2
0
파일: store.py 프로젝트: cwt1/BioTK
    def __init__(self, path, mode="rw", columns=None):
        self._db = tc.HDB()
        self.mode = mode
        new = not os.path.exists(path)
        if "w" in mode:
            mode_flags = tc.HDBOWRITER | tc.HDBOCREAT
        elif "r" in mode:
            mode_flags = tc.HDBOREADER | tc.HDBONOLCK
        else:
            raise ValueError("Invalid value for mode: must be 'rw' or 'r'")
        self._db.open(path, mode_flags)
        self._meta = Metadata(self)

        if new:
            assert columns is not None
            self._meta["columns"] = list(columns)
            self._meta["rows"] = []
예제 #3
0
def tc_open(path, mode='a+', compress=True, makedirs=True):
    if makedirs:
        try:
            os.makedirs(os.path.dirname(path))
        except OSError:
            pass

    db = tc.HDB()
    if compress:
        db.tune(-1, -1, -1, tc.HDBTDEFLATE)
    db.open(
        path, {
            'r': tc.HDBOREADER,
            'w': tc.HDBOWRITER | tc.HDBOCREAT | tc.HDBOTRUNC,
            'a': tc.HDBOWRITER,
            'a+': tc.HDBOWRITER | tc.HDBOCREAT,
        }[mode])
    return db