rosclean: support BusyBox du (#185)
* rosclean: support busybox du * Fix coding styles * Fix exception handling for symlink check
This commit is contained in:
parent
8a855e74ff
commit
f21e88cc9a
|
@ -34,6 +34,7 @@ from __future__ import print_function
|
||||||
|
|
||||||
__version__ = '1.7.0'
|
__version__ = '1.7.0'
|
||||||
|
|
||||||
|
from distutils.spawn import find_executable
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -134,17 +135,29 @@ def get_disk_usage(d):
|
||||||
:raises: :exc:`CleanupException` If get_disk_usage() cannot be used on this platform
|
:raises: :exc:`CleanupException` If get_disk_usage() cannot be used on this platform
|
||||||
"""
|
"""
|
||||||
# only implemented on Linux and FreeBSD for now. Should work on OS X but need to verify first (du is not identical)
|
# only implemented on Linux and FreeBSD for now. Should work on OS X but need to verify first (du is not identical)
|
||||||
if platform.system() == 'Linux':
|
cmd = None
|
||||||
|
unit = 1
|
||||||
|
du = find_executable('du')
|
||||||
|
if du is not None:
|
||||||
|
if platform.system() == 'Linux':
|
||||||
|
cmd = [du, '-sb', d]
|
||||||
|
elif platform.system() == 'FreeBSD':
|
||||||
|
cmd = [du, '-skA', d]
|
||||||
|
unit = 1024
|
||||||
try:
|
try:
|
||||||
return int(subprocess.Popen(['du', '-sb', d], stdout=subprocess.PIPE).communicate()[0].split()[0])
|
# detect BusyBox du command by following symlink
|
||||||
except:
|
if os.path.basename(os.readlink(du)) == 'busybox':
|
||||||
raise CleanupException("rosclean is not supported on this platform")
|
cmd = [du, '-sk', d]
|
||||||
elif platform.system() == 'FreeBSD':
|
unit = 1024
|
||||||
try:
|
except OSError:
|
||||||
return int(subprocess.Popen(['du', '-sA', d], stdout=subprocess.PIPE).communicate()[0].split()[0]) * 1024
|
# readlink raises OSError if the target is not symlink
|
||||||
except:
|
pass
|
||||||
raise CleanupException("rosclean is not supported on this platform")
|
|
||||||
else:
|
if cmd is None:
|
||||||
|
raise CleanupException("rosclean is not supported on this platform")
|
||||||
|
try:
|
||||||
|
return int(subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0].split()[0]) * unit
|
||||||
|
except:
|
||||||
raise CleanupException("rosclean is not supported on this platform")
|
raise CleanupException("rosclean is not supported on this platform")
|
||||||
|
|
||||||
def _sort_file_by_oldest(d):
|
def _sort_file_by_oldest(d):
|
||||||
|
|
Loading…
Reference in New Issue