本文整理汇总了Python中ZODB.FileStorage.FileStorage.getSize方法的典型用法代码示例。如果您正苦于以下问题:Python FileStorage.getSize方法的具体用法?Python FileStorage.getSize怎么用?Python FileStorage.getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZODB.FileStorage.FileStorage
的用法示例。
在下文中一共展示了FileStorage.getSize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_full_backup
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import getSize [as 别名]
def do_full_backup(options):
options.full = True
dest = os.path.join(options.repository, gen_filename(options))
if os.path.exists(dest):
raise WouldOverwriteFiles('Cannot overwrite existing file: %s' % dest)
# Find the file position of the last completed transaction.
fs = FileStorage(options.file, read_only=True)
# Note that the FileStorage ctor calls read_index() which scans the file
# and returns "the position just after the last valid transaction record".
# getSize() then returns this position, which is exactly what we want,
# because we only want to copy stuff from the beginning of the file to the
# last valid transaction record.
pos = fs.getSize()
# Save the storage index into the repository
index_file = os.path.join(options.repository,
gen_filename(options, '.index'))
log('writing index')
fs._index.save(pos, index_file)
fs.close()
log('writing full backup: %s bytes to %s', pos, dest)
sum = copyfile(options, dest, 0, pos)
# Write the data file for this full backup
datfile = os.path.splitext(dest)[0] + '.dat'
fp = open(datfile, 'w')
print >> fp, dest, 0, pos, sum
fp.flush()
os.fsync(fp.fileno())
fp.close()
if options.killold:
delete_old_backups(options)
示例2: do_incremental_backup
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import getSize [as 别名]
def do_incremental_backup(options, reposz, repofiles):
options.full = False
dest = os.path.join(options.repository, gen_filename(options))
if os.path.exists(dest):
raise WouldOverwriteFiles('Cannot overwrite existing file: %s' % dest)
# Find the file position of the last completed transaction.
fs = FileStorage(options.file, read_only=True)
# Note that the FileStorage ctor calls read_index() which scans the file
# and returns "the position just after the last valid transaction record".
# getSize() then returns this position, which is exactly what we want,
# because we only want to copy stuff from the beginning of the file to the
# last valid transaction record.
pos = fs.getSize()
log('writing index')
index_file = os.path.join(options.repository,
gen_filename(options, '.index'))
fs._index.save(pos, index_file)
fs.close()
log('writing incremental: %s bytes to %s', pos-reposz, dest)
sum = copyfile(options, dest, reposz, pos - reposz)
# The first file in repofiles points to the last full backup. Use this to
# get the .dat file and append the information for this incrementatl to
# that file.
fullfile = repofiles[0]
datfile = os.path.splitext(fullfile)[0] + '.dat'
# This .dat file better exist. Let the exception percolate if not.
fp = open(datfile, 'a')
print >> fp, dest, reposz, pos, sum
fp.flush()
os.fsync(fp.fileno())
fp.close()
示例3: TestNodeExtZODB
# 需要导入模块: from ZODB.FileStorage import FileStorage [as 别名]
# 或者: from ZODB.FileStorage.FileStorage import getSize [as 别名]
#.........这里部分代码省略.........
zodbnode['child'] = ZODBNode('child')
self.check_output("""\
{'zodbnode': <ZODBNode object 'zodbnode' at ...>}
""", repr(root))
self.assertEqual(zodbnode.keys(), ['child'])
self.assertEqual(zodbnode.values(), [zodbnode['child']])
self.assertEqual(zodbnode.treerepr(), (
'<class \'node.ext.zodb.ZODBNode\'>: zodbnode\n'
' <class \'node.ext.zodb.ZODBNode\'>: child\n'
))
self.assertEqual(list(root.keys()), ['zodbnode'])
# Reopen database connection and check again
self.close()
root = self.open()
self.assertEqual(list(root.keys()), ['zodbnode'])
zodbnode = root['zodbnode']
self.assertEqual(zodbnode.treerepr(), (
'<class \'node.ext.zodb.ZODBNode\'>: zodbnode\n'
' <class \'node.ext.zodb.ZODBNode\'>: child\n'
))
# Delete child node
del zodbnode['child']
self.assertEqual(zodbnode.treerepr(), (
'<class \'node.ext.zodb.ZODBNode\'>: zodbnode\n'
))
# Check node attributes
self.assertTrue(isinstance(zodbnode.attrs, ZODBNodeAttributes))
self.assertEqual(zodbnode.attrs.name, '_attrs')
zodbnode.attrs['foo'] = 1
bar = zodbnode.attrs['bar'] = ZODBNode()
self.assertEqual(zodbnode.attrs.values(), [1, bar])
# Fill root with some ZODBNodes and check memory usage
transaction.commit()
old_size = self.storage.getSize()
root['largezodb'] = ZODBNode('largezodb')
for i in range(1000):
root['largezodb'][str(i)] = ZODBNode()
self.assertEqual(len(root['largezodb']), 1000)
transaction.commit()
new_size = self.storage.getSize()
# ZODB 3 and ZODB 5 return different sizes so check whether lower or
# equal higher value
self.assertTrue((new_size - old_size) / 1000 <= 160)
self.close()
def test_OOBTNode(self):
# Based on OOBTree as storage
oobtnode = OOBTNode('oobtnode')
# Interface check
self.assertTrue(IZODBNode.providedBy(oobtnode))
# Storage check
self.assertTrue(isinstance(oobtnode.storage, OOBTodict))
self.assertTrue(isinstance(oobtnode._storage, OOBTodict))
# Structure check
root = self.open()
root[oobtnode.__name__] = oobtnode
oobtnode['child'] = OOBTNode('child')
self.assertEqual(sorted(root.keys()), ['oobtnode'])
self.assertEqual(oobtnode.keys(), ['child'])
self.assertEqual(oobtnode.values(), [oobtnode['child']])
self.assertEqual(oobtnode.treerepr(), (
'<class \'node.ext.zodb.OOBTNode\'>: oobtnode\n'
' <class \'node.ext.zodb.OOBTNode\'>: child\n'
))
self.check_output("""\
OOBTodict([('child', <OOBTNode object 'child' at ...>)])