Revision: 17677
          http://gar.svn.sourceforge.net/gar/?rev=17677&view=rev
Author:   wbonnet
Date:     2012-04-14 18:28:00 +0000 (Sat, 14 Apr 2012)
Log Message:
-----------
Add some statistics

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/build_tier_list.py

Modified: csw/mgar/gar/v2/lib/python/build_tier_list.py
===================================================================
--- csw/mgar/gar/v2/lib/python/build_tier_list.py       2012-04-14 17:41:15 UTC 
(rev 17676)
+++ csw/mgar/gar/v2/lib/python/build_tier_list.py       2012-04-14 18:28:00 UTC 
(rev 17677)
@@ -30,6 +30,7 @@
                                 action="store", dest="tier2", type="string")
         self.parser.add_option("-3", "--tier3-list", help="List of tier 3 
packages",
                                 action="store", dest="tier3", type="string")
+        self.parser.add_option("-s", "--simulate", help="Computes only the 
number of packages per tier. Do not output the lists", action="store_true", 
dest="simulate")
         self.parser.add_option("-V", "--verbose", help="Activate verbose 
mode", action="store_true", dest="verbose")
 
     def parse(self):
@@ -50,6 +51,11 @@
         else:
             self.verbose = False
 
+        if args.simulate != None:
+            self.simulate = args.simulate
+        else:
+            self.simulate = False
+
         if args.catalog != None:
             self.catalog = args.catalog
         else:
@@ -90,6 +96,9 @@
     def getTierOutputFile(self, tier):
        return "%(filename)s.out" % { 'filename' : self.getTierInputFile(tier) }
 
+    def getSimulate(self):
+        return self.simulate
+
     def getVerbose(self):
         return self.verbose
 
@@ -146,8 +155,8 @@
 
                # Check if tier is lower or undefined, then we need to do 
something
                if self.tier >= tier :
-                       if self.tier > tier :
-                               print "%(pkg)s : %(t1)d => %(t2)d" % { 'pkg' : 
self.name , 't1' : self.tier , 't2' : tier }
+#                      if self.tier > tier :
+#                              print "%(pkg)s : %(t1)d => %(t2)d" % { 'pkg' : 
self.name , 't1' : self.tier , 't2' : tier }
 
                        # Set the new tier value
                        self.tier = tier
@@ -162,6 +171,9 @@
        global catalog
        outputFile = {}
 
+       # Defines the counter used to stored for number of package in each tier
+       countPkg = [ [ 0, 0, 0 ] ,  [ 0, 0, 0 ] , [ 0, 0, 0 ] ]
+
        # Parse command line
        cliParser = CommandLineParser()
        (opts, args) = cliParser.parse()
@@ -174,11 +186,19 @@
                name          = pkgInfo[2]              
                depends       = pkgInfo[6]
                catalog[name] = Package(name, version, depends)
+       
+       # Iterates the catalog to compute the initial tiering before rule 
propagation 
+       for pkg in catalog:
+               countPkg[0][catalog[pkg].tier-1] += 1
 
        # Iterates the catalog once parsed to propagated tier values to depends
        for pkg in catalog:
                catalog[pkg].setTier(catalog[pkg].tier)
        
+       # Iterates the catalog to compute the tiering after rule propagation 
+       for pkg in catalog:
+               countPkg[1][catalog[pkg].tier-1] += 1
+
        for tier in (1 ,2 ,3):
                # Create the three files for outputing tier content
                outputFile[tier] = open(configParser.getTierOutputFile(tier), 
'w') 
@@ -189,14 +209,26 @@
                                name = line.split('\n') 
                                catalog[name[0]].setTier(tier)
                else:
-                       print "File %(filename)s does not exit. Skipping this 
file" %  { 'filename' : configParser.getTierInputFile(tier) }
+                       if configParser.getVerbose() == True:
+                               print "File %(filename)s does not exit. 
Skipping this file" %  { 'filename' : configParser.getTierInputFile(tier) }
 
        for pkg in catalog:
-               outputFile[catalog[pkg].tier].write("%(name)s\n" % { 'name' : 
catalog[pkg].name })
+               # If simulation mode is off the output to the file
+               if configParser.getSimulate() == False:
+                       outputFile[catalog[pkg].tier].write("%(name)s\n" % { 
'name' : catalog[pkg].name })
                
+               # Iterates the catalog to compute the tiering after rule 
propagation 
+               countPkg[2][catalog[pkg].tier-1] += 1
+
        for tier in (1 ,2 ,3):
                outputFile[tier].close()
 
+
+       if configParser.getSimulate() == True:
+               print "\tInit\tProp\tFile"
+               for tier in (0, 1 ,2 ):
+                       print "tier %(tier)d\t%(1)d\t%(2)d\t%(3)d" % { 'tier' : 
tier + 1 , '1' : countPkg[0][tier], '2' : countPkg[1][tier],'3' : 
countPkg[2][tier] }
+
 # On sort en rendant le code de retour de main
 if __name__ == '__main__':
     sys.exit(main())

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

_______________________________________________
devel mailing list
devel@lists.opencsw.org
https://lists.opencsw.org/mailman/listinfo/devel

Reply via email to