Author: wade
Date: 2007-01-11 17:11:39 -0500 (Thu, 11 Jan 2007)
New Revision: 70888

Added:
   trunk/release/pyutils/tests/test_web_index.py
Modified:
   trunk/release/pyutils/build.py
Log:
release/pyutils/build.py:
-redo web_index sorting, so there can be duplicates and numbers
 don't have to be successive

tests/test_web_index.py:
-helper test for new web_index sorting



Modified: trunk/release/pyutils/build.py
===================================================================
--- trunk/release/pyutils/build.py      2007-01-11 22:01:39 UTC (rev 70887)
+++ trunk/release/pyutils/build.py      2007-01-11 22:11:39 UTC (rev 70888)
@@ -13,14 +13,46 @@
 
 debug = 1
 
+# Private method
+def _web_index_sort(web_index_objs):
+       """Args: dictionary objects with an optional 'web_index' key in the 
'info' member
+       returns: sorted objects, according to web_index.
+       Items without web_index are at the end of resulting array, sorted in 
original
+       order, (which in this case is alphabetically)."""
+
+       obj_map = {}
+       # Create a map with key as index num, and value as an array of plat objs
+       for obj in web_index_objs:
+
+               index = obj.get_info_var('web_index')
+               if index == "": index = "999"
+
+               index = int(index)
+
+               if obj_map.has_key(index):
+                       obj_map[index].append(obj)
+               else:
+                       obj_map[index] = [obj]
+
+       sorted_web_index_objs = []
+
+       indexes = obj_map.keys()
+       indexes.sort()
+
+       # get objs out of map into sorted array
+       for index in indexes:
+               for i in obj_map[index]:
+                       sorted_web_index_objs.append(i)
+
+       return sorted_web_index_objs
+
 def get_platforms():
-       """Return buildenv objects sorted by web_index.  If some platforms 
don't have a web_index, sort
-        the remaining alphabetically."""
+       """Return platform names, sorted alphabetically."""
 
        platforms = []
 
        for entry in os.listdir(config.platform_conf_dir):
-               if entry != ".svn" and entry != "hosts":
+               if not re.compile('^\.').search(entry) and entry != "hosts":
                        platforms.append(entry)
 
        platforms.sort()
@@ -32,22 +64,11 @@
        platforms = get_platforms()
 
        plat_objs = []
-       plat_map = {}
        for platform in platforms:
-               plat_obj = packaging.buildenv(platform)
-               if plat_obj.info.has_key('web_index'):
-                       index = plat_obj.info['web_index']
-                       plat_map[index] = plat_obj
-               else:
-                       plat_objs.append(plat_obj)
+               plat_objs.append(packaging.buildenv(platform))
 
-       # Insert ordered platforms to the beginning of the list
-       for i in range(0, len(plat_map.keys())):
-               plat_objs.insert(i, plat_map[str(i)])
+       return _web_index_sort(plat_objs)
 
-       return plat_objs
-
-
 def get_packages():
 
        packages = []
@@ -69,9 +90,7 @@
        packages = get_packages()
 
         pack_objs = []
-        pack_map = {}
         noarch_pack_objs = []
-       noarch_pack_map = {}
 
         for package in packages:
                # Don't try to create the dirs and links because this code is 
run by the web server
@@ -79,30 +98,14 @@
 
                # Handle normal package
                if pack_obj.info['get_destroot'].find('noarch') == -1:
-                       map_ptr = pack_map
-                       obj_ptr = pack_objs
-
+                       pack_objs.append(pack_obj)
                # It's noarch
                else:
-                       map_ptr = noarch_pack_map
-                       obj_ptr = noarch_pack_objs
+                       noarch_pack_objs.append(pack_obj)
 
-                if pack_obj.info.has_key('web_index'):
-                        index = pack_obj.info['web_index']
-                        map_ptr[index] = pack_obj
-                else:
-                        obj_ptr.append(pack_obj)
+        return _web_index_sort(pack_objs), _web_index_sort(noarch_pack_objs)
 
-        # Insert ordered packages to the beginning of the list
-        for i in range(0, len(pack_map.keys())):
-                pack_objs.insert(i, pack_map[str(i)])
 
-        for i in range(0, len(noarch_pack_map.keys())):
-                noarch_pack_objs.insert(i, noarch_pack_map[str(i)])
-
-        return pack_objs, noarch_pack_objs
-
-
 def get_latest_version(HEAD_or_RELEASE, platform, package):
 
        version = ""

Added: trunk/release/pyutils/tests/test_web_index.py
===================================================================
--- trunk/release/pyutils/tests/test_web_index.py       2007-01-11 22:01:39 UTC 
(rev 70887)
+++ trunk/release/pyutils/tests/test_web_index.py       2007-01-11 22:11:39 UTC 
(rev 70888)
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+
+import sys
+
+import pdb
+
+sys.path += [ ".." ]
+
+import build
+
+print "Platforms:"
+objs = build.get_platform_objs()
+for i in objs:
+       print i.name
+
+print "packs:"
+objs2, objs3 = build.get_package_objs()
+for i in objs2:
+       print i.name
+
+print "noarch packs:"
+for i in objs3:
+       print i.name


Property changes on: trunk/release/pyutils/tests/test_web_index.py
___________________________________________________________________
Name: svn:executable
   + *

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to