Ejemplo n.º 1
0
    def __init__(self, secret, directory, special_key, conf_dir=None, N=3):
        """ Initialize the RSCoin server"""
        self.special_key = special_key
        self.key = rscoin.Key(secret, public=False)
        self.directory = sorted(directory)
        keyID = self.key.id()[:10]
        self.N = N

        # Open the databases
        self.dbname = 'keys-%s' % hexlify(keyID)
        self.logname = 'log-%s' % hexlify(keyID)
        
        self.logger = RSCLogger()
        
        
        
        if conf_dir:
            self.dbname = join(conf_dir, self.dbname)
            self.logname = join(conf_dir, self.logname)

        if RSCFactory._sync:                                
            self.db = dbm.open(self.dbname, 'c')
            self.log = dbm.open(self.logname, 'c')
            self.log["hashhead"] = ""
            self.log["lampClock"] = "0"
            ###????? RSCFactory._sync is set for synchronous writing to the disk          
            ### c mode means for both writing and reading, if the file does not exist, it will be created
        else:
            self.db = {} 
            self.log = {}
            self.log["hashhead"] = ""
            self.log["lampClock"] = "0"
Ejemplo n.º 2
0
    def __init__(self, secret, directory, special_key, conf_dir=None, N=3):
        """ Initialize the RSCoin server"""
        self.special_key = special_key
        self.key = rscoin.Key(secret, public=False)
        self.directory = sorted(directory)
        keyID = self.key.id()[:10]
        self.N = N

        # Open the databases
        self.dbname = 'keys-%s' % hexlify(keyID)
        self.logname = 'log-%s' % hexlify(keyID)

        if conf_dir:
            self.dbname = join(conf_dir, self.dbname)
            self.logname = join(conf_dir, self.logname)

        if RSCFactory._sync:
            self.db = dbm.open(self.dbname, 'c')
            self.log = dbm.open(self.logname, 'c')
        else:
            self.db = {}
            self.log = {}
Ejemplo n.º 3
0
    def __init__(self, secret, directory, special_key, conf_dir=None, N=3):
        """ Initialize the RSCoin server"""
        self.special_key = special_key
        self.key = rscoin.Key(secret, public=False)
        self.directory = sorted(directory)
        keyID = self.key.id()[:10]
        self.N = N

        # Open the databases
        self.dbname = 'keys-%s' % hexlify(keyID)
        self.logname = 'log-%s' % hexlify(keyID)
        
        if conf_dir:
            self.dbname = join(conf_dir, self.dbname)
            self.logname = join(conf_dir, self.logname)

        if RSCFactory._sync:
            self.db = dbm.open(self.dbname, 'c')
            self.log = dbm.open(self.logname, 'c')
        else:
            self.db = {} 
            self.log = {}
Ejemplo n.º 4
0
    def _loadIndex(self, compress=False):
        """load complete index into memory.

        if compress is set to true, the index will not be loaded,
        but a compressed index will be created instead.
        """
        if self.mMethod == "uncompressed":
            self.mDatabaseFile = open(self.mDbname, "r")
        elif self.mMethod == "dictzip":
            from . import dictzip
            self.mDatabaseFile = dictzip.GzipFile(self.mDbname)
        elif self.mMethod == "lzo":
            import lzo
            self.mDatabaseFile = Uncompressor(self.mDbname, lzo.decompress)
        elif self.mMethod == "gzip":
            self.mDatabaseFile = Uncompressor(self.mDbname, gzip_demangler)
        elif self.mMethod == "zlib":
            self.mDatabaseFile = Uncompressor(self.mDbname, zlib.decompress)
        elif self.mMethod == "bzip2":
            import bz2
            self.mDatabaseFile = Uncompressor(self.mDbname, bz2.decompress)
        elif self.mMethod == "debug":
            self.mDatabaseFile = Uncompressor(self.mDbname + ".debug",
                                              lambda x: x)

        filename_index = self.mNameIndex + ".dbm"

        if compress:
            # if os.path.exists(filename_index):
            #     raise OSError("file %s already exists" % filename_index)
            self.mIndex = dbm.open(filename_index, "n")
        elif os.path.exists(filename_index):
            self.mIndex = dbm.open(filename_index, "r")
            if len(self.mIndex) == 0:
                raise ValueError(
                    "length of index is 0, possibly a python version problem")
            self.mIsLoaded = True
            return
        else:
            self.mIndex = {}

        for line in open(self.mNameIndex, "r"):

            data = line[:-1].split("\t")

            if len(data) == 2:
                # ignore synonyms of non-existent contigs
                identifier = data[1]
                if data[0] not in self.mIndex:
                    continue
                self.mSynonyms[identifier] = data[0]
            else:
                # index with random access points
                if len(data) > 4:
                    (identifier, pos_id, block_size, lsequence) = data[0], int(
                        data[1]), int(data[2]), int(data[-1])
                    points = list(map(int, data[3:-1]))
                    self.mIndex[identifier] = (pos_id, block_size, lsequence,
                                               points)
                else:
                    (identifier, pos_id, pos_seq, lsequence) = data[0], int(
                        data[1]), int(data[2]), int(data[-1])
                    self.mIndex[identifier] = struct.pack(
                        "QQi", pos_id, pos_seq, lsequence)

        self._addSynonyms()
        self.mIsLoaded = True
Ejemplo n.º 5
0
    def _loadIndex(self, compress=False):
        """load complete index into memory.

        if compress is set to true, the index will not be loaded,
        but a compressed index will be created instead.
        """
        if self.mMethod == "uncompressed":
            self.mDatabaseFile = open(self.mDbname, "r")
        elif self.mMethod == "dictzip":
            from . import dictzip

            self.mDatabaseFile = dictzip.GzipFile(self.mDbname)
        elif self.mMethod == "lzo":
            import lzo

            self.mDatabaseFile = Uncompressor(self.mDbname, lzo.decompress)
        elif self.mMethod == "gzip":
            self.mDatabaseFile = Uncompressor(self.mDbname, gzip_demangler)
        elif self.mMethod == "zlib":
            self.mDatabaseFile = Uncompressor(self.mDbname, zlib.decompress)
        elif self.mMethod == "bzip2":
            import bz2

            self.mDatabaseFile = Uncompressor(self.mDbname, bz2.decompress)
        elif self.mMethod == "debug":
            self.mDatabaseFile = Uncompressor(self.mDbname + ".debug", lambda x: x)

        filename_index = self.mNameIndex + ".dbm"

        if compress:
            # if os.path.exists(filename_index):
            #     raise OSError("file %s already exists" % filename_index)
            self.mIndex = dbm.open(filename_index, "n")
        elif os.path.exists(filename_index):
            self.mIndex = dbm.open(filename_index, "r")
            if len(self.mIndex) == 0:
                raise ValueError("length of index is 0, possibly a python version problem")
            self.mIsLoaded = True
            return
        else:
            self.mIndex = {}

        for line in open(self.mNameIndex, "r"):

            data = line[:-1].split("\t")

            if len(data) == 2:
                # ignore synonyms of non-existent contigs
                identifier = data[1]
                if data[0] not in self.mIndex:
                    continue
                self.mSynonyms[identifier] = data[0]
            else:
                # index with random access points
                if len(data) > 4:
                    (identifier, pos_id, block_size, lsequence) = data[0], int(data[1]), int(data[2]), int(data[-1])
                    points = list(map(int, data[3:-1]))
                    self.mIndex[identifier] = (pos_id, block_size, lsequence, points)
                else:
                    (identifier, pos_id, pos_seq, lsequence) = data[0], int(data[1]), int(data[2]), int(data[-1])
                    self.mIndex[identifier] = struct.pack("QQi", pos_id, pos_seq, lsequence)

        self._addSynonyms()
        self.mIsLoaded = True