From: karltk Date: Fri, 3 Oct 2003 22:12:50 +0000 (-0000) Subject: Minor updates X-Git-Tag: gentoolkit-0.2.4.3~463 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6f1cdf35352fe2122d67b87b44383960fefe1213;p=gentoolkit.git Minor updates svn path=/; revision=39 --- diff --git a/trunk/TODO b/trunk/TODO index 24fbfe2..5e897b5 100644 --- a/trunk/TODO +++ b/trunk/TODO @@ -11,5 +11,8 @@ - rewrite distfiles-clean to use gentoolkit - rewrite etc-update to use gentoolkit, add UI - add genlop +- look through forums.gentoo.org for additional scripts +- write a Gentoolkit Guide ++ check esearch, eupdatedb: separate package for now + extract helper code from etcat diff --git a/trunk/src/etc-update/etc-update b/trunk/src/etc-update/etc-update index a92159b..50bf8d7 100755 --- a/trunk/src/etc-update/etc-update +++ b/trunk/src/etc-update/etc-update @@ -5,7 +5,9 @@ # Distributed under the terms of the GNU General Public License v2 # Copyright (c) 2003 Karl Trygve Kalleberg +from dialog import Dialog import portage +import time import re import os @@ -46,23 +48,98 @@ def _recurseFiles(path): else: print "What is this anyway?:", fn except OSError: - print "Access denied:", path + pass + # print "Access denied:", path return files -def findAllFiles(config): +def findAllFiles(dlg, config): files = [] - for i in config.config_protect: - files += _recurseFiles(i) + gauge = dlg.gauge(0, + "Processing CONFIG_PROTECT directories...", + 7, + 60, + "Gauge", + sleep=3) + num_dirs = len(config.config_protect) + for i in xrange(num_dirs): + rem = repr(num_dirs - i / num_dirs) + gauge.update(rem, "Directories remaining: %s" % rem) + files += _recurseFiles(config.config_protect[i]) return files -def displayFiles(config,files): - print files +def prettifyFiles(files): + rx = re.compile("\._cfg...._") + def strip_cfg(x): + """Remove ._cfg????_ part """ + m = rx.search(x) + if m: + s,e = m.span(0) + return x[:s] + x[e:] + return x + return map(strip_cfg, files) +def updateFile(dlg, original): + + # Find candidates + + dir = os.path.dirname(original) + filename = os.path.basename(original) + rx = re.compile("\._cfg...._" + filename) + cand = filter(lambda x: rx.search(x), os.listdir(dir)) + + if len(cand) > 1: + + # Add mtimes + for i in xrange(len(cand)): + stamp = time.localtime(os.path.getmtime(dir + "/" + cand[i])) + tstr = time.strftime("%a, %d %b %Y %H:%M:%S", stamp) + cand[i] = cand[i] + " - " + tstr + + + # Show selection + replacement = dlg.menu("Files that need updating", + Dialog.AUTO_SIZE, + list = cand, + showHelp = False, + title="Checklist") + + else: + replacement = cand[0] + + + # Display diff + + dlg.yesno("Would you like to update \n" + \ + "[" + original + "]with\n[" + dir + "/" + replacement + "] ?") + +def displayFiles(dlg, config, files): + + pretty_files = prettifyFiles(files) + + while 1: + result = dlg.menu("Files that need updating", + Dialog.AUTO_SIZE, + list = pretty_files, + showHelp = False, + title="Checklist") + if result == None: + if dlg.ERR_CANCEL: + break + + updateFile(dlg, result) + + if len(pretty_files): + print "!!! Warning: There are still files that require updating." + + def main(): + dlg = Dialog("etc-update") +# dlg = None + config = loadConfig() - files = findAllFiles(config) - displayFiles(config,files) + files = findAllFiles(dlg, config) + displayFiles(dlg, config,files) if __name__ == "__main__": @@ -70,3 +147,8 @@ if __name__ == "__main__": main() except KeyboardInterrupt: print "Operation aborted!" + +# TODO: +# - option for automatically update untouched files +# - show coloured diff +# - proper progress bar diff --git a/trunk/src/gentoolkit/gentoolkit.py b/trunk/src/gentoolkit/gentoolkit.py index b299e5a..adedfa2 100644 --- a/trunk/src/gentoolkit/gentoolkit.py +++ b/trunk/src/gentoolkit/gentoolkit.py @@ -7,7 +7,9 @@ # $Header$ # Author: Karl Trygve Kalleberg # -# Portions written ripped from etcat, written by Alistair Tse +# Portions written ripped from +# - etcat, by Alistair Tse +# __author__ = "Karl Trygve Kalleberg" __email__ = "karltk@gentoo.org" @@ -193,6 +195,40 @@ def find_best_match(search_key): return Package(t) return None +def find_system_packages(prefilter=None): + """Returns a tuple of lists, first list is resolved system packages, + second is a list of unresolved packages.""" + f = open(portage.profiledir+"/packages") + pkglist = f.readlines() + resolved = [] + unresolved = [] + for x in pkglist: + cpv = x.strip() + if len(cpv) and cpv[0] == "*": + pkg = find_best_match(cpv) + if pkg: + resolved.append(pkg) + else: + unresolved.append(cpv) + return (resolved, unresolved) + +def find_world_packages(prefilter=None): + """Returns a tuple of lists, first list is resolved world packages, + seond is unresolved package names.""" + f = open(portage.root+"var/cache/edb/world") + pkglist = f.readlines() + resolved = [] + unresolved = [] + for x in pkglist: + cpv = x.strip() + if len(cpv) and cpv[0] != "#": + pkg = find_best_match(cpv) + if pkg: + resolved.append(pkg) + else: + unresolved.append(cpv) + return (resolved,unresolved) + def find_all_installed_packages(prefilter=None): """Returns a list of all installed packages, after applying the prefilter function""" @@ -200,8 +236,18 @@ def find_all_installed_packages(prefilter=None): if prefilter: t=filter(prefilter,t) return map(lambda x: Package(x), t) - - return find_all_packages(prefilter,1) + +def find_all_uninstalled_packages(prefilter=None): + """Returns a list of all uninstalled packages, after applying the prefilter + function""" + t=porttree.getallnodes() + if prefilter: + t=filter(prefilter,t) + return map(lambda x: Package(x), t) +# t2 = [] +# for x in t: +# t2 += porttree.dep_match(x) +# return map(lambda x: Package(x), t2) def find_all_packages(prefilter=None): """Returns a list of all known packages, installed or not, after applying