diff -Nru python-central-0.6.15/debian/changelog python-central-0.6.16/debian/changelog --- python-central-0.6.15/debian/changelog 2010-03-31 15:52:37.000000000 +0200 +++ python-central-0.6.16/debian/changelog 2010-04-07 10:13:32.000000000 +0200 @@ -1,3 +1,12 @@ +python-central (0.6.16) unstable; urgency=low + + * pycentral cleanup-pkgprepare-updates: + - Try to use dlocate instead of dpkg -S. + - Don't try to remove emptied directories more than once (Piotr + Ozarowski). + + -- Matthias Klose Wed, 07 Apr 2010 08:10:12 +0200 + python-central (0.6.15) experimental; urgency=low [ Matthias Klose ] diff -Nru python-central-0.6.15/dh_pycentral.1 python-central-0.6.16/dh_pycentral.1 --- python-central-0.6.15/dh_pycentral.1 2010-03-31 16:13:13.000000000 +0200 +++ python-central-0.6.16/dh_pycentral.1 2010-04-07 10:15:09.000000000 +0200 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.07) +.\" Automatically generated by Pod::Man 2.1801 (Pod::Simple 3.05) .\" .\" Standard preamble: .\" ======================================================================== diff -Nru python-central-0.6.15/pycentral.py python-central-0.6.16/pycentral.py --- python-central-0.6.15/pycentral.py 2010-03-31 15:50:12.000000000 +0200 +++ python-central-0.6.16/pycentral.py 2010-04-07 10:17:14.000000000 +0200 @@ -18,7 +18,7 @@ shared_base = '/usr/share/pycentral/' shared_base2 = '/usr/share/pyshared/' -pycentral_version = '0.6.15' +pycentral_version = '0.6.16' req_pycentral_version = '0.6.15' @@ -1879,6 +1879,10 @@ register_action(ActionUpdateDefault) + +class DlocateError(Exception): + pass + class ActionCleanupPkgPrepareUpdates(Action): name = 'cleanup-pkgprepare-updates' help = 'cleanup dangling symlinks and byte code files' @@ -1903,6 +1907,7 @@ # then remove those not belonging to any package dirs = [] + removed = 0 for fn in unowned: try: os.unlink(fn + 'c') @@ -1911,7 +1916,9 @@ pass try: os.unlink(fn) - dirs.append(os.path.dirname(fn)) + removed += 1 + if not os.path.dirname(fn) in dirs: + dirs.append(os.path.dirname(fn)) except OSError, e: self.error("error removing dangling symlink: %s" % str(e), go_on=True) @@ -1924,7 +1931,8 @@ if len(packaged) > 0: for fn in packaged: self.warn('dangling symlink owned by package: %s' % fn) - self.warn('removed %d dangling symlinks not owned by any package') + if removed: + self.warn('removed %d dangling symlinks not owned by any package' % removed) return self.errors_occured def check_dangling_links(self): @@ -1950,28 +1958,68 @@ dangling.append(link) return dangling - def links_in_packages(self, links): + def locate(self, arg_list, cmd_list): from subprocess import PIPE, Popen - def chunks(l, n): - return [l[i:i+n] for i in range(0, len(l), n)] - packaged = set() - notfound = 0 - for arg_list in chunks(links, 50): - (stdout, stderr) = Popen(["dpkg","-S"] + arg_list, - env={"LANG" : "C"}, - stdout=PIPE, stderr=PIPE).communicate() - if stdout: - for line in map(string.strip, stdout.split("\n")): - if line == '': continue - fn = line.split(':', 1)[1][1:] - if fn in arg_list: - packaged.add(fn) - if stderr: - for line in map(string.strip, stderr.split("\n")): - if line == '': continue - fn = line.split(':', 1)[1][1:-11] - notfound += 1 - return packaged + (stdout, stderr) = Popen(cmd_list + arg_list, + env={"LANG" : "C"}, + shell=False, + stdout=PIPE, stderr=PIPE).communicate() + if stdout: + for line in map(string.strip, stdout.split("\n")): + # dlocate writes error messages to stdout + if line.startswith('dlocate: unknown option'): + raise DlocateError + if line == '': continue + fn = line.split(':', 1)[1][1:] + if fn in arg_list: + self.packaged.add(fn) + if stderr: + for line in map(string.strip, stderr.split("\n")): + if line.startswith('dlocate: unknown option'): + raise DlocateError + if line == '': continue + fn = line.split(':', 1)[1][1:-11] + self.notfound += 1 + + def links_in_packages(self, links): + def chunks(l): + if 'SC_ARG_MAX' in os.sysconf_names: + chunk_max = os.sysconf('SC_ARG_MAX') + else: + chunk_max = 16384 + chunk_max -= reduce(lambda x,y: x+y, + [len(k)+len(v)+3 for k,v in os.environ.items()]) + chunk_max -= 20 + chunk = [] + lchunk = 0 + all_chunks = [] + for i in l: + if lchunk + len(i)+1 > chunk_max: + all_chunks.append(chunk) + chunk = [] + lchunk = 0 + chunk.append(i) + lchunk += len(i) + 1 + if chunk: + all_chunks.append(chunk) + return all_chunks + + self.packaged = set() + self.notfound = 0 + all_chunks = chunks(links) + arg_list = all_chunks[0] + if os.path.exists('/usr/bin/dlocate'): + cmd_list = ["dlocate","--fixed-strings"] + else: + cmd_list = ["dpkg","-S"] + try: + self.locate(arg_list, cmd_list) + except DlocateError: + cmd_list = ["dpkg","-S"] + self.locate(arg_list, cmd_list) + for arg_list in all_chunks[1:]: + self.locate(arg_list, cmd_list) + return self.packaged register_action(ActionCleanupPkgPrepareUpdates)