[Piglit] [PATCH 9/9] summary.py: Use with open(...) as syntax

Dylan Baker baker.dylan.c at gmail.com
Thu Oct 17 14:18:11 CEST 2013


On Thursday, October 17, 2013 04:58:34 PM Chris Forbes wrote:
> Much better :)
> 
> Reviewed-by: Chris Forbes <chrisf at ijw.co.nz>
> 
> On Tue, Oct 15, 2013 at 11:13 PM, Dylan Baker <baker.dylan.c at gmail.com> 
wrote:
> > This is the commonly excepted "right way" in python.
> > 
> > Signed-off-by: Dylan Baker <baker.dylan.c at gmail.com>
> > ---
> > 
> >  framework/summary.py | 77
> >  ++++++++++++++++++++++++---------------------------- 1 file changed, 36
> >  insertions(+), 41 deletions(-)
> > 
> > diff --git a/framework/summary.py b/framework/summary.py
> > index 3ab71f3..359d078 100644
> > --- a/framework/summary.py
> > +++ b/framework/summary.py
> > 
> > @@ -428,13 +428,12 @@ class Summary:
> >          for each in self.results:
> >              os.mkdir(path.join(destination, each.name))
> > 
> > -            file = open(path.join(destination, each.name, "index.html"),
> > 'w') -            file.write(testindex.render(name=each.name,
> > -                                        time=each.time_elapsed,
> > -                                        options=each.options,
> > -                                        glxinfo=each.glxinfo,
> > -                                        lspci=each.lspci))
> > -            file.close()
> > +            with open(path.join(destination, each.name, "index.html"),
> > 'w') as out: +                out.write(testindex.render(name=each.name,
> > +                                           time=each.time_elapsed,
> > +                                           options=each.options,
> > +                                           glxinfo=each.glxinfo,
> > +                                           lspci=each.lspci))
> > 
> >              # Then build the individual test results
> > 
> >              for key, value in each.tests.iteritems():
> > @@ -447,21 +446,19 @@ class Summary:
> >                      if not path.exists(temp_path):
> >                          os.makedirs(temp_path)
> > 
> > -                    file = open(path.join(destination,
> > -                                          each.name,
> > -                                          key + ".html"), 'w')
> > -                    file.write(testfile.render(
> > -                        testname=key,
> > -                        status=value.get('result', 'None'),
> > -                        returncode=value.get('returncode', 'None'),
> > -                        time=value.get('time', 'None'),
> > -                        info=value.get('info', 'None'),
> > -                        traceback=value.get('traceback', 'None'),
> > -                        command=value.get('command', 'None'),
> > -                        dmesg=value.get('dmesg', 'None'),
> > -                        css=path.relpath(result_css, temp_path),
> > -                        index=path.relpath(index, temp_path)))
> > -                    file.close()
> > +                    with open(path.join(destination, each.name, key +
> > ".html"), +                              'w') as out:
> > +                        out.write(testfile.render(
> > +                            testname=key,
> > +                            status=value.get('result', 'None'),
> > +                            returncode=value.get('returncode', 'None'),
> > +                            time=value.get('time', 'None'),
> > +                            info=value.get('info', 'None'),
> > +                            traceback=value.get('traceback', 'None'),
> > +                            command=value.get('command', 'None'),
> > +                            dmesg=value.get('dmesg', 'None'),
> > +                            css=path.relpath(result_css, temp_path),
> > +                            index=path.relpath(index, temp_path)))
> > 
> >          # Finally build the root html files: index, regressions, etc
> >          index = Template(filename="templates/index.mako",
> > 
> > @@ -477,30 +474,28 @@ class Summary:
> >          # Index.html is a bit of a special case since there is index,
> >          all, and
> >          # alltests, where the other pages all use the same name. ie,
> >          # changes.html, self.changes, and page=changes.
> > 
> > -        file = open(path.join(destination, "index.html"), 'w')
> > -        file.write(index.render(results=HTMLIndex(self,
> > self.tests['all']), -                                page='all',
> > -                                pages=pages,
> > -                                colnum=len(self.results),
> > -                                exclude=exclude))
> > -        file.close()
> > +        with open(path.join(destination, "index.html"), 'w') as out:
> > +            out.write(index.render(results=HTMLIndex(self,
> > self.tests['all']), +                                   page='all',
> > +                                   pages=pages,
> > +                                   colnum=len(self.results),
> > +                                   exclude=exclude))
> > 
> >          # Generate the rest of the pages
> > 
> >          for page in pages:
> > -            file = open(path.join(destination, page + '.html'), 'w')
> > 
> > +            with open(path.join(destination, page + '.html'), 'w') as 
out:
> >              # If there is information to display display it
> > 
> > -            if self.tests[page]:
> > -                file.write(index.render(results=HTMLIndex(self,
> > -                                                         
> > self.tests[page]), -                                        pages=pages,
> > -                                        page=page,
> > -                                        colnum=len(self.results),
> > -                                        exclude=exclude))
> > -            # otherwise provide an empty page
> > -            else:
> > -                file.write(empty_status.render(page=page, pages=pages))
> > +                if self.tests[page]:
> > +                    out.write(index.render(results=HTMLIndex(self,
> > +                                                            
> > self.tests[page]), +                                          
> > pages=pages,
> > +                                           page=page,
> > +                                           colnum=len(self.results),
> > +                                           exclude=exclude))
> > +                # otherwise provide an empty page
> > +                else:
> > +                    out.write(empty_status.render(page=page,
> > pages=pages))
> > 
> > -            file.close()
> > 
> >      def generate_text(self, diff, summary):
> >          """ Write summary information to the console """
> > 
> > --
> > 1.8.1.5
> > 
> > _______________________________________________
> > Piglit mailing list
> > Piglit at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/piglit

Was that Reviewed-by for all of the patches, or just patch 9?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20131017/65172dad/attachment.pgp>


More information about the Piglit mailing list