Minor updates
authorkarltk <karltk@gentoo.org>
Fri, 3 Oct 2003 22:12:50 +0000 (22:12 -0000)
committerkarltk <karltk@gentoo.org>
Fri, 3 Oct 2003 22:12:50 +0000 (22:12 -0000)
svn path=/; revision=39

trunk/TODO
trunk/src/etc-update/etc-update
trunk/src/gentoolkit/gentoolkit.py

index 24fbfe242228448e0ade193578548c11ea1f5878..5e897b5474a8424e7a2f9997144c31a52092bbed 100644 (file)
@@ -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
index a92159bceff111b4bc4b6ec763b71001358f163a..50bf8d7134709088a7cc089078cccf5e793bdb0a 100755 (executable)
@@ -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
index b299e5a2424bb908b32606b5e13de36c4de30014..adedfa294b256994e33cf3e82cafb13d40c31b8d 100644 (file)
@@ -7,7 +7,9 @@
 # $Header$
 # Author: Karl Trygve Kalleberg <karltk@gentoo.org>
 #
-# Portions written ripped from etcat, written by Alistair Tse <liquidx@gentoo.org>
+# Portions written ripped from 
+# - etcat, by Alistair Tse <liquidx@gentoo.org>
+#
 
 __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