[Blends-commit] [SCM] website branch, master, updated. 918f4b94a80e13239881ab52bd2c762fa116388c
Ole Streicher
olebole at debian.org
Sun Mar 6 08:46:50 UTC 2016
The following commit has been merged in the master branch:
commit 918f4b94a80e13239881ab52bd2c762fa116388c
Author: Ole Streicher <olebole at debian.org>
Date: Sun Mar 6 09:46:41 2016 +0100
remove unneeded os.unlink(); use with codecs.open() instead of open/close
diff --git a/webtools/bugs.py b/webtools/bugs.py
index 66afc67..53e4290 100755
--- a/webtools/bugs.py
+++ b/webtools/bugs.py
@@ -456,28 +456,14 @@ the right shows the tasks of %s.""" ) \
#data['severitystat'] = severitystat[task]
template = loader.load('bugs.xhtml')
- f = codecs.open(outputdir + '/' + task + '.html', 'w', 'utf-8')
- try:
- print >> f, template.generate(**data).render('xhtml')
- except UnicodeDecodeError, err:
- fd = codecs.open('debug_'+blendname+'_bugs.json', 'w', 'utf-8')
- print >>fd, json.dumps(bugs_data[task])
- fd.close()
- SetFilePermissions(outputdir + '/' + task + '.html')
- print err
-
- f.close()
+ with codecs.open(outputdir + '/' + task + '.html', 'w', 'utf-8') as f:
+ f.write(template.generate(**data).render('xhtml'))
SetFilePermissions(outputdir + '/' + task + '.html')
template = loader.load('bugs_idx.xhtml')
outputfile = outputdir + '/index.html'
- try:
- os.unlink(outputfile)
- except: # simply continue if file does not exist
- pass
- f = codecs.open(outputfile, 'w', 'utf-8')
- print >> f, template.generate(**data).render('xhtml')
- f.close()
+ with codecs.open(outputfile, 'w', 'utf-8') as f:
+ f.write(template.generate(**data).render('xhtml'))
SetFilePermissions(outputfile)
if __name__ == '__main__':
diff --git a/webtools/tasks.py b/webtools/tasks.py
index f75cdb3..c9c5569 100755
--- a/webtools/tasks.py
+++ b/webtools/tasks.py
@@ -82,10 +82,6 @@ with open(os.path.join(outputdir, 'tasks.json'), 'w') as fp:
t = datetime.now()
htaccess = outputdir + '/.htaccess'
-try:
- os.unlink(htaccess)
-except: # simply continue if file does not exist
- pass
htafp = open(htaccess, 'w')
print >> htafp, "DirectoryIndex index index.html\nOptions +MultiViews"
@@ -187,19 +183,8 @@ for lang in languages:
outputfile = outputdir + '/index'
if lang != 'xyz': # let 'en' be a language as any other and add suffix to file name
outputfile += '.' + language_dict[lang]['short'] + '.html'
- try:
- os.unlink(outputfile)
- except: # simply continue if file does not exist
- pass
- f = codecs.open(outputfile, 'w', 'utf-8')
- try:
- print >> f, template.generate(**data).render('xhtml')
- except UnicodeDecodeError, errtxt:
- print >> stderr, \
- "Some critical encoding problem occured when trying to render index for lang %s.\n%s" \
- % (lang, errtxt)
-
- f.close()
+ with codecs.open(outputfile, 'w', 'utf-8') as f:
+ f.write(template.generate(**data).render('xhtml'))
SetFilePermissions(outputfile)
try:
@@ -207,19 +192,8 @@ for lang in languages:
outputfile = tasks.data['outputdir'] + '/index'
if lang != 'xyz': # let 'en' be a language as any other and add suffix to file name
outputfile += '.' + language_dict[lang]['short'] + '.html'
- try:
- os.unlink(outputfile)
- except: # simply continue if file does not exist
- pass
- f = codecs.open(outputfile, "w", "utf-8")
- try:
- print >> f, template.generate(**data).render('xhtml')
- except UnicodeDecodeError, errtxt:
- print >> stderr, \
- "Some critical encoding problem occured when trying to render index for lang %s.\n%s" \
- % (lang, errtxt)
-
- f.close()
+ with codecs.open(outputfile, "w", "utf-8") as f:
+ f.write(template.generate(**data).render('xhtml'))
SetFilePermissions(outputfile)
except:
pass
@@ -266,74 +240,37 @@ for lang in languages:
outputfile = outputdir + '/' + task
if lang != 'xyz': # let 'en' be a language as any other and add suffix to file name
outputfile += '.' + language_dict[lang]['short'] + '.html'
- try:
- os.unlink(outputfile)
- except: # simply continue if file does not exist
- pass
if data['projectname'] in ('Debian Astro', 'Debian Hamradio'):
template = loader.load('packages.xhtml')
else:
template = loader.load('tasks.xhtml')
- f = codecs.open(outputfile+'_tmp', "w", "utf-8")
- try:
- print >> f, template.generate(**data).render('xhtml')
- except UnicodeEncodeError, errtxt:
- print "Some critical encoding problem occured when trying to render task %s for lang %s.\n%s" \
- % (task, lang, errtxt)
- except UnicodeDecodeError, errtxt:
- print >> stderr, \
- "Some critical encoding problem occured when trying to render task %s for lang %s.\n%s" \
- % (task, lang, errtxt)
- except UndefinedError, errtxt:
- print >> stderr, \
- "UndefinedError while rendering task %s for lang %s.\n%s" \
- % (task, lang, errtxt)
- f.close()
- SetFilePermissions(outputfile+'_tmp')
- # Really rude hack to get back '<' / '>' signs which actually shoul be
- # in the output
- tmp = codecs.open(outputfile+'_tmp', "r", 'utf-8')
- f = codecs.open(outputfile, "w", 'utf-8')
- 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
+ lines = template.generate(**data).render('xhtml').split('\n')
+ for line in lines:
+ # 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):
+ if '%26' in line:
+ print line
line = re.sub('%26', '&', line)
- print >>f, line,
- f.close()
- tmp.close()
- os.unlink(outputfile+'_tmp')
- SetFilePermissions(outputfile)
+ with codecs.open(outputfile, "w", "utf-8") as f:
+ f.write('\n'.join(lines))
+ SetFilePermissions(outputfile)
template = loader.load('packagelist.xhtml')
outputfile = outputdir + '/packagelist'
if lang != 'xyz': # let 'en' be a language as any other and add suffix to file name
outputfile += '.' + lang + '.html'
- try:
- os.unlink(outputfile)
- except: # simply continue if file does not exist
- pass
- f = codecs.open(outputfile, 'w', 'utf-8')
data['projectsintasks'] = []
for task in data['taskskeys']:
data['projectsintasks'] = tasks.tasks[task].dependencies
- try:
- print >> f, template.generate(**data).render('xhtml')
- except UnicodeDecodeError, errtxt:
- print >> stderr, \
- "Some critical encoding problem occured when trying to render long package list for lang %s.\n%s" \
- % (lang, errtxt)
- except UndefinedError, errtxt:
- print >> stderr, \
- "UndefinedError while trying to render long package list for lang %s.\n%s" \
- % (lang, errtxt)
-
- f.close()
+ with codecs.open(outputfile, 'w', 'utf-8') as f:
+ f.write(template.generate(**data).render('xhtml'))
SetFilePermissions(outputfile)
diff --git a/webtools/thermometer.py b/webtools/thermometer.py
index 6897ec1..99e78ed 100755
--- a/webtools/thermometer.py
+++ b/webtools/thermometer.py
@@ -400,34 +400,27 @@ the right shows the tasks of %s.""" ) \
for key in ('homepage', 'projecturl', 'projectname', 'logourl', 'ubuntuhome', 'projectubuntu'):
data[key] = config[key]
- data['updatetimestamp'] = _('Last update:')) + ' ' + formatdate(time.mktime(t.timetuple())
-
+ data['updatetimestamp'] = _('Last update:') + ' ' + formatdate(time.mktime(t.timetuple()))
+
data['thermometer'] = blendname + '_thermometer.html'
os.system("ln -sf %s %s/index.html" % (data['thermometer'], outputdir))
data['uthermometer'] = 'ubuntu_' + blendname + '_thermometer.html'
outputfile = outputdir + '/' + data['thermometer']
uoutputfile = outputdir + '/' + data['uthermometer']
- try:
- os.unlink(outputfile)
- os.unlink(uoutputfile)
- except: # simply continue if file does not exist
- pass
- f = codecs.open(outputfile, 'w', 'utf-8')
template = loader.load('thermometer.xhtml')
- try:
- print >> f, template.generate(**data).render('xhtml')
- except TypeError, err:
- print >>stderr, "Problem creating thermometer.html.\tMessage: %s" % (str(err))
- f.close()
+ with codecs.open(outputfile, 'w', 'utf-8') as f:
+ try:
+ print >> f, template.generate(**data).render('xhtml')
+ except TypeError, err:
+ print >>stderr, "Problem creating thermometer.html.\tMessage: %s" % (str(err))
SetFilePermissions(outputfile)
- f = codecs.open(uoutputfile, 'w', 'utf-8')
utemplate = loader.load('uthermometer.xhtml')
- try:
+ with codecs.open(uoutputfile, 'w', 'utf-8') as f:
+ try:
print >> f, utemplate.generate(**data).render('xhtml')
- except TypeError, err:
- print >>stderr, "Problem creating uthermometer.html.\tMessage: %s" % (str(err))
- f.close()
+ except TypeError, err:
+ print >>stderr, "Problem creating uthermometer.html.\tMessage: %s" % (str(err))
SetFilePermissions(uoutputfile)
if __name__ == '__main__':
--
Static and dynamic websites for Debian Pure Blends
More information about the Blends-commit
mailing list