當前位置: 首頁>>代碼示例>>Python>>正文


Python Database.destroy方法代碼示例

本文整理匯總了Python中CodernityDB.database.Database.destroy方法的典型用法代碼示例。如果您正苦於以下問題:Python Database.destroy方法的具體用法?Python Database.destroy怎麽用?Python Database.destroy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CodernityDB.database.Database的用法示例。


在下文中一共展示了Database.destroy方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Store

# 需要導入模塊: from CodernityDB.database import Database [as 別名]
# 或者: from CodernityDB.database.Database import destroy [as 別名]

#.........這裏部分代碼省略.........
            return object_type

    def get_object(self, source_path, hash, side_dict):
        return StoreObject.create(source_path, self, side_dict)

    def get_unzipped_tempFile(self, hash, tempFile):
        gzipFile = gzip.open(self.get_object_path(hash))
        temp = open(tempFile.name, "w+")
        while True:
            block = gzipFile.read()
            temp.write(block)
            if not block:
                break
        temp.seek(0)
        gzipFile.close()
        return temp

    def get_hash(self, src_file, block_size = constants.CONST_BLOCK_SIZE):
        file_hash = hashlib.sha1()
        with open(src_file, "rb") as SF:
            while True:
                block = SF.read(block_size)
                file_hash.update(block)
                if not block : break
            SF.close()
        return file_hash.hexdigest()

    def incIndex(self, hash):
        if hash in self.objects_counter:
            self.objects_counter[hash]["value"] = self.objects_counter[hash]["value"] + 1
            return self.objects_counter[hash]["value"]
        else:
            try:
                element = self.db.get('hash', hash, with_doc=True)
                element = element['doc']
                self.objects_counter[hash] = {"value":element['pointer'] + 1, "operation":"update"}
                return element['pointer'] + 1
            except RecordNotFound:
                self.objects_counter[hash] = {"value":1, "operation":"insert"}
                return 1

    def decIndex(self, hash):
        if hash in self.objects_counter:
            self.objects_counter[hash]["value"] = self.objects_counter[hash]["value"] - 1
            return self.objects_counter[hash]["value"]
        else:
            try:
                element = self.db.get('hash', hash, with_doc=True)
                element = element['doc']
                self.objects_counter[hash] = {"value":element['pointer'] - 1, "operation":"update"}
                return element['pointer'] - 1
            except RecordNotFound:
                return

    def getIndex(self, hash):
        if hash in self.objects_counter:
            return self.objects_counter[hash]["value"]
        else:
            try:
                element = self.db.get('hash', hash, with_doc=True)
                element = element['doc']
                return element['pointer']
            except RecordNotFound:
                return 0


    def rebuildDB(self):
        self.db.destroy()
        self.init_store_db()
        backups = self.get_all_backups()
        for backup in backups:
            tmp = ExistingBackup('', self, backup)
            tmp.recovery_backup(True)

    def removeObject(self, hash):
        if len(os.listdir(self.get_objet_dir_path(hash))) == 2:
            self.write_to_journal("rmdir " + self.get_objet_dir_path(hash))
        else:
            self.write_to_journal("remove " + self.get_object_path(hash))
            self.write_to_journal("remove " + self.get_object_header_path(hash))
        self.write_to_journal("delete " + hash)

    def removeBackup(self, time):
        backup = ExistingBackup("", self, time).get_root_object()
        self.is_journal_complete()
        backup.remove()
        os.remove(self.get_backup_path(time))
        newest = self.getNewestBackupTime()
        if newest != None:
            self.save_data(self.get_journal_latest_path(), newest)
        self.finish_journal()
        self.commit()

    def getNewestBackupTime(self):
        backups_path = self.get_backups_path()
        backups = sorted(os.listdir(backups_path))
        backups.remove("latest")
        if len(backups) > 0:
            return backups[len(backups) - 1]
        return None
開發者ID:PapajaLM,項目名稱:Backuping,代碼行數:104,代碼來源:store.py


注:本文中的CodernityDB.database.Database.destroy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。