diff options
author | Kang Kai <kai.kang@windriver.com> | 2012-06-15 10:20:18 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2012-06-18 13:16:37 +0100 |
commit | 4d2920dee32bbc5d12ed98234de096d28d29415b (patch) | |
tree | b36e10d6cce1b246b72330af00cc176ff709c1e0 | |
parent | 4b6f29ddb00480896f47d96ea376f3a6f6d8451e (diff) | |
download | openembedded-core-4d2920dee32bbc5d12ed98234de096d28d29415b.tar.gz openembedded-core-4d2920dee32bbc5d12ed98234de096d28d29415b.tar.bz2 openembedded-core-4d2920dee32bbc5d12ed98234de096d28d29415b.zip |
cleanup-workdir: update the way to check obsolete dirs
Update the way to check obsolete directories.
According to package and its version construct a list of all packages'
current build directory. If any directory under $WORKDIR/*/ is not in
the list will be removed.
At same time, all the files(vs. directory) under $WORKDIR and
$WORKDIR/*/ will be removed because they are not created by poky.
Signed-off-by: Kang Kai <kai.kang@windriver.com>
-rwxr-xr-x | scripts/cleanup-workdir | 59 |
1 files changed, 23 insertions, 36 deletions
diff --git a/scripts/cleanup-workdir b/scripts/cleanup-workdir index b77e8c664f..3739a00032 100755 --- a/scripts/cleanup-workdir +++ b/scripts/cleanup-workdir @@ -22,7 +22,7 @@ import re import commands import shutil -versions = {} +pkg_cur_dirs = [] obsolete_dirs = [] parser = None @@ -39,15 +39,6 @@ def parse_version(verstr): else: return epoch + '_' + elems[1] -def parse_dir(match, pkgabsdir): - pkg_name = match.group(1) - pkg_version = match.group(2) - if pkg_name in versions: - if pkg_version != versions[pkg_name]: - obsolete_dirs.append(pkgabsdir) - return True - return False - def main(): global parser parser = optparse.OptionParser( @@ -89,7 +80,7 @@ This script must be ran under BUILDDIR after source file \"oe-init-build-env\"." version = parse_version(elems[1]) else: version = parse_version(elems[2]) - versions[elems[0]] = version + pkg_cur_dirs.append(elems[0] + '-' + version) cmd = "bitbake -e | grep ^TMPDIR" (ret, output) = commands.getstatusoutput(cmd) @@ -103,31 +94,27 @@ This script must be ran under BUILDDIR after source file \"oe-init-build-env\"." print "WORKDIR %s does NOT exist. Quit." % workdir return 1 - for archdir in os.listdir(workdir): - archdir = os.path.join(workdir, archdir) - if not os.path.isdir(archdir): - pass - - for pkgdir in sorted(os.listdir(archdir)): - pkgabsdir = os.path.join(archdir, pkgdir) - if not os.path.isdir(pkgabsdir): - pass - - # parse the package directory names - # parse native/nativesdk packages first - match = re.match('(.*?-native.*?)-(.*)', pkgdir) - if match and parse_dir(match, pkgabsdir): - continue - - # parse package names which ends with numbers such as 'glib-2.0' - match = re.match('(.*?-[\.\d]+)-(\d.*)', pkgdir) - if match and parse_dir(match, pkgabsdir): - continue - - # other packages - match = re.match('(.*?)-(\d.*)', pkgdir) - if match and parse_dir(match, pkgabsdir): - continue + for workroot, dirs, files in os.walk(workdir): + # For the files, they should NOT exist in WORKDIR. Romve them. + for f in files: + obsolete_dirs.append(os.path.join(workroot, f)) + + for d in dirs: + for pkgroot, pkgdirs, filenames in os.walk(os.path.join(workroot, d)): + for f in filenames: + obsolete_dirs.append(os.path.join(pkgroot, f)) + + for pkgdir in sorted(pkgdirs): + if pkgdir not in pkg_cur_dirs: + obsolete_dirs.append(os.path.join(pkgroot, pkgdir)) + + # just process the top dir of every package under tmp/work/*/, + # then jump out of the above os.walk() + break + + # it is convenient to use os.walk() to get dirs and files at same time + # both of them have been dealed in the loop, so jump out + break for d in obsolete_dirs: print "Deleleting %s" % d |