本文整理汇总了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