SF.net SVN: gar:[23130] csw/mgar/gar/v2/lib/python/find_obsolete_pkgs.py

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue Mar 4 09:59:51 CET 2014


Revision: 23130
          http://sourceforge.net/p/gar/code/23130
Author:   wahwah
Date:     2014-03-04 08:59:50 +0000 (Tue, 04 Mar 2014)
Log Message:
-----------
find-obsolete-pkgs: Pass around rest_client

Since rest_client is necessary in a few places, let's instantiate it at the
top level and then pass the instance around between functions.

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

Modified: csw/mgar/gar/v2/lib/python/find_obsolete_pkgs.py
===================================================================
--- csw/mgar/gar/v2/lib/python/find_obsolete_pkgs.py	2014-03-04 08:59:42 UTC (rev 23129)
+++ csw/mgar/gar/v2/lib/python/find_obsolete_pkgs.py	2014-03-04 08:59:50 UTC (rev 23130)
@@ -52,18 +52,11 @@
 
 class CompCatalog(object):
 
-    def __init__(self, name, arch, osrel):
-        config = configuration.GetConfig()
-        username, password = rest.GetUsernameAndPassword()
-        self.rest_client = rest.RestClient(
-            pkgdb_url=config.get('rest', 'pkgdb'),
-            releases_url=config.get('rest', 'releases'),
-            username=username,
-            password=password)
-
+    def __init__(self, name, arch, osrel, rest_client):
         self.catrel = name
         self.arch = arch
         self.osrel = osrel
+        self.rest_client = rest_client
 
     def __getCat(self, name,arch,osrel):
         ''' get dependcy list from catalog, read cached list if available '''
@@ -100,14 +93,15 @@
         return self.__getCat(self.catrel,self.arch,self.osrel)
 
 
-def processCat(catrel,arch,osrel):
+def processCat(catrel, arch, osrel, rest_client):
     logger.info("processCat: -> %r %r %r" % (catrel, arch, osrel))
-    cc = CompCatalog(catrel,arch,osrel)
+
+    cc = CompCatalog(catrel, arch, osrel, rest_client)
     pkg_by_pkgname = cc.getCatalog()
     logger.info("processCat: iterate on %r" % (catrel))
 
     # build reverse dependency list
-    rev_deps_access = RevDeps()
+    rev_deps_access = RevDeps(rest_client)
     rev_deps_by_pkg = {}
     for pkgname in pkg_by_pkgname:
         pkg = pkg_by_pkgname[pkgname]
@@ -130,9 +124,9 @@
     return pkg_by_pkgname, rev_deps_by_pkg
 
 
-def ComputeRemoveAndRebuild(oldcatrel, newcatrel, arch, osrel):
-    newcatlst, newrevdeplst = processCat(newcatrel,arch,osrel)
-    oldcatlst, oldrevdeplst = processCat(oldcatrel,arch,osrel)
+def ComputeRemoveAndRebuild(oldcatrel, newcatrel, arch, osrel, rest_client):
+    newcatlst, newrevdeplst = processCat(newcatrel, arch, osrel, rest_client)
+    oldcatlst, oldrevdeplst = processCat(oldcatrel, arch, osrel, rest_client)
 
     to_remove_candidates = []
     rebuildlst = set()
@@ -231,8 +225,17 @@
 
 def main():
     oldcatrel, newcatrel, arch, osrel = GetCLIOptions()
+
+    config = configuration.GetConfig()
+    username, password = rest.GetUsernameAndPassword()
+    rest_client = rest.RestClient(
+        pkgdb_url=config.get('rest', 'pkgdb'),
+        releases_url=config.get('rest', 'releases'),
+        username=username,
+        password=password)
+
     reallyremovelst, rebuildlst = ComputeRemoveAndRebuild(oldcatrel, newcatrel,
-                                                          arch, osrel)
+                                                          arch, osrel, rest_client)
     WriteToTextFiles(reallyremovelst, rebuildlst, newcatrel, arch, osrel)
 
 

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



More information about the devel mailing list