[Blends-commit] [SCM] website branch, master, updated. 1bc06676f66579fdbad9c099022f1d2ad495b00a

Ole Streicher ole at aip.de
Thu Mar 17 16:02:47 UTC 2016


The following commit has been merged in the master branch:
commit 1bc06676f66579fdbad9c099022f1d2ad495b00a
Author: Ole Streicher <ole at aip.de>
Date:   Thu Mar 17 17:01:21 2016 +0100

    Do long rendering only in the templates, not in blendstasktools

diff --git a/webtools/blendsmarkdown.py b/webtools/blendsmarkdown.py
index 46c6c7c..4710daf 100644
--- a/webtools/blendsmarkdown.py
+++ b/webtools/blendsmarkdown.py
@@ -8,7 +8,7 @@ import re
 from sys import stderr
 from markdown import markdown            # Markdown
 from docutils.core import publish_parts  # alternatively reST
-from genshi import Markup
+from genshi import Markup                # Mark the string as rendered
 
 detect_list_start_re = re.compile("^\s+[-*+]\s+")
 detect_code_start_re = re.compile("^\s")
@@ -17,6 +17,7 @@ detect_url_re = re.compile("[fh]t?tp://")
 
 
 def PrepareMarkdownInput(lines):
+    lines = lines.splitlines()
     ret = ''
     inlist = 0
     incode = 0
@@ -69,10 +70,7 @@ def PrepareMarkdownInput(lines):
         ret += line + "\n"
     return ret
 
-
-def render_longdesc(lines):
-    MarkDownInput = PrepareMarkdownInput(lines)
-
+def render_longdesc(MarkDownInput):
     global rendering_lib
     if rendering_lib == 'rest':
         try:
@@ -83,7 +81,7 @@ def render_longdesc(lines):
             LongDesc = "Problems in rendering description using reST"
     else:  # by default use Markdown
         LongDesc = markdown(MarkDownInput)
-    return LongDesc
+    return Markup(LongDesc)
 
 
 def SplitDescription(description):
@@ -91,10 +89,8 @@ def SplitDescription(description):
 
     lines = description.splitlines()
 
-    ShortDesc = lines[0].replace("&", "&") \
-                        .replace("<", "<") \
-                        .replace(">", ">")
-    LongDesc = render_longdesc(lines[1:])
+    ShortDesc = lines[0]
+    LongDesc = PrepareMarkdownInput('\n'.join(lines[1:]))
 
     return (ShortDesc, LongDesc)
 
diff --git a/webtools/blendstasktools.py b/webtools/blendstasktools.py
index 8984ae1..ed44c16 100644
--- a/webtools/blendstasktools.py
+++ b/webtools/blendstasktools.py
@@ -26,8 +26,7 @@ import email.utils
 import psycopg2
 import gettext
 
-from genshi import Markup
-from blendsmarkdown import SplitDescription, render_longdesc
+from blendsmarkdown import SplitDescription, PrepareMarkdownInput
 
 try:
     from debian import deb822
@@ -1029,13 +1028,6 @@ class Tasks:
         # Return dictionary with description information of all tasks of a Blend
         return self.tasks
 
-    def MarkupPreformatedStringsBlend(self):
-        # Genshi does not touch strings that are marked with "Markup()" - so just
-        # mark the strings that are ready formatted for the whole Blend
-        for task in self.metapackagekeys:
-            tdeps = self.tasks[task]
-            tdeps.MarkupPreformatedStrings()
-
     def LinkEnhances(self):
         # To provide a connection between packages enhancing other packages a set of links
         # will be provided.  The links should point to paragraphs on the tasks pages if the
@@ -1129,7 +1121,7 @@ class TaskDependencies:
                 self.metapkg.desc[lang] = {}
                 self.metapkg.desc[lang]['short'] = ddtptranslations['description_' + lang]
                 try:
-                    self.metapkg.desc[lang]['long'] = Markup(render_longdesc(ddtptranslations['long_description_' + lang].splitlines()))
+                    self.metapkg.desc[lang]['long'] = PrepareMarkdownInput(ddtptranslations['long_description_' + lang])
                 except AttributeError as err:
                     logger.error("===> AttributeError in metapackage long %s (lang='%s'): '%s'; ErrTxt: %s"
                                  % (self.metapkg.pkg, lang, ddtptranslations['long_description_' + lang], err))
@@ -1184,8 +1176,7 @@ class TaskDependencies:
                     else:
                         (shortDesc, longDesc) = SplitDescription(stanza['description'])
                         self.metapkg.desc['en']['short'] = shortDesc
-                        # Markup strings to enable verbatim output of preformatted text
-                        self.metapkg.desc['en']['long']  = Markup(longDesc)
+                        self.metapkg.desc['en']['long']  = longDesc
                         found_description = True
                     continue
                 if key == 'Meta-Depends':
@@ -1425,7 +1416,7 @@ class TaskDependencies:
                     else:
                         _pkg = dep.pkg
                     remark['short'] = shortDesc
-                    remark['long']  = Markup(longDesc)
+                    remark['long']  = longDesc
                     continue
                 else:
                     if key not in KEYSTOIGNORE:
@@ -1608,7 +1599,7 @@ class TaskDependencies:
                         dep.desc[l] = {}
                         dep.desc[l]['short'] = row['description_' + l]
                         if row['long_description_' + l]:
-                            dep.desc[l]['long']  = Markup(render_longdesc(row['long_description_' + l].splitlines()))
+                            dep.desc[l]['long']  = PrepareMarkdownInput(row['long_description_' + l])
                 if 'short' not in dep.desc['en']:
                     logger.error("Dep has no English short description: %s", dep.pkg)
                     dep.desc['en']['short'] = "??? missing short description for package %s :-(" % dep.pkg
@@ -1668,7 +1659,7 @@ class TaskDependencies:
                 for prop in PROPERTIES:
                     dep.properties[prop] = row[prop]
                 dep.desc['en']['short'] = row['description_en']
-                dep.desc['en']['long']  = Markup(render_longdesc(row['long_description_en'].splitlines()))
+                dep.desc['en']['long']  = PrepareMarkdownInput(row['long_description_en'])
                 if row['maintainer']:
                     (_name, _url) = email.utils.parseaddr(row['maintainer'])
                     dep.properties['maintainer_name'] = _name
@@ -1753,7 +1744,7 @@ class TaskDependencies:
                     dep.properties['wnpp'] = row['wnpp']
                 dep.SetPublications(row)
                 dep.desc['en']['short'] = row['description_en']
-                dep.desc['en']['long']  = Markup(render_longdesc(row['long_description_en'].splitlines()))
+                dep.desc['en']['long'] = PrepareMarkdownInput(row['long_description_en'])
                 if row['maintainer']:
                     (_name, _url) = email.utils.parseaddr(row['maintainer'])
                     dep.properties['maintainer_name'] = _name
@@ -1908,19 +1899,6 @@ class TaskDependencies:
         for dependency in self.dependencies.values():
             dependency.sort()
 
-    def MarkupPreformatedStrings(self):
-        # Genshi does not touch strings that are marked with "Markup()" - so just
-        # mark the strings that are ready formatted
-
-        for dependency in self.dependencies.values():
-            for dep in dependency:
-                if dep.desc['en'] != {}:
-                    try:
-                        dep.desc['en']['long'] = Markup(dep.desc['en']['long'])
-                    except KeyError:
-                        logger.error("Dep has no English long description: %s", dep.pkg)
-                        dep.desc['en']['long'] = "??? Missing long description for package %s" % dep.pkg
-
     def __str__(self):
         ret = "Blend: " + self.blendname + ", " \
               "Task:"   + self.task      + ", " \
diff --git a/webtools/blendstasktools_udd.py b/webtools/blendstasktools_udd.py
index 07f4473..ddedbf1 100644
--- a/webtools/blendstasktools_udd.py
+++ b/webtools/blendstasktools_udd.py
@@ -22,8 +22,7 @@ import email.utils
 
 import psycopg2
 
-from genshi import Markup
-from blendsmarkdown import SplitDescription, render_longdesc
+from blendsmarkdown import SplitDescription, PrepareMarkdownInput
 
 try:
     from debian import deb822
@@ -949,13 +948,6 @@ class Tasks:
         # Return dictionary with description information of all tasks of a Blend
         return self.tasks
 
-    def MarkupPreformatedStringsBlend(self):
-        # Genshi does not touch strings that are marked with "Markup()" - so just
-        # mark the strings that are ready formatted for the whole Blend
-        for task in self.metapackagekeys:
-            tdeps = self.tasks[task]
-            tdeps.MarkupPreformatedStrings()
-
     def LinkEnhances(self):
         # To provide a connection between packages enhancing other packages a set of links
         # will be provided.  The links should point to paragraphs on the tasks pages if the
@@ -1040,7 +1032,7 @@ class TaskDependencies:
                 self.metapkg.desc[lang] = {}
                 self.metapkg.desc[lang]['short'] = ddtptranslations['description_' + lang]
                 try:
-                    self.metapkg.desc[lang]['long'] = Markup(render_longdesc(ddtptranslations['long_description_' + lang].splitlines()))
+                    self.metapkg.desc[lang]['long'] = PrepareMarkdownInput(dtptranslations['long_description_' + lang])
                 except AttributeError as err:
                     logger.error("===> AttributeError in metapackage long %s (lang='%s'): '%s'; ErrTxt: %s"
                                  % (self.metapkg.pkg, lang, ddtptranslations['long_description_' + lang], err))
@@ -1207,7 +1199,7 @@ class TaskDependencies:
                     dep.desc[l] = {}
                     dep.desc[l]['short'] = row['description_' + l]
                     if row['long_description_' + l]:
-                        dep.desc[l]['long']  = Markup(render_longdesc(row['long_description_' + l].splitlines()))
+                        dep.desc[l]['long']  = PrepareMarkdownInput(row['long_description_' + l])
             if 'short' not in dep.desc['en']:
                 logger.error("Dep has no English short description: %s", dep.pkg)
                 dep.desc['en']['short'] = "??? missing short description for package %s :-(" % dep.pkg
@@ -1222,7 +1214,7 @@ class TaskDependencies:
             if row.get('remark'):
                 (shortDesc, longDesc) = SplitDescription(row['remark'])
                 dep.remark['short'] = shortDesc
-                dep.remark['long']  = Markup(longDesc)
+                dep.remark['long']  = longDesc
 
             # Publications
             dep.SetPublications(row)
@@ -1243,8 +1235,7 @@ class TaskDependencies:
         if curs.rowcount > 0:
             self.metapkg.PrintedName, shortDesc, longDesc = curs.fetchone()
             self.metapkg.desc['en']['short'] = shortDesc
-            # Markup strings to enable verbatim output of preformatted text
-            self.metapkg.desc['en']['long']  = Markup(longDesc)
+            self.metapkg.desc['en']['long']  = PrepareMarkdownInput(longDesc)
 
 
         # Get the package_name, license, dependency of the official dependencies of the task
@@ -1327,19 +1318,6 @@ class TaskDependencies:
 
         return 1
 
-    def MarkupPreformatedStrings(self):
-        # Genshi does not touch strings that are marked with "Markup()" - so just
-        # mark the strings that are ready formatted
-
-        for dependency in self.dependencies.values():
-            for dep in dependency:
-                if dep.desc['en'] != {}:
-                    try:
-                        dep.desc['en']['long'] = Markup(dep.desc['en']['long'])
-                    except KeyError:
-                        logger.error("Dep has no English long description: %s", dep.pkg)
-                        dep.desc['en']['long'] = "??? Missing long description for package %s" % dep.pkg
-
     def __str__(self):
         ret = "Blend: " + self.blendname + ", " \
               "Task:"   + self.task      + ", " \
diff --git a/webtools/tasks.py b/webtools/tasks.py
index 3ae86f4..292b109 100755
--- a/webtools/tasks.py
+++ b/webtools/tasks.py
@@ -28,7 +28,6 @@ tasks    = Tasks(argv[1])
 tasks.GetAllDependencies()
 packages = tasks.GetNamesOnlyDict()
 tasks.GetAllDependentPackagesOfBlend()
-tasks.MarkupPreformatedStringsBlend()
 
 data = tasks.data
 data['timestamp']        = formatdate(time.mktime(datetime.now().timetuple()))
diff --git a/webtools/tasks_udd.py b/webtools/tasks_udd.py
index 4fef57e..79cff2c 100755
--- a/webtools/tasks_udd.py
+++ b/webtools/tasks_udd.py
@@ -28,7 +28,6 @@ tasks    = Tasks(argv[1])
 tasks.GetAllDependencies()
 packages = tasks.GetNamesOnlyDict()
 tasks.GetAllDependentPackagesOfBlend()
-tasks.MarkupPreformatedStringsBlend()
 
 data = tasks.data
 data['timestamp']        = formatdate(time.mktime(datetime.now().timetuple()))
diff --git a/webtools/templates/packagelist.xhtml b/webtools/templates/packagelist.xhtml
index c42f9f0..cc69ea1 100644
--- a/webtools/templates/packagelist.xhtml
+++ b/webtools/templates/packagelist.xhtml
@@ -9,6 +9,8 @@
 <link href="/css/sentinel.css" type="text/css" rel="stylesheet"/>
 </head>
 <body>
+     <?python
+      from blendsmarkdown import render_longdesc ?>
 <div style="text-align: center;">
 <a href="$projecturl"><span py:choose="logourl">
 	           <span py:when="None">${projectname} Project</span>
@@ -47,8 +49,8 @@
 	<span py:otherwise="">${tasks[task].metapkg.desc['en']['short']}</span>
 	</span></a></h2>
 	<p py:choose="">
-	  <span py:when="lang in tasks[task].metapkg.desc">${tasks[task].metapkg.desc[lang]['long']}</span>
-	  <span py:otherwise="">${tasks[task].metapkg.desc['en']['long']}</span>
+	  <span py:when="lang in tasks[task].metapkg.desc">${render_longdesc(tasks[task].metapkg.desc[lang]['long'])}</span>
+	  <span py:otherwise="">${render_longdesc(tasks[task].metapkg.desc['en']['long'])}</span>
 	</p>
 	<py:for each="pstatus in dependencies[task]">
 	  <h3>${headline[pstatus]}</h3>
diff --git a/webtools/templates/packages.xhtml b/webtools/templates/packages.xhtml
index 7f0ed90..8788861 100644
--- a/webtools/templates/packages.xhtml
+++ b/webtools/templates/packages.xhtml
@@ -175,6 +175,8 @@ function show_fulldesc(hash) {
   </script>
   </head>
   <body onload="show_fulldesc(window.location.hash)">
+     <?python
+      from blendsmarkdown import render_longdesc ?>
     <div id="header">
       <div id="upperheader">
 	<div id="logo">
@@ -224,13 +226,13 @@ function show_fulldesc(hash) {
 	    <a class="editlink" title="${fixtranslation}" href="http://ddtp.debian.net/ddtss/index.cgi/${lang}/forexternalreview/${tasks[task].metapkg.pkg}" py:if="lang != 'en'">
 	      ✏
 	    </a>
-	    ${tasks[task].metapkg.desc[lang]['long']}
+	    ${render_longdesc(tasks[task].metapkg.desc[lang]['long'])}
 	  </py:when>
 	  <py:otherwise>
 	    <a class="editlink" title="${translatedesc}" href="http://ddtp.debian.net/ddtss/index.cgi/${lang}/fetch?package=${tasks[task].metapkg.pkg}" py:if="lang != 'en'">
 	      ✏
 	    </a>
-	    ${tasks[task].metapkg.desc['en']['long']}
+	    ${render_longdesc(tasks[task].metapkg.desc['en']['long'])}
 	  </py:otherwise>
 	</py:choose>
 	<table width="90%">
@@ -362,9 +364,9 @@ function show_fulldesc(hash) {
 			  <a class="editlink" title="${fixtranslation}" href="http://ddtp.debian.net/ddtss/index.cgi/${lang}/forexternalreview/${project.pkg}">
 			    ✏
 			  </a>
-			  ${project.desc[lang]['long']}
+			  ${render_longdesc(project.desc[lang]['long'])}
 			</py:when>
-			<py:otherwise>${project.desc['en']['long']}</py:otherwise>
+			<py:otherwise>${render_longdesc(project.desc['en']['long'])}</py:otherwise>
 		      </py:choose>
 		    </dd>
 		    <py:if test="'published' in project.properties">
@@ -586,7 +588,7 @@ function show_fulldesc(hash) {
 		      <dt>Remark</dt>
 		      <dd>
 			<py:if test="project.remark['short']">${project.remark['short']}</py:if>
-			<py:if test="project.remark['long']">${project.remark['long']}</py:if>
+			<py:if test="project.remark['long']">${render_longdesc(project.remark['long'])}</py:if>
 		      </dd>
 		    </py:if>
 		    <py:if test="project.component == 'main'
diff --git a/webtools/templates/tasks.xhtml b/webtools/templates/tasks.xhtml
index d7e2577..0a387e1 100644
--- a/webtools/templates/tasks.xhtml
+++ b/webtools/templates/tasks.xhtml
@@ -9,6 +9,8 @@
 <link href="/css/sentinel.css" type="text/css" rel="stylesheet"/>
 </head>
 <body>
+     <?python
+      from blendsmarkdown import render_longdesc ?>
 <script type="text/javascript" src="/js/wz_tooltip.js"></script>
 <div style="text-align: center;">
 <a href="$projecturl"><span py:choose="logourl">
@@ -33,10 +35,10 @@
 				  <div py:otherwise="">${tasks[task].metapkg.desc['en']['short']}</div>
 				</div>
 				<p><span py:choose="">
-	           <span py:when="lang in tasks[task].metapkg.desc">${tasks[task].metapkg.desc[lang]['long']}
+	           <span py:when="lang in tasks[task].metapkg.desc">${render_longdesc(tasks[task].metapkg.desc[lang]['long'])}
                      <div class="transmpkg" py:if="lang != 'en'"><a href="http://ddtp.debian.net/ddtss/index.cgi/${lang}/forexternalreview/${tasks[task].metapkg.pkg}">${fixtranslation}</a></div>
                    </span>
-	           <span py:otherwise="">${tasks[task].metapkg.desc['en']['long']}
+	           <span py:otherwise="">${render_longdesc(tasks[task].metapkg.desc['en']['long'])}
                      <div class="transmpkg" py:if="lang != 'en'"><a href="http://ddtp.debian.net/ddtss/index.cgi/${lang}/fetch?package=${tasks[task].metapkg.pkg}">${translatedesc}</a></div>
                    </span>
                  </span></p>
@@ -154,8 +156,8 @@
          </tr>
          <tr>
            <td colspan="2" class="project-description"><span py:choose="">
-	           <span py:when="lang in project.desc">${project.desc[lang]['long']}</span>
-	           <span py:otherwise="">${project.desc['en']['long']}</span>
+	           <span py:when="lang in project.desc">${render_longdesc(project.desc[lang]['long'])}</span>
+	           <span py:otherwise="">${render_longdesc(project.desc['en']['long'])}</span>
 	         </span>
 	     <div class="enhanced-by" py:if="project.properties['Enhances'] != {}">
 	       The package is enhanced by the following packages: <py:for each="enh in sorted(project.properties['Enhances'].keys())">
@@ -218,7 +220,7 @@
 	 <tr py:if="project.remark">
 	   <td colspan="3" class="remark">
 	     <div py:if="project.remark['short']"><strong>Remark of ${projectname} team:</strong> ${project.remark['short']}</div>
-	     <div py:if="project.remark['long']">${project.remark['long']}</div>
+	     <div py:if="project.remark['long']">${render_longdesc(project.remark['long'])}</div>
 	   </td>
 	 </tr>
        </tbody>

-- 
Static and dynamic websites for Debian Pure Blends



More information about the Blends-commit mailing list