本文整理汇总了Python中bleachbit.FileUtilities.human_to_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python FileUtilities.human_to_bytes方法的具体用法?Python FileUtilities.human_to_bytes怎么用?Python FileUtilities.human_to_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bleachbit.FileUtilities
的用法示例。
在下文中一共展示了FileUtilities.human_to_bytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_cleaner_cmd
# 需要导入模块: from bleachbit import FileUtilities [as 别名]
# 或者: from bleachbit.FileUtilities import human_to_bytes [as 别名]
def run_cleaner_cmd(cmd, args, freed_space_regex=r'[\d.]+[kMGTE]?B?', error_line_regexes=None):
"""Runs a specified command and returns how much space was (reportedly) freed.
The subprocess shouldn't need any user input and the user should have the
necessary rights.
freed_space_regex gets applied to every output line, if the re matches,
add values captured by the single group in the regex"""
if not FileUtilities.exe_exists(cmd):
raise RuntimeError(_('Executable not found: %s') % cmd)
freed_space_regex = re.compile(freed_space_regex)
error_line_regexes = [re.compile(regex) for regex in error_line_regexes or []]
output = subprocess.check_output([cmd]+args, stderr=subprocess.STDOUT,
universal_newlines=True, env={'LC_ALL': 'C'})
freed_space = 0
for line in output.split('\n'):
m = freed_space_regex.match(line)
if m is not None:
freed_space += FileUtilities.human_to_bytes(m.group(1))
for error_re in error_line_regexes:
if error_re.search(line):
raise RuntimeError('Invalid output from %s: %s' % (cmd, line))
return freed_space