本文整理汇总了Python中bleachbit.FileUtilities.bytes_to_human方法的典型用法代码示例。如果您正苦于以下问题:Python FileUtilities.bytes_to_human方法的具体用法?Python FileUtilities.bytes_to_human怎么用?Python FileUtilities.bytes_to_human使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bleachbit.FileUtilities
的用法示例。
在下文中一共展示了FileUtilities.bytes_to_human方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_total_size
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import bytes_to_human [as 别名]
def update_total_size(self, bytes_removed):
"""Callback to update the total size cleaned"""
context_id = self.status_bar.get_context_id('size')
text = FileUtilities.bytes_to_human(bytes_removed)
if 0 == bytes_removed:
text = ""
self.status_bar.push(context_id, text)
示例2: execute
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import bytes_to_human [as 别名]
def execute(self, cmd, operation_option):
"""Execute or preview the command"""
ret = None
try:
for ret in cmd.execute(self.really_delete):
if True == ret or isinstance(ret, tuple):
# Temporarily pass control to the GTK idle loop,
# allow user to abort, and
# display progress (if applicable).
yield ret
except SystemExit:
pass
except Exception as e:
# 2 = does not exist
# 13 = permission denied
from errno import ENOENT, EACCES
if isinstance(e, OSError) and e.errno in (ENOENT, EACCES):
# For access denied, do not show traceback
exc_message = str(e).decode(FSE)
logger.error('%s: %s', exc_message, cmd)
else:
# For other errors, show the traceback.
msg = _('Error: {operation_option}: {command}')
data = {'command': cmd, 'operation_option': operation_option}
logger.error(msg.format(**data), exc_info=True)
self.total_errors += 1
else:
if ret is None:
return
if isinstance(ret['size'], (int, long)):
size = FileUtilities.bytes_to_human(ret['size'])
self.size += ret['size']
self.total_bytes += ret['size']
else:
size = "?B"
if ret['path']:
path = ret['path']
else:
path = ''
path = path.decode('utf8', 'replace') # for invalid encoding
line = u"%s %s %s\n" % (ret['label'], size, path)
self.total_deleted += ret['n_deleted']
self.total_special += ret['n_special']
if ret['label']:
# the label may be a hidden operation
# (e.g., win.shell.change.notify)
self.ui.append_text(line)
示例3: fill_memory_linux
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import bytes_to_human [as 别名]
def fill_memory_linux():
"""Fill unallocated memory"""
report_free()
allocbytes = int(physical_free() * 0.4)
if allocbytes < 1024:
return
bytes_str = FileUtilities.bytes_to_human(allocbytes)
logger.info('allocating and wiping %s (%d B) of memory', bytes_str, allocbytes)
try:
buf = '\x00' * allocbytes
except MemoryError:
pass
else:
fill_memory_linux()
logger.debug('freeing %s of memory" % bytes_str')
del buf
report_free()
示例4: update_item_size
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import bytes_to_human [as 别名]
def update_item_size(self, option, option_id, bytes_removed):
"""Update size in tree control"""
model = self.view.get_model()
text = FileUtilities.bytes_to_human(bytes_removed)
if 0 == bytes_removed:
text = ""
__iter = model.get_iter_root()
while __iter:
if model[__iter][2] == option:
if option_id == -1:
model[__iter][3] = text
else:
child = model.iter_children(__iter)
while child:
if model[child][2] == option_id:
model[child][3] = text
child = model.iter_next(child)
__iter = model.iter_next(__iter)
示例5: run
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import bytes_to_human [as 别名]
def run(self):
"""Perform the main cleaning process which has these phases
1. General cleaning
2. Deep scan
3. Memory
4. Free disk space"""
self.deepscans = {}
# prioritize
self.delayed_ops = []
for operation in self.operations:
delayables = ['free_disk_space', 'memory']
for delayable in delayables:
if operation not in ('system', '_gui'):
continue
if delayable in self.operations[operation]:
i = self.operations[operation].index(delayable)
del self.operations[operation][i]
priority = 99
if 'free_disk_space' == delayable:
priority = 100
new_op = (priority, {operation: [delayable]})
self.delayed_ops.append(new_op)
# standard operations
import warnings
with warnings.catch_warnings(record=True) as ws:
# This warning system allows general warnings. Duplicate will
# be removed, and the warnings will show near the end of
# the log.
warnings.simplefilter('once')
for dummy in self.run_operations(self.operations):
# yield to GTK+ idle loop
yield True
for w in ws:
logger.warning(w.message)
# run deep scan
if self.deepscans:
for dummy in self.run_deep_scan():
yield dummy
# delayed operations
for op in sorted(self.delayed_ops):
operation = op[1].keys()[0]
for option_id in op[1].values()[0]:
for ret in self.run_delayed_op(operation, option_id):
# yield to GTK+ idle loop
yield True
# print final stats
bytes_delete = FileUtilities.bytes_to_human(self.total_bytes)
if self.really_delete:
# TRANSLATORS: This refers to disk space that was
# really recovered (in other words, not a preview)
line = _("Disk space recovered: %s") % bytes_delete
else:
# TRANSLATORS: This refers to a preview (no real
# changes were made yet)
line = _("Disk space to be recovered: %s") % bytes_delete
self.ui.append_text("\n%s" % line)
if self.really_delete:
# TRANSLATORS: This refers to the number of files really
# deleted (in other words, not a preview).
line = _("Files deleted: %d") % self.total_deleted
else:
# TRANSLATORS: This refers to the number of files that
# would be deleted (in other words, simply a preview).
line = _("Files to be deleted: %d") % self.total_deleted
self.ui.append_text("\n%s" % line)
if self.total_special > 0:
line = _("Special operations: %d") % self.total_special
self.ui.append_text("\n%s" % line)
if self.total_errors > 0:
line = _("Errors: %d") % self.total_errors
self.ui.append_text("\n%s" % line, 'error')
if self.really_delete:
self.ui.update_total_size(self.total_bytes)
self.ui.worker_done(self, self.really_delete)
yield False
示例6: report_free
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import bytes_to_human [as 别名]
def report_free():
"""Report free memory"""
bytes_free = physical_free()
bytes_str = FileUtilities.bytes_to_human(bytes_free)
logger.debug('physical free: %s (%d B)', bytes_str, bytes_free)