2007-03-26 14:58:33 +02:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
|
|
|
import xml.dom.minidom
|
|
|
|
import os
|
|
|
|
import stat
|
|
|
|
import re
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
from six import StringIO
|
2007-03-26 14:58:33 +02:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import ezt
|
|
|
|
|
|
|
|
base_template = ezt.Template()
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open('templates/base.ezt') as f:
|
|
|
|
base_template.parse(f.read())
|
2007-03-26 14:58:33 +02:00
|
|
|
buildlog_template = ezt.Template()
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open('templates/buildlog.ezt') as f:
|
|
|
|
buildlog_template.parse(f.read())
|
2007-03-26 14:58:33 +02:00
|
|
|
changelog_template = ezt.Template()
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open('templates/changelog.ezt') as f:
|
|
|
|
changelog_template.parse(f.read())
|
2007-03-26 14:58:33 +02:00
|
|
|
tests_template = ezt.Template()
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open('templates/tests.ezt') as f:
|
|
|
|
tests_template.parse(f.read())
|
2007-03-26 14:58:33 +02:00
|
|
|
|
2008-09-12 17:06:58 +02:00
|
|
|
def getText(nodelist):
|
2007-03-26 14:58:33 +02:00
|
|
|
if not nodelist:
|
|
|
|
return None
|
|
|
|
rc = ''
|
|
|
|
for node in nodelist:
|
|
|
|
if node.nodeType == node.TEXT_NODE:
|
|
|
|
rc = rc + node.data
|
|
|
|
return rc.encode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
class ChangelogFile:
|
|
|
|
def __init__(self, node):
|
|
|
|
for attr in ('name', 'revision'):
|
|
|
|
try:
|
|
|
|
setattr(self, attr, getText(node.getElementsByTagName(attr)[0].childNodes))
|
|
|
|
except IndexError:
|
|
|
|
setattr(self, attr, None)
|
|
|
|
|
|
|
|
|
|
|
|
class ChangelogEntry:
|
|
|
|
def __init__(self, node):
|
2007-03-29 10:50:54 +02:00
|
|
|
for attr in ('date', 'weekday', 'time', 'isoDate', 'msg', 'author', 'revision'):
|
2007-03-26 14:58:33 +02:00
|
|
|
try:
|
|
|
|
setattr(self, attr, getText(node.getElementsByTagName(attr)[0].childNodes))
|
|
|
|
except IndexError:
|
|
|
|
setattr(self, attr, None)
|
|
|
|
self.file = [ChangelogFile(x) for x in node.getElementsByTagName('file')]
|
|
|
|
|
2007-03-29 10:50:54 +02:00
|
|
|
class ChangelogSvnEntry:
|
|
|
|
def __init__(self, node):
|
|
|
|
for attr in ('date', 'msg', 'author', 'file'):
|
|
|
|
try:
|
|
|
|
setattr(self, attr, getText(node.getElementsByTagName(attr)[0].childNodes))
|
|
|
|
except IndexError:
|
|
|
|
setattr(self, attr, None)
|
|
|
|
self.revision = node.attributes['revision'].value
|
|
|
|
if self.date:
|
|
|
|
self.time = self.date[11:16]
|
|
|
|
|
2007-03-26 14:58:33 +02:00
|
|
|
|
|
|
|
class TestTest:
|
|
|
|
def __init__(self, node):
|
|
|
|
for attr in ('id', 'description'):
|
|
|
|
try:
|
|
|
|
setattr(self, attr, getText(node.getElementsByTagName(attr)[0].childNodes))
|
|
|
|
except IndexError:
|
|
|
|
setattr(self, attr, None)
|
|
|
|
self.result = node.attributes['result'].value
|
|
|
|
|
|
|
|
class TestSuite:
|
|
|
|
def __init__(self, node):
|
|
|
|
for attr in ('title', 'duration'):
|
|
|
|
try:
|
|
|
|
setattr(self, attr, getText(node.getElementsByTagName(attr)[0].childNodes))
|
|
|
|
except IndexError:
|
|
|
|
setattr(self, attr, None)
|
|
|
|
if self.duration:
|
|
|
|
self.duration = '%.4f' % float(self.duration)
|
|
|
|
self.test = [TestTest(x) for x in node.getElementsByTagName('test')]
|
|
|
|
self.len_tests = len(self.test)
|
|
|
|
|
|
|
|
|
|
|
|
class Build:
|
|
|
|
def __init__(self, node):
|
|
|
|
for attr in ('date', 'hostname', 'duration', 'buildlog', 'buildlog295', 'changelog'):
|
|
|
|
try:
|
|
|
|
setattr(self, attr, getText(node.getElementsByTagName(attr)[0].childNodes))
|
|
|
|
except IndexError:
|
|
|
|
setattr(self, attr, None)
|
|
|
|
|
|
|
|
self.display_date = '%s-%s-%s' % (self.date[:4], self.date[4:6], self.date[6:8])
|
|
|
|
self.display_hour = '%s:%s' % (self.date[9:11], self.date[11:13])
|
|
|
|
|
|
|
|
for component in ('liblasso', 'java', 'python', 'php', 'perl', 'csharp', 'liblasso295'):
|
|
|
|
try:
|
|
|
|
cnode = [x for x in node.getElementsByTagName(component) if \
|
|
|
|
x.attributes.has_key('buildlog')][0]
|
|
|
|
except IndexError:
|
|
|
|
setattr(self, component + '_status', None)
|
|
|
|
continue
|
|
|
|
setattr(self, component + '_status', getText(cnode.childNodes))
|
|
|
|
setattr(self, component + '_href', cnode.attributes['buildlog'].value.replace('.xml',''))
|
|
|
|
|
|
|
|
for test in ('c', 'python', 'souk'):
|
|
|
|
try:
|
|
|
|
cnode = [x for x in node.getElementsByTagName(test) if \
|
|
|
|
x.attributes.has_key('href')][0]
|
|
|
|
except IndexError:
|
|
|
|
setattr(self, 'tests_' + test + '_status', None)
|
|
|
|
continue
|
|
|
|
setattr(self, 'tests_' + test + '_status', getText(cnode.childNodes))
|
|
|
|
setattr(self, 'tests_' + test + '_href', cnode.attributes['href'].value.replace('.xml', ''))
|
|
|
|
|
|
|
|
if self.changelog:
|
|
|
|
self.changelog = self.changelog.replace('.xml', '')
|
2010-07-27 15:06:06 +02:00
|
|
|
try:
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open('web' + self.changelog + '.xml') as f:
|
|
|
|
dom_cl = xml.dom.minidom.parse(f)
|
2010-07-27 15:06:06 +02:00
|
|
|
except:
|
|
|
|
self.nb_commits = '?'
|
|
|
|
self.last_commit_author = '?'
|
|
|
|
else:
|
|
|
|
self.last_commit_author = getText(dom_cl.getElementsByTagName('author')[-1].childNodes)
|
|
|
|
self.nb_commits = len(dom_cl.getElementsByTagName('entry'))
|
|
|
|
if not self.nb_commits:
|
|
|
|
self.nb_commits = len(dom_cl.getElementsByTagName('logentry'))
|
2007-03-26 14:58:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
re_body = re.compile('<body(.*?)>(.*)</body>', re.DOTALL)
|
|
|
|
re_div = re.compile('<div(.*?)>(.*)</div>', re.DOTALL)
|
|
|
|
re_title = re.compile('<title>(.*)</title>', re.DOTALL)
|
|
|
|
re_summary = re.compile('[a-z]+\.[0-9]{4}.xml')
|
|
|
|
|
|
|
|
if not os.path.exists('web-static'):
|
|
|
|
os.mkdir('web-static')
|
|
|
|
|
2021-09-04 00:02:14 +02:00
|
|
|
for BUILDLOGS_DIR in ('build-logs'):
|
2007-03-26 14:58:33 +02:00
|
|
|
if not os.path.exists('web/%s' % BUILDLOGS_DIR):
|
|
|
|
continue
|
|
|
|
if not os.path.exists('web-static/%s' % BUILDLOGS_DIR):
|
|
|
|
os.mkdir('web-static/%s' % BUILDLOGS_DIR)
|
|
|
|
|
|
|
|
for base, dirs, files in os.walk('web/%s' % BUILDLOGS_DIR):
|
2010-07-27 16:13:07 +02:00
|
|
|
if base.endswith('/CVS') or base.endswith('/.svn') or base.endswith('/.git'):
|
2007-03-26 14:58:33 +02:00
|
|
|
continue
|
|
|
|
for dirname in dirs:
|
|
|
|
src_file = os.path.join(base, dirname)
|
|
|
|
dst_file = 'web-static/' + src_file[4:]
|
|
|
|
if not os.path.exists(dst_file):
|
|
|
|
os.mkdir(dst_file)
|
|
|
|
for filename in files:
|
|
|
|
if filename[0] == '.':
|
|
|
|
continue
|
|
|
|
src_file = os.path.join(base, filename)
|
|
|
|
dst_file = 'web-static/' + src_file[4:].replace('.xml', '.html')
|
|
|
|
if os.path.exists(dst_file) and \
|
|
|
|
os.stat(dst_file)[stat.ST_MTIME] >= os.stat(src_file)[stat.ST_MTIME]:
|
|
|
|
continue
|
|
|
|
if src_file.endswith('.log'):
|
|
|
|
os.link(src_file, dst_file)
|
|
|
|
continue
|
|
|
|
if src_file.endswith('.html'):
|
|
|
|
try:
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open(src_file) as f:
|
|
|
|
body = re_body.findall(f.read())[0][1].strip()
|
2008-09-12 17:06:58 +02:00
|
|
|
except IndexError:
|
2007-03-26 14:58:33 +02:00
|
|
|
raise "no body found"
|
|
|
|
fd = StringIO()
|
|
|
|
base_template.generate(fd, {'body': body, 'title': 'Build Log', 'section': 'buildbox'})
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open(dst_file, 'w') as f:
|
|
|
|
f.write(fd.getvalue())
|
2007-03-26 14:58:33 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open(src_file) as f:
|
|
|
|
dom = xml.dom.minidom.parse(f)
|
2007-03-26 14:58:33 +02:00
|
|
|
except:
|
|
|
|
continue
|
|
|
|
type = dom.childNodes[0].nodeName
|
|
|
|
if type == 'changelog':
|
|
|
|
entries = [ChangelogEntry(x) for x in dom.getElementsByTagName('entry')]
|
|
|
|
fd = StringIO()
|
|
|
|
changelog_template.generate(fd, {'entry': entries})
|
|
|
|
body = fd.getvalue()
|
|
|
|
fd = StringIO()
|
|
|
|
base_template.generate(fd, {'body': body, 'title': 'ChangeLog', 'section': 'buildbox'})
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open(dst_file, 'w') as f:
|
|
|
|
f.write(fd.getvalue())
|
2007-03-26 14:58:33 +02:00
|
|
|
|
2007-03-29 10:50:54 +02:00
|
|
|
if type == 'log':
|
|
|
|
entries = [ChangelogSvnEntry(x) for x in dom.getElementsByTagName('logentry')]
|
|
|
|
fd = StringIO()
|
|
|
|
changelog_template.generate(fd, {'entry': entries})
|
|
|
|
body = fd.getvalue()
|
|
|
|
fd = StringIO()
|
|
|
|
base_template.generate(fd, {'body': body, 'title': 'ChangeLog', 'section': 'buildbox'})
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open(dst_file, 'w') as f:
|
|
|
|
f.write(fd.getvalue())
|
2007-03-29 10:50:54 +02:00
|
|
|
|
2007-03-26 14:58:33 +02:00
|
|
|
if type == 'testsuites':
|
|
|
|
datetime = getText(dom.getElementsByTagName('datetime')[0].childNodes)
|
|
|
|
title = getText(dom.getElementsByTagName('title')[0].childNodes)
|
|
|
|
suites = [TestSuite(x) for x in dom.getElementsByTagName('suite')]
|
|
|
|
fd = StringIO()
|
|
|
|
tests_template.generate(fd, {'datetime': datetime, 'title': title,
|
|
|
|
'suite': suites})
|
|
|
|
body = fd.getvalue()
|
|
|
|
fd = StringIO()
|
|
|
|
base_template.generate(fd, {'body': body,
|
|
|
|
'title': 'Test Suite - %s' % title, 'section': 'buildbox'})
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open(dst_file, 'w') as f:
|
|
|
|
f.write(fd.getvalue())
|
2007-03-26 14:58:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
day_dirs = os.listdir('web/%s/' % BUILDLOGS_DIR)
|
|
|
|
day_dirs.sort()
|
|
|
|
day_dirs.reverse()
|
2010-07-27 15:06:06 +02:00
|
|
|
day_dirs = day_dirs[:60]
|
2007-03-26 14:58:33 +02:00
|
|
|
|
|
|
|
main_page = []
|
|
|
|
|
|
|
|
for base, dirs, files in os.walk('web/%s' % BUILDLOGS_DIR):
|
|
|
|
for dirname in dirs:
|
|
|
|
if dirname in day_dirs:
|
|
|
|
for t in [x for x in os.listdir(os.path.join(base, dirname)) if re_summary.match(x)]:
|
|
|
|
main_page.append(os.path.join(base, dirname, t))
|
|
|
|
|
|
|
|
main_page.sort()
|
|
|
|
main_page.reverse()
|
2010-07-27 15:06:06 +02:00
|
|
|
main_page = main_page[:50]
|
2007-03-26 14:58:33 +02:00
|
|
|
builds = []
|
|
|
|
for filename in main_page:
|
2010-07-27 16:13:07 +02:00
|
|
|
try:
|
|
|
|
builds.append( Build(xml.dom.minidom.parse(filename)) )
|
|
|
|
if len(builds) > 1 and builds[-2].date[:8] == builds[-1].date[:8]:
|
|
|
|
builds[-1].display_date = ''
|
|
|
|
except:
|
|
|
|
pass
|
2007-03-26 14:58:33 +02:00
|
|
|
|
|
|
|
fd = StringIO()
|
|
|
|
buildlog_template.generate(fd, {'build': builds})
|
|
|
|
body = fd.getvalue()
|
|
|
|
fd = StringIO()
|
|
|
|
base_template.generate(fd, {'body': body, 'title': 'Build Box', 'section': 'buildbox'})
|
|
|
|
if BUILDLOGS_DIR == 'build-logs':
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open('web-static/buildbox.html', 'w') as f:
|
|
|
|
f.write(fd.getvalue())
|
2007-03-26 14:58:33 +02:00
|
|
|
|
|
|
|
for base, dirs, files in os.walk('web'):
|
|
|
|
if '/build-logs' in base or '/news/' in base:
|
|
|
|
continue
|
2007-03-29 10:50:54 +02:00
|
|
|
if base.endswith('CVS') or base.endswith('.svn'):
|
2007-03-26 14:58:33 +02:00
|
|
|
continue
|
|
|
|
for dirname in dirs:
|
2007-03-29 10:50:54 +02:00
|
|
|
if dirname in ('CVS', 'news', '.svn'):
|
2007-03-26 14:58:33 +02:00
|
|
|
continue
|
|
|
|
src_file = os.path.join(base, dirname)
|
|
|
|
dst_file = 'web-static/' + src_file[4:]
|
|
|
|
if not os.path.exists(dst_file):
|
|
|
|
os.mkdir(dst_file)
|
|
|
|
for filename in files:
|
|
|
|
if filename in ('.cvsignore', 'buildbox.xml'):
|
|
|
|
continue
|
|
|
|
if filename[0] == '.':
|
|
|
|
continue
|
|
|
|
basename, ext = os.path.splitext(filename)
|
|
|
|
src_file = os.path.join(base, filename)
|
|
|
|
dst_file = 'web-static/' + src_file[4:]
|
|
|
|
|
2010-07-27 16:13:07 +02:00
|
|
|
if os.path.isdir(src_file): continue
|
2010-07-27 15:06:06 +02:00
|
|
|
|
2007-03-26 14:58:33 +02:00
|
|
|
if os.path.exists(dst_file) and \
|
|
|
|
os.stat(dst_file)[stat.ST_MTIME] >= os.stat(src_file)[stat.ST_MTIME]:
|
|
|
|
continue
|
|
|
|
|
2007-03-29 10:50:54 +02:00
|
|
|
if ext not in ('.html', '.xml') or filename.startswith('doap.') or 'api-reference' in src_file:
|
2008-08-05 16:53:29 +02:00
|
|
|
if os.path.exists(dst_file):
|
|
|
|
os.unlink(dst_file)
|
2007-03-26 14:58:33 +02:00
|
|
|
os.link(src_file, dst_file)
|
|
|
|
continue
|
|
|
|
|
|
|
|
type = None
|
|
|
|
if ext == '.xml':
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open(src_file) as f:
|
|
|
|
dom = xml.dom.minidom.parse(f)
|
2007-03-26 14:58:33 +02:00
|
|
|
type = dom.childNodes[0].nodeName
|
|
|
|
dst_file = dst_file.replace('.xml', '.html')
|
|
|
|
|
|
|
|
news = None
|
|
|
|
if dst_file == 'web-static/index.html':
|
|
|
|
news_files = [x for x in os.listdir('web/news/') if x.endswith('.xml') and x[2] == '-']
|
|
|
|
news_files.sort()
|
|
|
|
news_files.reverse()
|
2010-10-05 08:30:02 +02:00
|
|
|
news_files = news_files[:2]
|
2007-03-26 14:58:33 +02:00
|
|
|
news = []
|
|
|
|
for f in news_files:
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open(os.path.join('web/news/', f)) as f:
|
|
|
|
news.append('<div>%s</div>' % re_div.findall(f.read())[0][1].strip())
|
2007-03-26 14:58:33 +02:00
|
|
|
news = '\n'.join(news)
|
|
|
|
|
|
|
|
section = src_file.split('/')[1].replace('.xml', '')
|
|
|
|
if ext == '.html' or type == 'html':
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open(src_file) as f:
|
|
|
|
content = f.read()
|
2007-03-26 14:58:33 +02:00
|
|
|
try:
|
|
|
|
body = re_body.findall(content)[0][1].strip()
|
2008-09-12 17:06:58 +02:00
|
|
|
except IndexError:
|
2007-03-26 14:58:33 +02:00
|
|
|
raise "no body found"
|
|
|
|
title = re_title.findall(content)[0]
|
|
|
|
fd = StringIO()
|
|
|
|
base_template.generate(fd, {'body': body, 'title': title, 'section': section,
|
|
|
|
'news': news})
|
Make more Python scripts compatible with both Py2 and Py3
While porting other Python code in the repo to run under Py3 (as well
as Py2) it was discovered there were a number of other Python scripts
which also needed porting. However these scripts are never invoked
during a build so there was no easy way to test the porting work. I
assume these scripts are for developers only and/or are
historical. Because there was no way for me to test the porting
changes on these scripts I did not want to include the changes in the
patch for the Py3 porting which fixed scripts that are invoked during
the build (the former patch is mandatory, this patch is optional at
the moment). I did verify the scripts compile cleanly under both Py2
and Py3, however it's possible I missed porting something or the error
does not show up until run-time.
Examples of the required changes are:
* Replace use of the built-in function file() with open(). file()
does not exist in Py3, open works in both Py2 and Py3. The code was
also modified to use a file context manager (e.g. with open(xxx) as
f:). This assures open files are properly closed when the code block
using the file goes out of scope. This is a standard modern Python
idiom.
* Replace all use of the print keyword with the six.print_()
function, which itself is an emulation of Py3's print function. Py3
no longer has a print keyword, only a print() function.
* The dict methods .keys(), .values(), .items() no longer return a
list in Py3, instead they return a "view" object which is an
iterator whose result is an unordered set. The most notable
consequence is you cannot index the result of these functions like
your could in Py2 (e.g. dict.keys()[0] will raise a run time
exception).
* Replace use of StringIO.StringIO and cStringIO with
six.StringIO. Py3 no longer has cStringIO and the six variant
handles the correct import.
* Py3 no longer allows the "except xxx, variable" syntax, where
variable appering after the comma is assigned the exception object,
you must use the "as" keyword to perform the variable assignment
(e.g. execpt xxx as variable)
* Python PEP 3113 removed tuple parameter unpacking. Therefore you can
no longer define a formal parameter list that contains tuple
notation representing a single parameter that is unpacked into
multiple arguments.
License: MIT
Signed-off-by: John Dennis <jdennis@redhat.com>
2018-06-26 00:52:16 +02:00
|
|
|
with open(dst_file, 'w')as f:
|
|
|
|
f.write(fd.getvalue())
|
2007-03-26 14:58:33 +02:00
|
|
|
continue
|
|
|
|
|