[med-svn] r1263 - trunk/community/infrastructure/test

tille at alioth.debian.org tille at alioth.debian.org
Sat Feb 2 17:23:00 UTC 2008


Author: tille
Date: 2008-02-02 17:23:00 +0000 (Sat, 02 Feb 2008)
New Revision: 1263

Modified:
   trunk/community/infrastructure/test/cddtasktools.py
Log:
Just another snapshot (not yet working)


Modified: trunk/community/infrastructure/test/cddtasktools.py
===================================================================
--- trunk/community/infrastructure/test/cddtasktools.py	2008-02-02 15:14:48 UTC (rev 1262)
+++ trunk/community/infrastructure/test/cddtasktools.py	2008-02-02 17:23:00 UTC (rev 1263)
@@ -48,6 +48,7 @@
     def __init__(self, cddname=None, taskname=None):
         self.cddname        = cddname
         self.taskname       = taskname
+        self.pkg            = None # Name of dependant package
         self.dependencytype = None # Values: 'Depends', 'Recommends', 'Suggests'
         self.dists          = []   # Values: 'stable', 'testing', 'unstable', etc.
         self.component      = None # Values: 'main', 'contrib', 'non-free', 'experimental'
@@ -76,16 +77,150 @@
             return None
 
         self.cddname = cddname
-        tasks = "%s/%s/data/tasks" % (HTMLBASE, cddname)
+        self.tasksdir = "%s/%s/data/tasks" % (HTMLBASE, cddname)
         # Checkout/Update tasks from SVN
-        if os.path.isdir(tasks+'/.svn'):
-            os.system("svn up %s %s >> /dev/null" % (REPOS[self.cddname], tasks))
+        if os.path.isdir(self.tasksdir+'/.svn'):
+            os.system("svn up %s %s >> /dev/null" % (REPOS[self.cddname], self.tasksdir))
         else:
-            os.system("mkdir -p %s" % (tasks))
-            os.system("svn co %s %s >> /dev/null" % (REPOS[self.cddname], tasks))
+            os.system("mkdir -p %s" % (self.tasksdir))
+            os.system("svn co %s %s >> /dev/null" % (REPOS[self.cddname], self.tasksdir))
+        self.tasks = {}
+        self.available = Available()
+
+    def GetTasks(self):
+        for task in os.listdir(self.tasksdir):
+            if os.path.isfile("%s/%s" % (self.tasksdir, task)):
+                self.tasks[task] = self.GetTaskDependencies(task)
+
+    def GetAllDependencies(self):
+        if self.tasks == {}:
+            self.GetTasks()
+        for task in self.tasks:
+            self.GetTaskDependencies(task)
+
+class TaskDependencies:
+    # List of depencencies defined in one Metapackage
+    def __init__(self, cddname, task):
+        if cddname not in REPOS.keys():
+            print >>sys.stderr, "Unknown CDD."
+            return None
+
+        self.cddname = cddname
+        self.dependencies = { 'official'    : [],
+                              'unofficial'  : [],
+                              'prospective' : []
+                            }
+
+    def GetTaskDependencies(self, task):
+        # return a list of 
+        if self.tasks == {}:
+            self.GetTasks()
+
+        if task not in self.tasks:
+            print >>stderr, "Unknown task for %s. Nothing to do." % self.cddname
+            return
         
+        # First obtain information about Packages
+        # available in Debian
+        # This might take some time.
+        # Caching comes to mind, but the script is supposed
+        # to be run not more frequently than mirror pushes
+        # and thus only testing the script might profit from
+        # caching
+        self.available.GetPackageNames()
 
+        # These keys might contain more than one item that
+        # has to be separated to detect the dependency
+        dependency_keys = [ "Depends", "Recommends", "Suggests" ] 
 
+        f = file(self.tasksdir+'/'+task)
+        for stanza in deb822.Sources.iter_paragraphs(f):
+            # Why and Responsible can be valid for more than one dependency
+            # Store them in strings and use them for all Dependent Package objects
+            why         = None
+            responsible = None
+            dep         = None
+            for key in stanza:
+                if key == 'Why':
+                    why = stanza['why']
+                    continue
+                if key == 'Responsible':
+                    responsible = stanza['responsible']
+                    continue
+
+                if key in dependency_keys:
+                    # turn alternatives ('|') into real depends for this purpose
+                    # because we are finally interested in all alternatives
+                    dependencies = stanza[key].replace('|',',').split(',')
+                    # Collect all dependencies in one line first,
+                    # create an object for each later
+                    deps_in_one_line = []
+                    for dependency in dependencies:
+                        deps_in_one_line.append(dependency.strip())
+
+                    for dep_in_line in deps_in_one_line:
+                        dep = DependantPackage(self.cddname, task)
+                        # Store the comments in case they might be usefull for later applications
+                        dep.why            = why
+                        dep.responsible    = responsible
+                        dep.dependencytype = key
+                        dep.pkg            = stanza[key]
+                        dep.dists.append(self.available.dist)
+                        # Find the component the Dependency might be in
+                        for component in self.available.components:
+                            if dep.pkg in self.available.pkgnames[component]:
+                                dep.component = component
+                                break # The same package should be only in one component
+                                      # At least I currently see no reason for having a
+                                      # package with the same name in main and contrib
+                                      # at the same time for instance
+                    continue # at th
+                # The following keys will be mostly used for programs that
+                # are not yet existing in Debian and will go to our todo list
+                if key == 'Homepage':
+                    if dep != None:
+                        dep.homepage = stanza['homepage']
+                    else:
+                        print >>stderr, "Dep not initiatet before Homepage %s -> something is wrong." \
+                              % stanza['homepage']
+                elif key == 'License':
+                    if dep != None:
+                        dep.license  = stanza['license']
+                    else:
+                        print >>stderr, "Dep not initiatet before License %s -> something is wrong." \
+                              % stanza['license']
+                elif key == 'WNPP':
+                    if dep != None:
+                        dep.wnpp     = stanza['wnpp']
+                    else:
+                        print >>stderr, "Dep not initiatet before WNPP %s -> something is wrong." \
+                              % stanza['wnpp']
+                elif key == 'Pkg-URL':
+                    if dep != None:
+                        dep.pkgURL   = stanza['pkg-url']
+                    else:
+                        print >>stderr, "Dep not initiatet before Pkg-URL %s -> something is wrong." \
+                              % stanza['pkg-url']
+                elif key == 'Pkg-Description':
+                    if dep == None:
+                        print >>stderr, "Dep not initiatet before Pkg-Description %s -> something is wrong." \
+                              % stanza['pkg-description'].splitlines()[0]
+                    else:
+                        lines = stanza['pkg-description'].splitlines()
+                        dep.pkgShortDesc   = lines[0]
+                        dep.pkgLongDesc    = lines[1:].join('\n')
+                else:
+                    print "Unknown key '%s': %s" % (key, stanza[key])
+            if dep.component != None:
+                self.dependencies['official'].append(dep)
+            elif dep.pkgURL != None:
+                self.dependencies['unofficial'].append(dep)
+            else
+                self.dependencies['prospective'].append(dep)
+                
+        f.close()
+
+
 class Available:
     # Information about available packages
 
@@ -113,6 +248,10 @@
     def GetPackageNames(self):
         # Fetch Packages / Sources file and get list of package names out of it
 
+        if self.pkgnames != {}:
+            # Just got the Package names
+            return
+
         for component in self.components:
             f = urllib.urlopen(BASEURL+'/'+self.dist+'/'+component+'/'+self.binary+'/'+self.source)
             compresseddata = f.read()




More information about the debian-med-commit mailing list