本文整理汇总了Python中ZODB.FileStorage.FileStorage.cleanup方法的典型用法代码示例。如果您正苦于以下问题:Python FileStorage.cleanup方法的具体用法?Python FileStorage.cleanup怎么用?Python FileStorage.cleanup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZODB.FileStorage.FileStorage
的用法示例。
在下文中一共展示了FileStorage.cleanup方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: HistoryFreeFromFileStorage
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import cleanup [as 别名]
class HistoryFreeFromFileStorage(
RelStorageTestBase,
UndoableRecoveryStorage,
):
keep_history = False
def setUp(self):
self.open(create=1)
self._storage.zap_all()
self._dst = self._storage
self._storage = FileStorage("Source.fs", create=True)
def tearDown(self):
self._storage.close()
self._dst.close()
self._storage.cleanup()
self._dst.cleanup()
def new_dest(self):
return self._dst
def compare(self, src, dest):
# The dest storage has a truncated copy of dest, so
# use compare_truncated() instead of compare_exact().
self.compare_truncated(src, dest)
示例2: tearDown
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import cleanup [as 别名]
def tearDown(self):
self.storage.close()
if self.recovered is not None:
self.recovered.close()
self.storage.cleanup()
temp = FileStorage(self.dest)
temp.close()
temp.cleanup()
示例3: HistoryFreeToFileStorage
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import cleanup [as 别名]
class HistoryFreeToFileStorage(RelStorageTestBase, BasicRecoveryStorage):
keep_history = False
def setUp(self):
self._storage = self.make_storage()
self._dst = FileStorage("Dest.fs", create=True)
def tearDown(self):
self._storage.close()
self._dst.close()
self._storage.cleanup()
self._dst.cleanup()
def new_dest(self):
return FileStorage("Dest.fs")
示例4: HistoryFreeToFileStorage
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import cleanup [as 别名]
class HistoryFreeToFileStorage(RelStorageTestBase,
BasicRecoveryStorage):
# pylint:disable=abstract-method,too-many-ancestors
keep_history = False
def setUp(self):
self._storage = self.make_storage()
self._dst = FileStorage("Dest.fs", create=True)
def tearDown(self):
self._storage.close()
self._dst.close()
self._storage.cleanup()
self._dst.cleanup()
def new_dest(self):
return FileStorage('Dest.fs')
示例5: HistoryPreservingToFileStorage
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import cleanup [as 别名]
class HistoryPreservingToFileStorage(RelStorageTestBase,
UndoableRecoveryStorage):
# pylint:disable=too-many-ancestors,abstract-method,too-many-locals
keep_history = True
def setUp(self):
super(HistoryPreservingToFileStorage, self).setUp()
self._storage = self.make_storage()
self._dst = FileStorage("Dest.fs", create=True)
def tearDown(self):
self._dst.close()
self._dst.cleanup()
super(HistoryPreservingToFileStorage, self).tearDown()
def new_dest(self):
return FileStorage('Dest.fs')
示例6: HistoryPreservingFromFileStorage
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import cleanup [as 别名]
class HistoryPreservingFromFileStorage(
RelStorageTestBase,
UndoableRecoveryStorage,
):
keep_history = True
def setUp(self):
self._dst = self.make_storage()
self._storage = FileStorage("Source.fs", create=True)
def tearDown(self):
self._storage.close()
self._dst.close()
self._storage.cleanup()
self._dst.cleanup()
def new_dest(self):
return self._dst
示例7: HistoryPreservingToFileStorage
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import cleanup [as 别名]
class HistoryPreservingToFileStorage(
RelStorageTestBase,
UndoableRecoveryStorage,
):
keep_history = True
def setUp(self):
self.open(create=1)
self._storage.zap_all()
self._dst = FileStorage("Dest.fs", create=True)
def tearDown(self):
self._storage.close()
self._dst.close()
self._storage.cleanup()
self._dst.cleanup()
def new_dest(self):
return FileStorage('Dest.fs')
示例8: HistoryFreeFromFileStorage
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import cleanup [as 别名]
class HistoryFreeFromFileStorage(RelStorageTestBase,
UndoableRecoveryStorage):
# pylint:disable=abstract-method,too-many-ancestors
keep_history = False
def setUp(self):
self._dst = self._storage
self._storage = FileStorage("Source.fs", create=True)
def tearDown(self):
self._storage.close()
self._dst.close()
self._storage.cleanup()
self._dst.cleanup()
def new_dest(self):
return self._dst
def compare(self, src, dest):
# The dest storage has a truncated copy of dest, so
# use compare_truncated() instead of compare_exact().
self.compare_truncated(src, dest)
示例9: RecoverTest
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import cleanup [as 别名]
class RecoverTest(unittest.TestCase):
level = 2
path = None
def setUp(self):
self.path = tempfile.mktemp(suffix=".fs")
self.storage = FileStorage(self.path)
self.populate()
self.dest = tempfile.mktemp(suffix=".fs")
self.recovered = None
def tearDown(self):
self.storage.close()
if self.recovered is not None:
self.recovered.close()
self.storage.cleanup()
temp = FileStorage(self.dest)
temp.close()
temp.cleanup()
def populate(self):
db = ZODB.DB(self.storage)
cn = db.open()
rt = cn.root()
# Create a bunch of objects; the Data.fs is about 100KB.
for i in range(50):
d = rt[i] = PersistentMapping()
transaction.commit()
for j in range(50):
d[j] = "a" * j
transaction.commit()
def damage(self, num, size):
self.storage.close()
# Drop size null bytes into num random spots.
for i in range(num):
offset = random.randint(0, self.storage._pos - size)
f = open(self.path, "a+b")
f.seek(offset)
f.write("\0" * size)
f.close()
ITERATIONS = 5
# Run recovery, from self.path to self.dest. Return whatever
# recovery printed to stdout, as a string.
def recover(self):
orig_stdout = sys.stdout
faux_stdout = StringIO.StringIO()
try:
sys.stdout = faux_stdout
try:
ZODB.fsrecover.recover(self.path, self.dest,
verbose=0, partial=True, force=False, pack=1)
except SystemExit:
raise RuntimeError("recover tried to exit")
finally:
sys.stdout = orig_stdout
return faux_stdout.getvalue()
# Caution: because recovery is robust against many kinds of damage,
# it's almost impossible for a call to self.recover() to raise an
# exception. As a result, these tests may pass even if fsrecover.py
# is broken badly. testNoDamage() tries to ensure that at least
# recovery doesn't produce any error msgs if the input .fs is in
# fact not damaged.
def testNoDamage(self):
output = self.recover()
self.assert_('error' not in output, output)
self.assert_('\n0 bytes removed during recovery' in output, output)
# Verify that the recovered database is identical to the original.
before = file(self.path, 'rb')
before_guts = before.read()
before.close()
after = file(self.dest, 'rb')
after_guts = after.read()
after.close()
self.assertEqual(before_guts, after_guts,
"recovery changed a non-damaged .fs file")
def testOneBlock(self):
for i in range(self.ITERATIONS):
self.damage(1, 1024)
output = self.recover()
self.assert_('error' in output, output)
self.recovered = FileStorage(self.dest)
self.recovered.close()
os.remove(self.path)
os.rename(self.dest, self.path)
def testFourBlocks(self):
for i in range(self.ITERATIONS):
self.damage(4, 512)
output = self.recover()
#.........这里部分代码省略.........
示例10: cDB
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import cleanup [as 别名]
#.........这里部分代码省略.........
self.storage = None
self.path = None
self.db = None
self.connection = None
self._root = None
self.root = None
self.db_version = None
self.is_app_db = None
def copy_to(self, path="", storage=None, close_when_finished=False):
"""
Questa funzione permette di copiare il contenuto di questo database in un altro database.
Gli argomenti sono analoghi a quelli di cDB.start e vi vengono passati direttamente.
L'argomento close_when_finished indica (se falso) che il nuovo database verrà restituito
in seguito all'operazione di copiatura, o (se vero) che verrà chiuso successivamente
alla copiatura e poi restituito.
"""
new_db = cDB() # Creiamo l'istanza vuota del nuovo database.
new_db.start(path, storage) # Inizializziamo il database.
new_db.root = self.root # Copiamo il contenuto di questo database nel nuovo.
if close_when_finished: # Chiudiamo la connessione al nuovo database, o...
new_db.close_connection()
return new_db # Ritorniamo il nuovo database.
def delete(self):
"""
Questa funzione permette di cancellare questo database dal disco.
WARNING: USE WITH CAUTION.
"""
self.close(save=False, set_to_none=False)
self.storage.cleanup()
self.__set_to_none()
def save(self, save_plugins=True, encrypt=False, key=None):
if not self.is_app_db and save_plugins:
plugins_savs = self.instruct_plugins()
if plugins_savs is None:
exc.warn("", exc.DB_InstructPluginsNotSet) # message is provided by the exc module
else:
for plugin_id in plugins_savs.keys():
# TODO: if the plugin has not been enabled by the user, raise an exception
self.root['Plugins'][plugin_id] = plugins_savs[plugin_id]
transaction.commit()
self._root['ROOT'] = self.root
self._root._p_changed = True
transaction.commit()
# save completed. now encrypt if requested
if encrypt:
if self.path is None:
raise exc.DB_NoPathOnEncryption()
if key is None:
raise exc.DB_NoKeyOnEncryption()
security.encrypt_file(self.path, key)
def instruct_plugins(self):
"""
This function instructs the plugins about entering the saving state.
This function will be replaced with an other one set by the DB APIService.
The replaced method should return a non-None value (refer to cDB.save).
This functon should always return a dictionary.
"""