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:24:56 +0100 |
commit | 7dbc26874f9e5bb9e057b32e02b099faca4aed15 (patch) | |
tree | 22a08a25481209d6bcefc84c66a95b4bcd606c80 /scripts/cleanup-workdir | |
parent | 21bd4552d63659ac68936bd18ed8013d6783d02c (diff) | |
download | poky-7dbc26874f9e5bb9e057b32e02b099faca4aed15.tar.gz |
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.
(From OE-Core rev: 4d2920dee32bbc5d12ed98234de096d28d29415b)
Signed-off-by: Kang Kai <kai.kang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/cleanup-workdir')
-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 | |||
22 | import commands | 22 | import commands |
23 | import shutil | 23 | import shutil |
24 | 24 | ||
25 | versions = {} | 25 | pkg_cur_dirs = [] |
26 | obsolete_dirs = [] | 26 | obsolete_dirs = [] |
27 | parser = None | 27 | parser = None |
28 | 28 | ||
@@ -39,15 +39,6 @@ def parse_version(verstr): | |||
39 | else: | 39 | else: |
40 | return epoch + '_' + elems[1] | 40 | return epoch + '_' + elems[1] |
41 | 41 | ||
42 | def parse_dir(match, pkgabsdir): | ||
43 | pkg_name = match.group(1) | ||
44 | pkg_version = match.group(2) | ||
45 | if pkg_name in versions: | ||
46 | if pkg_version != versions[pkg_name]: | ||
47 | obsolete_dirs.append(pkgabsdir) | ||
48 | return True | ||
49 | return False | ||
50 | |||
51 | def main(): | 42 | def main(): |
52 | global parser | 43 | global parser |
53 | parser = optparse.OptionParser( | 44 | parser = optparse.OptionParser( |
@@ -89,7 +80,7 @@ This script must be ran under BUILDDIR after source file \"oe-init-build-env\"." | |||
89 | version = parse_version(elems[1]) | 80 | version = parse_version(elems[1]) |
90 | else: | 81 | else: |
91 | version = parse_version(elems[2]) | 82 | version = parse_version(elems[2]) |
92 | versions[elems[0]] = version | 83 | pkg_cur_dirs.append(elems[0] + '-' + version) |
93 | 84 | ||
94 | cmd = "bitbake -e | grep ^TMPDIR" | 85 | cmd = "bitbake -e | grep ^TMPDIR" |
95 | (ret, output) = commands.getstatusoutput(cmd) | 86 | (ret, output) = commands.getstatusoutput(cmd) |
@@ -103,31 +94,27 @@ This script must be ran under BUILDDIR after source file \"oe-init-build-env\"." | |||
103 | print "WORKDIR %s does NOT exist. Quit." % workdir | 94 | print "WORKDIR %s does NOT exist. Quit." % workdir |
104 | return 1 | 95 | return 1 |
105 | 96 | ||
106 | for archdir in os.listdir(workdir): | 97 | for workroot, dirs, files in os.walk(workdir): |
107 | archdir = os.path.join(workdir, archdir) | 98 | # For the files, they should NOT exist in WORKDIR. Romve them. |
108 | if not os.path.isdir(archdir): | 99 | for f in files: |
109 | pass | 100 | obsolete_dirs.append(os.path.join(workroot, f)) |
110 | 101 | ||
111 | for pkgdir in sorted(os.listdir(archdir)): | 102 | for d in dirs: |
112 | pkgabsdir = os.path.join(archdir, pkgdir) | 103 | for pkgroot, pkgdirs, filenames in os.walk(os.path.join(workroot, d)): |
113 | if not os.path.isdir(pkgabsdir): | 104 | for f in filenames: |
114 | pass | 105 | obsolete_dirs.append(os.path.join(pkgroot, f)) |
115 | 106 | ||
116 | # parse the package directory names | 107 | for pkgdir in sorted(pkgdirs): |
117 | # parse native/nativesdk packages first | 108 | if pkgdir not in pkg_cur_dirs: |
118 | match = re.match('(.*?-native.*?)-(.*)', pkgdir) | 109 | obsolete_dirs.append(os.path.join(pkgroot, pkgdir)) |
119 | if match and parse_dir(match, pkgabsdir): | 110 | |
120 | continue | 111 | # just process the top dir of every package under tmp/work/*/, |
121 | 112 | # then jump out of the above os.walk() | |
122 | # parse package names which ends with numbers such as 'glib-2.0' | 113 | break |
123 | match = re.match('(.*?-[\.\d]+)-(\d.*)', pkgdir) | 114 | |
124 | if match and parse_dir(match, pkgabsdir): | 115 | # it is convenient to use os.walk() to get dirs and files at same time |
125 | continue | 116 | # both of them have been dealed in the loop, so jump out |
126 | 117 | break | |
127 | # other packages | ||
128 | match = re.match('(.*?)-(\d.*)', pkgdir) | ||
129 | if match and parse_dir(match, pkgabsdir): | ||
130 | continue | ||
131 | 118 | ||
132 | for d in obsolete_dirs: | 119 | for d in obsolete_dirs: |
133 | print "Deleleting %s" % d | 120 | print "Deleleting %s" % d |