本文整理汇总了Python中bleachbit.FileUtilities.wipe_contents方法的典型用法代码示例。如果您正苦于以下问题:Python FileUtilities.wipe_contents方法的具体用法?Python FileUtilities.wipe_contents怎么用?Python FileUtilities.wipe_contents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bleachbit.FileUtilities
的用法示例。
在下文中一共展示了FileUtilities.wipe_contents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wipe_swap_linux
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import wipe_contents [as 别名]
def wipe_swap_linux(devices, proc_swaps):
"""Shred the Linux swap file and then reinitilize it"""
if devices is None:
return
if 0 < count_swap_linux():
raise RuntimeError('Cannot wipe swap while it is in use')
for device in devices:
logger.info("wiping swap device '%s'", device)
safety_limit_bytes = 16 * 1024 ** 3 # 16 gibibytes
actual_size_bytes = get_swap_size_linux(device, proc_swaps)
if actual_size_bytes > safety_limit_bytes:
raise RuntimeError(
'swap device %s is larger (%d) than expected (%d)' %
(device, actual_size_bytes, safety_limit_bytes))
uuid = get_swap_uuid(device)
# wipe
FileUtilities.wipe_contents(device, truncate=False)
# reinitialize
logger.debug('reinitializing swap device %s', device)
args = ['mkswap', device]
if uuid:
args.append("-U")
args.append(uuid)
(rc, _, stderr) = General.run_external(args)
if 0 != rc:
raise RuntimeError(stderr.replace("\n", ""))