[Blends-commit] [SCM] blends-gsoc branch, master, updated. a5e08eb70db55460ee99caf964bd47831c9bbc2e

Emmanouil Kiagias e.kiagias at gmail.com
Fri Jul 5 13:02:28 UTC 2013


The following commit has been merged in the master branch:
commit a5e08eb70db55460ee99caf964bd47831c9bbc2e
Author: Emmanouil Kiagias <e.kiagias at gmail.com>
Date:   Fri Jul 5 15:01:54 2013 +0200

    Now blend-gen-control uses all the new blends_tasks fields(Leaf,Section etc), I also implemented a first idea of using the new blends_dependencies_alternatives, now task-description files and control files should be generated properly(no more data or headers from task files are missing and alternative package are included and handled properly). At first look the generated files look ok BUT they are not test it yet, i need to spend some time the data from UDD agrees with the new files. Also tomorrow days I will implement another way of using the blends_dependencies_alternatives table(an idea my mentor Andreas Tille proposed)

diff --git a/blend-gen-control b/blend-gen-control
index 1a81aa1..c7b7a9b 100755
--- a/blend-gen-control
+++ b/blend-gen-control
@@ -86,7 +86,7 @@ class UDD_connector:
         """
         It queries the UDD and returns a list with all the available Debian architectures
         """
-        query = "select distinct architecture from packages"
+        query = "select distinct architecture from packages where architecture != 'all'"
 
         self.__execute_query(query)
 
@@ -135,9 +135,10 @@ class UDD_connector:
         blends_dependencies = {}
 
         query="""
-            SELECT distinct t.task, t.description, t.metapackage, t.long_description
-                FROM blends_tasks t
-            WHERE t.blend='{0}'
+            SELECT task, description, section as "Section", enhances as "Enhances", leaf as "Leaf",
+                  metapackage, test_always_lang, long_description
+                FROM blends_tasks
+            WHERE blend='{0}'
             """.format(blendname)
 
         self.__execute_query(query)
@@ -162,39 +163,113 @@ class UDD_connector:
                 #results[i+1] cause we start from index 1 (desc[1:]) and not from 0
                 blends_dependencies[task][column[0]] = result[i+1]
 
-            #FIXME for the moment just initialize these headers with default values, later
-            #they will be taken from the new blends_tasks table
-            blends_dependencies[task]["Section"] = "misc"
+            #the proposed priority is extra for all Blends
             blends_dependencies[task]["Priority"] = "extra"
-            blends_dependencies[task]["Enhances"] = None
 
             #also initialize empty lists for the following keys:
-            for key in ["Depends", "Recommends", "Suggests", "Ignores"]:
+            for key in ["Depends", "Recommends", "Suggests", "Ignores", "Avoid"]:
                 blends_dependencies[task][key] = []
             
-
             result = self.cursor.fetchone()
-        
+            
         return blends_dependencies
 
-    ##FIXME: for the moment it returns a dataset even if an invalid architecture is provided cause inside
-    #the sql query we select also the packages with architecture 'all', so (almost?)always it return some packages
+
+    #TODO, this method will be used to implement my idea about blend_dependencies
+    def __get_blend_alternatives(self, **kwargs):
+        """
+        It returns a dictionary containing the alternatives packages per task of a Blend
+        """
+        self.logger.debug("get_blend_alternatives function was called")
+
+        blendname = kwargs['blend'] 
+        blend_alternatives = {}
+
+        query="""
+            SELECT  task, dependency, alternatives FROM blends_dependencies_alternatives
+              WHERE blend='{0}' and alternatives like '%|%'
+            """.format(blendname)
+
+        self.__execute_query(query)
+
+        #indexes of row: task(0), alternatives(1), dependency(2)
+        row = self.cursor.fetchone()
+
+        while not row is None:
+            task = row[0]
+            dependency = row[1]
+            alternatives = row[2]
+
+            if not task in blend_alternatives:
+                blend_alternatives[task] = {}
+                for header in [ "Depends", "Suggests", "Recommends", "Avoid", "Ignores"]:
+                    blend_alternatives[task][header] = []
+
+            if dependency == 'd':
+                blend_alternatives[task]["Depends"].append(alternatives)
+            if dependency == 'r':
+                blend_alternatives[task]["Recommends"].append(alternatives)
+            if dependency == 'i':
+                blend_alternatives[task]["Ignores"].append(alternatives)
+            if dependency == 's':
+                blend_alternatives[task]["Suggests"].append(alternatives)
+            if dependency == 'a':
+                blend_alternatives[task]["Avoid"].append(alternatives)
+
+            row = self.cursor.fetchone()
+
+        #TODO, comment out this debug message
+        self.logger.debug("Dumping out  the collected alternatives")
+        self.logger.debug(blend_alternatives)
+
+        return blend_alternatives
+
+
+    def __resolve_alternatives(self, package_list, alternatives):
+        """
+        This method will convert single packages according to the alternatives.
+        For example the following lists: package_list = [ 'k3b', 'brasero' ,  'k3b-i18n'] 
+        and alternatives = [ 'k3b | brasero' ,  'k3b-i18n | brasero' ], and return this ['k3b | brasero', 'k3b-i18n | brasero']
+        """
+        seen = []
+        resolved_list = []
+        for alter in alternatives:
+            #strip the spaces from the beginning and the end of the str packages
+            temp_alters = [ al.strip() for al in alter.split('|') ]
+            alt_exists = []
+            for alt in temp_alters:
+                if alt in package_list:
+                    seen.append(alt)
+                    alt_exists.append(alt)
+            
+            if alt_exists:
+                resolved_list.append(' | '.join(alt_exists))
+        
+        for package in package_list:
+            if not package in seen:
+                resolved_list.append(package)
+
+
+        return resolved_list
+
+
     def get_blend_dependecies(self, **kwargs):
         """
         Using the given arguments queries UDD and returns a dictionary containing
         all the blends' tasks dependencies
         """
+        self.logger.debug("get_blend_dependecies function was called.")
+
         blend = kwargs["blend"]
         release = kwargs["release"]
         architecture = kwargs["architecture"]
         nodepends = kwargs["nodepends"]
 
-        self.logger.debug("get_blend_dependecies function was called.")
-
         #initialize the tasks' info before getting the dependencies for the tasks
         blend_dependencies = self.__get_tasks_info(blend = blend, release = release, tasksprefix = kwargs["tasksprefix"])
         available = []
         missing = []
+        excluded = []
 
         query = """
             SELECT b.task, b.package, b.dependency, b.distribution, pkg.component, pkg.architecture
@@ -240,9 +315,11 @@ class UDD_connector:
             if dependency == 'i':
                 blend_dependencies[task]["Ignores"].append(package)
                 missing.append(package)
-                #TODO check again, here I imitate the old blends-dev load_task function
                 increase_packages = False
-
+            if dependency == 'a':
+                blend_dependencies[task]["Avoid"].append(package)
+                excluded.append(package)
+                increase_packages = False
 
             #not sure if i should add these packages into the missing
             if not distribution == 'debian' or not component == 'main' or arch is None:
@@ -255,9 +332,35 @@ class UDD_connector:
 
             row = self.cursor.fetchone()
 
+        #once we have all the dependencies we will get the alternatives
+        blend_alternatives = self.__get_blend_alternatives(blend = blend)
+
+        #and now we will resolve the alternatives in the single dependencies for each header
+        for task in blend_dependencies:
+            if not task in blend_alternatives:
+                continue
+
+            self.logger.debug("PRINT ALTERNATIVES")
+
+            if nodepends:
+                temp_depends = blend_alternatives[task]["Depends"]
+                temp_recommends = blend_alternatives[task]["Recommends"]
+                blend_alternatives[task]["Recommends"] = temp_depends + temp_recommends
+            
+            for header in [ "Depends", "Recommends", "Suggests", "Ignores", "Avoid" ]:
+                if blend_alternatives[task][header]:
+                    package_list = blend_dependencies[task][header]
+                    alternatives = blend_alternatives[task][header]
+
+                    #change previous package list with the alternatives resolved package list
+                    blend_dependencies[task][header] = self.__resolve_alternatives(package_list, alternatives)
+
+        #self.logger.debug("RESOLVED SINGLE LIST")
+        #self.logger.debug(pprint.pformat(blend_dependencies))
+
         #return the depenencies with the corrensponding architecture
         return ({ "architecture" : architecture, "tasks" : blend_dependencies }, { "available" : available, "architecture" : architecture},
-                     {"missing" : missing, "architecture" : architecture })
+                     {"missing" : missing, "architecture" : architecture }, {'excluded' : excluded, 'architecture' : architecture})
 
 
 def gen_control(**kwargs):
@@ -345,10 +448,16 @@ def gen_task_desc(**kwargs):
 
         for task in sorted(blend_dependencies.keys()):    
 
-            if suppressempty and blend_dependencies[task]["haspackages"] == 0:
-                logger.debug("The metapackage {2} will not be created because {0} dependant are in the pool and suppressempty was set {1}\n".format(blend_dependencies[task]["haspackages"], suppressempty, task))
+            if blend_dependencies[task]['Leaf'] == 'false':
                 continue
 
+            if suppressempty and blend_dependencies[task]["haspackages"] == 0:
+                if blend_dependencies[task]['test_always_lang']:
+                    logger.debug("Print empty task {0} because Test-always-lang is set\n".format(task))
+                else:
+                    logger.debug("The metapackage {2} will not be created because {0} dependant are in the pool and suppressempty was set {1}\n".format(blend_dependencies[task]["haspackages"], suppressempty, task))
+                    continue
+
             fout.write("Task: {0}-{1}\n".format(tasksprefix, task))
             fout.write("Section: {0}\n".format(blend));
             fout.write("Description: {0}\n".format(blend_dependencies[task]["description"]))
@@ -365,7 +474,18 @@ def gen_task_desc(**kwargs):
 
             fout.write("Packages: list\n ")
             for header in ["Depends", "Recommends"]:
-                fout.write("{0}".format("\n ".join(sorted(blend_dependencies[task][header]))))
+                if not blend_dependencies[task][header]:
+                    continue
+                #Tasksel doesn't allow boolean(eg OR : |) comparisons in dependencies such as package1 | package2.
+                #so we include in the list the first of the alternative packages
+                alternatives_resolved = []
+                for pkg in blend_dependencies[task][header]:
+                    if '|' in pkg:
+                        alternatives_resolved.append(pkg.split('|')[0])
+                    else:
+                        alternatives_resolved.append(pkg)
+
+                fout.write("{0}".format("\n ".join(sorted(alternatives_resolved))))
 
             fout.write("\n\n")
 
@@ -448,7 +568,7 @@ def main():
         #generate a control for each provided architecture
         for arch in architectures:
             #get all the blends dependencies etc
-            blend_dependencies, available, missing = myudd.get_blend_dependecies(blend = blend_info["blend"], release = release, 
+            blend_dependencies, available, missing, excluded = myudd.get_blend_dependecies(blend = blend_info["blend"], release = release, 
                 architecture = arch, tasksprefix = blend_info["tasksprefix"], nodepends = nodepends)
             
             gen_control(blend_info = blend_info, blend_dependencies = blend_dependencies,
@@ -459,7 +579,7 @@ def main():
         for arch in architectures:
             #we reuse the same code as above here BUT we need the blend_dependencies here without nodepends so we make sure we call it
             #with nodepends = False no matter the command line argument, no need to descrease depends to recommends in any way for task description
-            blend_dependencies, available, missing = myudd.get_blend_dependecies(blend = blend_info["blend"], release = release, 
+            blend_dependencies, available, missing, excluded = myudd.get_blend_dependecies(blend = blend_info["blend"], release = release, 
                 architecture = arch, tasksprefix = blend_info["tasksprefix"], nodepends = False)
             
             gen_task_desc(blend_info = blend_info, blend_dependencies = blend_dependencies,
diff --git a/sql/blendsd b/sql/blendsd
index 1e49027..6ffe697 100755
--- a/sql/blendsd
+++ b/sql/blendsd
@@ -10,5 +10,5 @@ SELECT b.blend, b.task, b.package, b.dependency, b.distribution, pkg.component,
        FROM all_packages p JOIN releases r ON p.release = r.release 
        WHERE r.role='$2' and architecture in ('$3', 'all' )) pkg ON b.package = pkg.package
   WHERE b.blend='$1'
-ORDER BY b.package, b.task
+ORDER BY b.package
 EOT
diff --git a/sql/get_alternatives b/sql/get_alternatives
new file mode 100644
index 0000000..ca8ef90
--- /dev/null
+++ b/sql/get_alternatives
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+#arguments: blends
+#example of usage ./get_alternatives debian-med
+
+#query to get all the existing alternatives packages from the task files
+#this query will ne used to implement my idea, aftewards I will implement Andreas' idea.
+#relavant discussion: https://lists.debian.org/debian-blends/2013/07/msg00010.html
+psql udd << EOT
+SELECT  task, dependency, alternatives
+    FROM blends_dependencies_alternatives
+  WHERE blend='$1' and alternatives like '%|%'
+ORDER BY task
+EOT
diff --git a/sql/tasksinfo b/sql/tasksinfo
index 4f1495d..654cf79 100755
--- a/sql/tasksinfo
+++ b/sql/tasksinfo
@@ -3,13 +3,12 @@
 #arguments: blends, tasksprefix, release-role
 #example of usage ./taskinfo debian-med med testing
 
-#this sql is no more used in blend-gen-control because of "circular dependency" and
-#also these fields(Section, Enhances etc) will be included in blends_tasks
-#relevant discussion : http://lists.debian.org/debian-blends/2013/06/msg00025.html
+#updated blends_tasks table now contains all the info we need and we can get it with a simple query as:
+#relevant mail with the update: https://lists.debian.org/debian-blends/2013/06/msg00034.html
 psql udd << EOT
-SELECT  distinct t.task, t.description, p.priority as "Priority", p.section as "Section", p.enhances as "Enhances"
-    FROM blends_tasks t LEFT OUTER JOIN packages p ON  '$2-' || t.task  = p.package 
-    	LEFT OUTER JOIN releases r ON p.release = r.release
-  WHERE t.blend='$1' and (r.role = '$3' or r.role is NULL )
-ORDER BY t.task
+SELECT  task, description, section as "Section", enhances as "Enhances", leaf as "Leaf",
+	  metapackage, test_always_lang
+    FROM blends_tasks 
+  WHERE blend='$1'
+ORDER BY task
 EOT

-- 
Git repository for blends-gsoc code



More information about the Blends-commit mailing list