[elbe-devel] [PATCH] init: fix crash if --directory was not specified

Manuel Traut manut at linutronix.de
Mon Apr 29 14:47:57 CEST 2019


Hi Torben,

thanks for the review. I pushed the change into master.

  Manuel

On 12:28 Mon 29 Apr     , Torben Hohn wrote:
> On Fri, Apr 26, 2019 at 05:32:54PM +0200, Manuel Traut wrote:
> > this fixes #217
> 
> where opt.directory is accessed from elbepack/init/libvirt.xml.mako
> 
> also please add the complete backtrace, including the mako traceback...
> 
> 
> copied from https://github.com/Linutronix/elbe/issues/217
> ----------------------------------------------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/usr/lib/python2.7/dist-packages/elbepack/templates.py", line 28, in template
>     **d)
>   File "/usr/lib/python2.7/dist-packages/mako/template.py", line 462, in render
>     return runtime._render(self, self.callable_, args, data)
>   File "/usr/lib/python2.7/dist-packages/mako/runtime.py", line 838, in _render
>     **_kwargs_for_callable(callable_, data))
>   File "/usr/lib/python2.7/dist-packages/mako/runtime.py", line 873, in _render_context
>     _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
>   File "/usr/lib/python2.7/dist-packages/mako/runtime.py", line 899, in _exec_template
>     callable_(context, *args, **kwargs)
>   File "/usr/lib/python2.7/dist-packages/elbepack/init/libvirt.xml.mako", line 8, in render_body
>     <%
>   File "/usr/lib/python2.7/posixpath.py", line 70, in join
>     elif path == '' or path.endswith('/'):
> AttributeError: 'NoneType' object has no attribute 'endswith'
> 
> Traceback (most recent call last):
>   File "/usr/bin/elbe", line 55, in <module>
>     cmdmod.run_command(sys.argv[2:])
>   File "/usr/lib/python2.7/dist-packages/elbepack/commands/init.py", line 218, in run_command
>     init_template_dir, t), d, linebreak=True)
>   File "/usr/lib/python2.7/dist-packages/elbepack/templates.py", line 38, in write_template
>     outfile.write(template(fname, d, linebreak))
>   File "/usr/lib/python2.7/dist-packages/elbepack/templates.py", line 28, in template
>     **d)
>   File "/usr/lib/python2.7/dist-packages/mako/template.py", line 462, in render
>     return runtime._render(self, self.callable_, args, data)
>   File "/usr/lib/python2.7/dist-packages/mako/runtime.py", line 838, in _render
>     **_kwargs_for_callable(callable_, data))
>   File "/usr/lib/python2.7/dist-packages/mako/runtime.py", line 873, in _render_context
>     _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
>   File "/usr/lib/python2.7/dist-packages/mako/runtime.py", line 899, in _exec_template
>     callable_(context, *args, **kwargs)
>   File "_usr_lib_python2_7_dist_packages_elbepack_init_libvirt_xml_mako", line 46, in render_body
>   File "/usr/lib/python2.7/posixpath.py", line 70, in join
>     elif path == '' or path.endswith('/'):
> AttributeError: 'NoneType' object has no attribute 'endswith'
> ----------------------------------------------------------------------------------------------------------
> 
> > 
> > Traceback (most recent call last):
> >   File "/usr/bin/elbe", line 55, in <module>
> >     cmdmod.run_command(sys.argv[2:])
> >   File "/usr/lib/python2.7/dist-packages/elbepack/commands/init.py", line 218, in run_command
> >     init_template_dir, t), d, linebreak=True)
> >   File "/usr/lib/python2.7/dist-packages/elbepack/templates.py", line 38, in write_template
> >     outfile.write(template(fname, d, linebreak))
> >   File "/usr/lib/python2.7/dist-packages/elbepack/templates.py", line 28, in template
> >     **d)
> >   File "/usr/lib/python2.7/dist-packages/mako/template.py", line 462, in render
> >     return runtime._render(self, self.callable_, args, data)
> >   File "/usr/lib/python2.7/dist-packages/mako/runtime.py", line 838, in _render
> >     **_kwargs_for_callable(callable_, data))
> >   File "/usr/lib/python2.7/dist-packages/mako/runtime.py", line 873, in _render_context
> >     _exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
> >   File "/usr/lib/python2.7/dist-packages/mako/runtime.py", line 899, in _exec_template
> >     callable_(context, *args, **kwargs)
> >   File "_usr_lib_python2_7_dist_packages_elbepack_init_libvirt_xml_mako", line 46, in render_body
> >   File "/usr/lib/python2.7/posixpath.py", line 70, in join
> >     elif path == '' or path.endswith('/'):
> > AttributeError: 'NoneType' object has no attribute 'endswith'
> > 
> > Signed-off-by: Manuel Traut <manut at linutronix.de>
> 
> after that...
> 
> Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>
> 
> > ---
> >  elbepack/commands/init.py | 15 +++++----------
> >  1 file changed, 5 insertions(+), 10 deletions(-)
> > 
> > diff --git a/elbepack/commands/init.py b/elbepack/commands/init.py
> > index 8b5a6fee..08f77d1e 100644
> > --- a/elbepack/commands/init.py
> > +++ b/elbepack/commands/init.py
> > @@ -36,7 +36,7 @@ def run_command(argv):
> >                         dest="skip_validation", default=False,
> >                         help="Skip xml schema validation")
> >  
> > -    oparser.add_option("--directory", dest="directory",
> > +    oparser.add_option("--directory", dest="directory", default="./build",
> >                         help="Working directory (default is build)",
> >                         metavar="FILE")
> >  
> > @@ -142,11 +142,6 @@ def run_command(argv):
> >          cdrom = mirror.ensure_child("cdrom")
> >          cdrom.set_text(os.path.abspath(opt.cdrom))
> >  
> > -    if not opt.directory:
> > -        path = "./build"
> > -    else:
> > -        path = opt.directory
> > -
> >      # this is a workaround for
> >      # http://lists.linutronix.de/pipermail/elbe-devel/2017-July/000541.html
> >      _, virt = command_out('test -x /usr/bin/systemd-detect-virt && /usr/bin/systemd-detect-virt');
> > @@ -158,14 +153,14 @@ def run_command(argv):
> >          machine_type = 'pc'
> >  
> >      try:
> > -        os.makedirs(path)
> > +        os.makedirs(opt.directory)
> >      except OSError as e:
> >          print(
> >              "unable to create project directory: %s (%s)" %
> > -            (path, e.strerror))
> > +            (opt.directory, e.strerror))
> >          sys.exit(30)
> >  
> > -    out_path = os.path.join(path, ".elbe-in")
> > +    out_path = os.path.join(opt.directory, ".elbe-in")
> >      try:
> >          os.makedirs(out_path)
> >      except OSError as e:
> > @@ -214,7 +209,7 @@ def run_command(argv):
> >          if t == "Makefile.mako" or t == "libvirt.xml.mako":
> >              write_template(
> >                  os.path.join(
> > -                    path, o), os.path.join(
> > +                    opt.directory, o), os.path.join(
> >                      init_template_dir, t), d, linebreak=True)
> >          else:
> >              write_template(
> > -- 
> > 2.20.1
> > 
> > 
> > _______________________________________________
> > elbe-devel mailing list
> > elbe-devel at linutronix.de
> > https://lists.linutronix.de/mailman/listinfo/elbe-devel
> 
> -- 
> Torben Hohn
> Linutronix GmbH | Bahnhofstrasse 3 | D-88690 Uhldingen-Mühlhofen
> Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99
> 
> Hinweise zum Datenschutz finden Sie hier (Informations on data privacy 
> can be found here): https://linutronix.de/kontakt/Datenschutz.php
> 
> Linutronix GmbH | Firmensitz (Registered Office): Uhldingen-Mühlhofen | 
> Registergericht (Registration Court): Amtsgericht Freiburg i.Br., HRB700 
> 806 | Geschäftsführer (Managing Directors): Heinz Egger, Thomas Gleixner





More information about the elbe-devel mailing list