[Blends-commit] [SCM] website branch, master, updated. 62b4b5d8b2d72459d39faf2a7c535e06ba4b8f6f

Ole Streicher olebole at debian.org
Mon Jan 11 13:31:10 UTC 2016


The following commit has been merged in the master branch:
commit 5fa8bf13933a7f57dc39757f52ae9a38ff78d075
Author: Ole Streicher <olebole at debian.org>
Date:   Mon Jan 11 09:04:38 2016 +0100

    Replace print(.., file=f) with f.write() and most open/close sequences with 'with'

diff --git a/webtools_py3/tasks_udd.py b/webtools_py3/tasks_udd.py
index 8181029..a0305e2 100755
--- a/webtools_py3/tasks_udd.py
+++ b/webtools_py3/tasks_udd.py
@@ -80,14 +80,14 @@ try:
 except: # simply continue if file does not exist
 	pass
 htafp = open(htaccess, 'w')
-print("DirectoryIndex index index.html\nOptions +MultiViews", file=htafp)
+htafp.write("DirectoryIndex index index.html\nOptions +MultiViews\n")
 
 detect_javascript_code_re = re.compile("onmouseover=\"Tip\(\\'")
 detect_ampersand_code_re  = re.compile("href=\"http://\w+\.debian\.org/.+\?\w+=")
 
 use_dependencystatus = GetDependencies2Use()
 for lang in languages:
-    print("AddLanguage %s .%s" % (language_dict[lang]['htaccess'], lang), file=htafp)
+    htafp.write("AddLanguage %s .%s\n" % (language_dict[lang]['htaccess'], lang))
     l10nstring[lang].install()
     # _ = l10nstring[lang].ugettext
     data['lang']              = lang
@@ -183,14 +183,12 @@ for lang in languages:
         os.unlink(outputfile)
     except: # simply continue if file does not exist
 	    pass
-    f = open(outputfile, 'w')
-    try:
-	    print(template.generate(**data).render('xhtml'), file=f)
-    except UnicodeDecodeError as errtxt:
+    with open(outputfile, 'w') as f:
+        try:
+	    f.write(template.generate(**data).render('xhtml'))
+        except UnicodeDecodeError as errtxt:
 	    print("Some critical encoding problem occured when trying to render index for lang %s.\n%s" \
-		    % (lang, errtxt), file=stderr)
-		
-    f.close()
+		  % (lang, errtxt), file=stderr)
     SetFilePermissions(outputfile)
     try:
         template = loader.load('%s_idx.xhtml' % tasks.blendname)
@@ -201,14 +199,13 @@ for lang in languages:
             os.unlink(outputfile)
         except: # simply continue if file does not exist
             pass
-        f = open(outputfile, 'w')
-        try:
-            print(template.generate(**data).render('xhtml'), file=f)
-        except UnicodeDecodeError as errtxt:
-            print("Some critical encoding problem occured when trying to render index for lang %s.\n%s"
-                  % (lang, errtxt), file = stderr)
+        with open(outputfile, 'w') as f:
+            try:
+                f.write(template.generate(**data).render('xhtml'))
+            except UnicodeDecodeError as errtxt:
+                print("Some critical encoding problem occured when trying to render index for lang %s.\n%s"
+                      % (lang, errtxt), file = stderr)
 
-        f.close()
         SetFilePermissions(outputfile)
     except:
         pass
@@ -264,37 +261,35 @@ for lang in languages:
             template = loader.load('packages.xhtml')
         else:
             template = loader.load('tasks.xhtml')
-        f = open(outputfile+'_tmp', "w")
-        try:
-            print(template.generate(**data).render('xhtml'), file=f)
-        except UnicodeEncodeError as errtxt:
-            print("Some critical encoding problem occured when trying to render task %s for lang %s.\n%s" \
-			      % (task, lang, errtxt))
-        except UnicodeDecodeError as errtxt:
-            print("Some critical encoding problem occured when trying to render task %s for lang %s.\n%s" \
-			     % (task, lang, errtxt), file=stderr)
-        except UndefinedError as errtxt:
-            print("UndefinedError while rendering task %s for lang %s.\n%s" \
-			     % (task, lang, errtxt), file=stderr)
-        f.close()
+        with open(outputfile+'_tmp', "w") as f:
+            try:
+                f.write(template.generate(**data).render('xhtml'))
+            except UnicodeDecodeError as errtxt:
+                print("Some critical encoding problem occured when trying to render task %s for lang %s.\n%s" \
+		      % (task, lang, errtxt), file=stderr)
+            except UndefinedError as errtxt:
+                print("UndefinedError while rendering task %s for lang %s.\n%s" \
+		      % (task, lang, errtxt), file=stderr)
         SetFilePermissions(outputfile+'_tmp')
         # Really rude hack to get back '<' / '>' signs which actually shoul be
         # in the output
-        tmp = open(outputfile+'_tmp', "r")
-        f   = open(outputfile, "w")
-        for line in tmp.readlines():
-            # We had to mask ampersand ('&') from Genshi but even if the browser shows
-            # the correct character packages.debian.org gets confused - so turn it back here
-            if detect_ampersand_code_re.search(line):
-                line = re.sub('%26', '&', line)
-            print(line, end=' ', file=f)
-        f.close()
-        tmp.close()
+        with open(outputfile+'_tmp', "r") as tmp:
+            with open(outputfile, "w") as f:
+                for line in tmp.readlines():
+# We had to mask ampersand ('&') from Genshi but even if the browser shows
+# the correct character packages.debian.org gets confused - so turn it back here
+                    if detect_ampersand_code_re.search(line):
+                        line = re.sub('%26', '&', line)
+                        f.write(line)
         os.unlink(outputfile+'_tmp')
         SetFilePermissions(outputfile)
 
     template = loader.load('packagelist.xhtml')
 
+    data['projectsintasks'] = []
+    for task in data['taskskeys']:
+        data['projectsintasks']     = tasks.tasks[task].dependencies
+
     outputfile = outputdir + '/packagelist'
     if lang != 'xyz': # let 'en' be a language as any other and add suffix to file name
         outputfile += '.' + lang + '.html'
@@ -302,29 +297,21 @@ for lang in languages:
         os.unlink(outputfile)
     except: # simply continue if file does not exist
         pass
-    f = open(outputfile, 'w')
-
-    data['projectsintasks'] = []
-    for task in data['taskskeys']:
-        data['projectsintasks']     = tasks.tasks[task].dependencies
-
-    try:
-        print(template.generate(**data).render('xhtml'), file=f)
-    except UnicodeDecodeError as errtxt:
-        print("Some critical encoding problem occured when trying to render long package list for lang %s.\n%s" \
-		    % (lang, errtxt), file=stderr)
-    except UndefinedError as errtxt:
-        print("UndefinedError while trying to render long package list for lang %s.\n%s" \
-		    % (lang, errtxt), file=stderr)
-		
-    f.close()
+    with open(outputfile, 'w') as f:
+        try:
+            f.write(template.generate(**data).render('xhtml'))
+        except UnicodeDecodeError as errtxt:
+            print("Some critical encoding problem occured when trying to render long package list for lang %s.\n%s" \
+		  % (lang, errtxt), file=stderr)
+        except UndefinedError as errtxt:
+            print("UndefinedError while trying to render long package list for lang %s.\n%s" \
+		  % (lang, errtxt), file=stderr)
     SetFilePermissions(outputfile)
 
-
-print("LanguagePriority", end=' ', file=htafp)
+htafp.write("LanguagePriority ")
 for lang in languages:
-    print(language_dict[lang]['htaccess'], end=' ', file=htafp)
-print(file=htafp)
+    htafp.write(language_dict[lang]['htaccess'] + ' ')
+htafp.write("\n")
 
 htafp.close()
 SetFilePermissions(htaccess)

-- 
Static and dynamic websites for Debian Pure Blends



More information about the Blends-commit mailing list