Examples can't be loaded, glade files are gzipped

Bug #40177 reported by Sidnei da Silva
8
Affects Status Importance Assigned to Milestone
Kiwi
Fix Released
Wishlist
kiwi (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

There were a couple issues with the kiwi-examples package as installed on dapper.

1. Some of the .glade files were gzipped as .glade.gz
2. Kiwi had a bug that it wouldn't load the .glade file if you ran the script from a different directory (reported as
https://bit.ly/2BtN52W

Example:
"""
python /usr/share/doc/kiwi-examples/examples/framework/news/news4.py
"""

A fix has been checked in to kiwi to fix #2 and accept .glade.bz2 .glade.gz files as alternative to .glade.

A fix has been checked in to gazpacho to allow loading of .glade.bz2 and .glade.gz in addition to .glade files.

https://bit.ly/2BtN52W

Please update the packages to the to-be-released versions of those upstream products to fix the issue.

Revision history for this message
In , Patrick K. O'Brien (pobrien) wrote :

C:\Code\Kiwi-svn\trunk\examples\framework\hey>python heyglade.py

C:\Code\Kiwi-svn\trunk\examples\framework\hey>cd ..

C:\Code\Kiwi-svn\trunk\examples\framework>python hey\heyglade.py
Traceback (most recent call last):
  File "hey\heyglade.py", line 7, in ?
    app = BaseView(gladefile="hey", delete_handler=quit_if_last)
  File "C:\Code\Kiwi-svn\trunk\tests\..\kiwi\ui\views.py", line 805, in __init__
    toplevel_name, domain)
  File "C:\Code\Kiwi-svn\trunk\tests\..\kiwi\ui\views.py", line 261, in __init__
    self._glade_adaptor = self.get_glade_adaptor()
  File "C:\Code\Kiwi-svn\trunk\tests\..\kiwi\ui\views.py", line 824, in get_glade_adaptor
    self.gladename)
  File "C:\Code\Kiwi-svn\trunk\kiwi\ui\gazpacholoader.py", line 71, in __init__
    self._gladefile = environ.find_resource("glade", filename + ".glade")
  File "C:\Code\Kiwi-svn\trunk\kiwi\environ.py", line 103, in find_resource
    raise EnvironmentError("Could not find %s resource: %s" % (
EnvironmentError: Could not find glade resource: hey.glade

Revision history for this message
In , Sidnei da Silva (sidnei) wrote :

And while you are there, would be nice to be able to load a glade file from a .gz or .bz2.

In fact, the lookup order should be 1) .glade.bz2, 2) .glade.gz, 3) .glade.

I just installed 'kiwi-examples' in Dapper and it does install *some* (but not all!) the .glade files as .glade.gz, which makes the examples non-working OOTB.

Anyway, just a nice to have feature, if you forget that the file shouldn't have been gzipped in Dapper in the first place *wink*.

Revision history for this message
In , Sidnei da Silva (sidnei) wrote :

Created an attachment (id=3114)
Patch to gazpacho.loader.loader to allow opening .gz and .bz2

Since I've opened my big mouth, here comes the first patch.

Revision history for this message
In , Johan Dahlin (jdahlin-deactivatedaccount) wrote :

(In reply to comment #2)
> Created an attachment (id=3114) [edit]
> Patch to gazpacho.loader.loader to allow opening .gz and .bz2
>
> Since I've opened my big mouth, here comes the first patch.

Thanks, applied to svn of gazpacho. I modified it to not change ImportError into ParseError, it can be handled later if there is an issue for somebody.

Revision history for this message
In , Sidnei da Silva (sidnei) wrote :

Created an attachment (id=3115)
Patch to kiwi.environ, to add 'alternative extensions' to a given resource type

And now the kiwi counterpart. Look for .bz2, .gz and finally the original filename when looking for .glade files (untested)

Revision history for this message
In , Sidnei da Silva (sidnei) wrote :

Created an attachment (id=3116)
Updated patch to add script's parent directory to resource path for "glade" resources, in addition to adding "alternative extensions"

Here's the updated patch which includes the actual fix for this bug in addition to the previous patch for loading alternate extensions.

Revision history for this message
In , Johan Dahlin (jdahlin-deactivatedaccount) wrote :

(From update of attachment 3116)
Looks good, some nitpicks.

>Index: kiwi/environ.py

> import locale
> import os
> import sys
>+from os.path import dirname, abspath

This is not allowed, just use the name directly, since they're
no need to explicitly importing os.path.

>+ # Add "current" (as in the directory of the main script being
>+ # run) to resource paths to look at when searching for "glade"
>+ # resources (see http://bugzilla.async.com.br/show_bug.cgi?id=2409)
>+ #
>+ # Note this path is absolute, while in general we deal with
>+ # relative paths here. However the join() function is smart
>+ # enough to ignore the prefix if it see's an absolute path as
>+ # the second argument.
>+ self.add_resource("glade", dirname(abspath(sys.argv[0])))
>+
>+ # Add some compressed formats as alternative extensions to
>+ # "glade" resources. A patch has been added to gazpacho trunk
>+ # (rev. 2251) to support loading those compressed formats.
>+ self.add_alternative_extensions("glade", ".bz2", ".gz")

Can this be determined in runtime somehow?
So the extensions are only added if gazpacho actually supports them.

Revision history for this message
In , Sidnei da Silva (sidnei) wrote :

(In reply to comment #6)
> >+from os.path import dirname, abspath
>
> This is not allowed, just use the name directly, since they're
> no need to explicitly importing os.path.

Fair enough. Just that the line would be longer than 80 columns, but I can wrap that.

Do you want me to submit a new patch?

> >+ # Add some compressed formats as alternative extensions to
> >+ # "glade" resources. A patch has been added to gazpacho trunk
> >+ # (rev. 2251) to support loading those compressed formats.
> >+ self.add_alternative_extensions("glade", ".bz2", ".gz")
>
> Can this be determined in runtime somehow?
> So the extensions are only added if gazpacho actually supports them.

Given that we added a module-level function 'open_file' to gazpacho, you could check for that. Or you could check for the version. Does gazpacho have a function to return it's version?

Revision history for this message
Sidnei da Silva (sidnei) wrote :

There were a couple issues with the kiwi-examples package as installed on dapper.

1. Some of the .glade files were gzipped as .glade.gz
2. Kiwi had a bug that it wouldn't load the .glade file if you ran the script from a different directory (reported as http://bugzilla.async.com.br/show_bug.cgi?id=2409).

Example:
"""
python /usr/share/doc/kiwi-examples/examples/framework/news/news4.py
"""

A fix has been checked in to kiwi to fix #2 and accept .glade.bz2 .glade.gz files as alternative to .glade.

A fix has been checked in to gazpacho to allow loading of .glade.bz2 and .glade.gz in addition to .glade files.

Please update the packages to the to-be-released versions of those upstream products to fix the issue.

Revision history for this message
In , Johan Dahlin (jdahlin-deactivatedaccount) wrote :

I checked in a patch based on yours:

Sending ChangeLog
Sending kiwi/environ.py
Transmitting file data ..
Committed revision 3318.

I simplified it a bit and made sure to test the script directory and current directory after all others. I also changed it to try to load the uncompressed resource before the compressed onces.

Revision history for this message
Daniel Holbach (dholbach) wrote :

Fixed in Dapper's kiwi 1.9.8

Changed in kiwi:
status: Unconfirmed → Fix Released
Revision history for this message
In , Christian Reis (kiko) wrote :

Wow, just noticed that these comments are now synced across to the Launchpad tracker for Ubuntu kiwi.

Revision history for this message
In , Christian Reis (kiko) wrote :

I wonder if this goes upstream to https://bugs.edge.launchpad.net/ubuntu/+source/kiwi/+bug/40177 since they are monitoring this site's plugins.

Changed in kiwi:
importance: Unknown → Wishlist
tranadols (tramadols)
description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.