Add get_updated_config_files in portage API
authorMounir Lamouri <volkmar@gentoo.org>
Thu, 30 Jul 2009 20:36:02 +0000 (20:36 -0000)
committerMounir Lamouri <volkmar@gentoo.org>
Thu, 30 Jul 2009 20:36:02 +0000 (20:36 -0000)
chk_updated_cfg_files in _emerge API is now using get_updated_config_files
It lets other app to get updated config files without ouputs

svn path=/main/trunk/; revision=13858

pym/_emerge/actions.py
pym/portage/util.py

index f28f0dcaa2c4b4e4017cfafa1e958d1834050c5a..affa6bc49dc363b7f68c335099a5bae1796b0778 100644 (file)
@@ -2610,58 +2610,19 @@ def load_emerge_config(trees=None):
        return settings, trees, mtimedb
 
 def chk_updated_cfg_files(target_root, config_protect):
-       if config_protect:
-               #number of directories with some protect files in them
-               procount=0
-               for x in config_protect:
-                       x = os.path.join(target_root, x.lstrip(os.path.sep))
-                       if not os.access(x, os.W_OK):
-                               # Avoid Permission denied errors generated
-                               # later by `find`.
-                               continue
-                       try:
-                               mymode = os.lstat(x).st_mode
-                       except OSError:
-                               continue
-                       if stat.S_ISLNK(mymode):
-                               # We want to treat it like a directory if it
-                               # is a symlink to an existing directory.
-                               try:
-                                       real_mode = os.stat(x).st_mode
-                                       if stat.S_ISDIR(real_mode):
-                                               mymode = real_mode
-                               except OSError:
-                                       pass
-                       if stat.S_ISDIR(mymode):
-                               mycommand = "find '%s' -name '.*' -type d -prune -o -name '._cfg????_*'" % x
-                       else:
-                               mycommand = "find '%s' -maxdepth 1 -name '._cfg????_%s'" % \
-                                       os.path.split(x.rstrip(os.path.sep))
-                       mycommand += " ! -name '.*~' ! -iname '.*.bak' -print0"
-                       a = commands.getstatusoutput(mycommand)
-                       if a[0] != 0:
-                               sys.stderr.write(" %s error scanning '%s': " % (bad("*"), x))
-                               sys.stderr.flush()
-                               # Show the error message alone, sending stdout to /dev/null.
-                               os.system(mycommand + " 1>/dev/null")
-                       else:
-                               files = a[1].split('\0')
-                               # split always produces an empty string as the last element
-                               if files and not files[-1]:
-                                       del files[-1]
-                               if files:
-                                       procount += 1
-                                       print "\n"+colorize("WARN", " * IMPORTANT:"),
-                                       if stat.S_ISDIR(mymode):
-                                                print "%d config files in '%s' need updating." % \
-                                                       (len(files), x)
-                                       else:
-                                                print "config file '%s' needs updating." % x
-
-               if procount:
-                       print " "+yellow("*")+" See the "+colorize("INFORM","CONFIGURATION FILES")+ \
-                               " section of the " + bold("emerge")
-                       print " "+yellow("*")+" man page to learn how to update config files."
+       result = portage.util.get_updated_config_files(target_root, config_protect)
+
+       for x in result:
+               print "\n"+colorize("WARN", " * IMPORTANT:"),
+               if not x[1]: # it's a protected file
+                       print "config file '%s' needs updating." % x[0]
+               else: # it's a protected dir
+                       print "%d config files in '%s' need updating." % (len(x[1]), x[0])
+
+       if result != []:
+               print " "+yellow("*")+" See the "+colorize("INFORM","CONFIGURATION FILES")\
+                               + " section of the " + bold("emerge")
+               print " "+yellow("*")+" man page to learn how to update config files."
 
 def display_news_notification(root_config, myopts):
        target_root = root_config.root
index 63b504cf91c4aa146865a9a385f8a606f551dc13..1759e132e5d2e18fd43c2593fb7b5f894e025a1e 100644 (file)
@@ -5,13 +5,14 @@
 __all__ = ['apply_permissions', 'apply_recursive_permissions',
        'apply_secpass_permissions', 'apply_stat_permissions', 'atomic_ofstream',
        'cmp_sort_key', 'ConfigProtect', 'dump_traceback', 'ensure_dirs',
-       'getconfig', 'getlibpaths', 'grabdict', 'grabdict_package', 'grabfile',
-       'grabfile_package', 'grablines', 'initialize_logger', 'LazyItemsDict',
-       'map_dictlist_vals', 'new_protect_filename', 'normalize_path',
-       'pickle_read', 'stack_dictlist', 'stack_dicts', 'stack_lists',
-       'unique_array', 'varexpand', 'write_atomic', 'writedict', 'writemsg',
-       'writemsg_level', 'writemsg_stdout']
-
+       'getconfig', 'getlibpaths', 'get_updated_config_files' 'grabdict',
+       'grabdict_package', 'grabfile', 'grabfile_package', 'grablines',
+       'initialize_logger', 'LazyItemsDict', 'map_dictlist_vals',
+       'new_protect_filename', 'normalize_path', 'pickle_read', 'stack_dictlist',
+       'stack_dicts', 'stack_lists', 'unique_array', 'varexpand', 'write_atomic',
+       'writedict', 'writemsg', 'writemsg_level', 'writemsg_stdout']
+
+import commands
 import codecs
 import os
 import errno
@@ -1290,6 +1291,63 @@ def new_protect_filename(mydest, newmd5=None):
                                return old_pfile
        return new_pfile
 
+def get_updated_config_files(target_root, config_protect):
+       """
+       Return a list of configuration files that needs to be updated.
+       The list contains tuple organized like this:
+       [ protected_dir, file_list ]
+       If the protected config isn't a protected_dir but a procted_file, tuple is:
+       [ protected_file, None ]
+       If no configuration files needs to be updated, [] is returned
+       """
+
+       rval = []
+
+       if config_protect:
+               # directories with some protect files in them
+               for x in config_protect:
+                       files = []
+
+                       x = os.path.join(target_root, x.lstrip(os.path.sep))
+                       if not os.access(x, os.W_OK):
+                               continue
+                       try:
+                               mymode = os.lstat(x).st_mode
+                       except OSError:
+                               continue
+
+                       if stat.S_ISLNK(mymode):
+                               # We want to treat it like a directory if it
+                               # is a symlink to an existing directory.
+                               try:
+                                       real_mode = os.stat(x).st_mode
+                                       if stat.S_ISDIR(real_mode):
+                                               mymode = real_mode
+                               except OSError:
+                                       pass
+
+                       if stat.S_ISDIR(mymode):
+                               mycommand = \
+                                       "find '%s' -name '.*' -type d -prune -o -name '._cfg????_*'" % x
+                       else:
+                               mycommand = "find '%s' -maxdepth 1 -name '._cfg????_%s'" % \
+                                               os.path.split(x.rstrip(os.path.sep))
+                       mycommand += " ! -name '.*~' ! -iname '.*.bak' -print0"
+                       a = commands.getstatusoutput(mycommand)
+
+                       if a[0] == 0:
+                               files = a[1].split('\0')
+                               # split always produces an empty string as the last element
+                               if files and not files[-1]:
+                                       del files[-1]
+                               if files:
+                                       if stat.S_ISDIR(mymode):
+                                               rval.append([x, files])
+                                       else:
+                                               rval.append([x, None])
+
+       return rval
+
 def getlibpaths(root):
        """ Return a list of paths that are used for library lookups """