Merge lp:~stefan-schwarzburg/qreator/qreator_vendor_plugins into lp:qreator

Proposed by Schwarzburg
Status: Merged
Merged at revision: 170
Proposed branch: lp:~stefan-schwarzburg/qreator/qreator_vendor_plugins
Merge into: lp:qreator
Diff against target: 91 lines (+30/-4)
4 files modified
qreator/__init__.py (+11/-3)
qreator/qrcodes/QRCodeSoftwareCenterApp.py (+8/-0)
qreator_lib/__init__.py (+1/-1)
qreator_lib/helpers.py (+10/-0)
To merge this branch: bzr merge lp:~stefan-schwarzburg/qreator/qreator_vendor_plugins
Reviewer Review Type Date Requested Status
David Planella Approve
Schwarzburg Needs Information
Review via email: mp+164632@code.launchpad.net

Description of the change

The implementation is a simplified version of my comment on https://trello.com/card/add-vendor-infrastructure/4fc6a3556634e8557016945d/27 :

Each plugin is responsible for checking for vendor compatibility (since we have only one at the moment, this seemed the simplest way and is also in line with the plugin idea). If the vendor compatibilty is not met, the plugin raises an VendorError, which is caught by the importer infrastrucuter.

This has at the moment nothing to do with the colors of the icons.

Also: I was not able to test this on non-ubuntu distros, but they should normally not be named "Ubuntu", and therefore the test wether this is "Ubuntu" should fail...

To post a comment you must log in.
Revision history for this message
David Planella (dpm) wrote :

Nice work as usual, I like the approach.

Comments inline, just minor things:

21 + print "%s disabled due to missing vendor infrastructure." % (name,)

I wonder if we might want to use the logging system and just flag this as a warning message.

43 +

Additional whitespace here, just a nitpick, but it might be worth not introducing it.

67 + pass

Rather than passing here, do we want to perhaps print the warning in the exception as a central place, and let the plugins override the message?

review: Needs Information
170. By Schwarzburg

added the VendorError body which can now hold an error-value; replaced a print statement by a proper logging call.

Revision history for this message
Schwarzburg (stefan-schwarzburg) wrote :

I think changes should adress your comments.

- The logging is implemented this way because the order of plugin-imports and logging setup matters
- The ValueError now has a body with a message. The printing of that message is still left to the structure that catches the error. I think this is more the way it is supposed in python.
- I have removed the whitespace, but added three other :-)
  38: There was one blank line to separate code, so I have added another one at the end of the added lines.
  52-53: After an import line, there should be two blank lines...

review: Needs Resubmitting
Revision history for this message
Schwarzburg (stefan-schwarzburg) :
review: Needs Information
Revision history for this message
David Planella (dpm) wrote :

Merged, thanks!

I made a few small changes before the merge: namely, protecting the USC database module import with a try/exception block and raising a VendorError, as otherwise, the import was executed and it would have raised an ImportError exception if not available in a given platform other than Ubuntu.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qreator/__init__.py'
2--- qreator/__init__.py 2012-11-22 12:37:55 +0000
3+++ qreator/__init__.py 2013-05-20 06:15:31 +0000
4@@ -19,8 +19,9 @@
5 from qreator_lib.i18n import _
6 from gi.repository import Gtk, Gdk, GLib, GObject # pylint: disable=E0611
7 from qreator import QreatorWindow
8-from qreator_lib import set_up_logging, get_version
9+from qreator_lib import set_up_logging, get_version, VendorError
10 from qreator.qrcodes.QRCodeType import QRCodeType
11+import logging
12
13 # use dynamic importing to get all qrcode dataformats without
14 # knowing their names.
15@@ -29,10 +30,13 @@
16 import pkgutil
17 import qreator.qrcodes
18
19+warnings = []
20 for qr in list(pkgutil.iter_modules(qreator.qrcodes.__path__)):
21 name = "qreator.qrcodes." + qr[1]
22- __import__(name, fromlist=[])
23-
24+ try:
25+ __import__(name, fromlist=[])
26+ except VendorError as e:
27+ warnings.append("%s: %s." % (name, e))
28
29 def UTF8_(message):
30 return _(message).decode('UTF-8')
31@@ -65,6 +69,10 @@
32 qr_types = [d(window.update_qr_code) for d in QRCodeType.dataformats]
33 options = parse_options(qr_types)
34
35+ logger = logging.getLogger('qreator')
36+ for warning_message in warnings:
37+ logger.warn(warning_message)
38+
39 window.qr_types = qr_types
40 window.show()
41 if getattr(options, 'view', None) is not None:
42
43=== modified file 'qreator/qrcodes/QRCodeSoftwareCenterApp.py'
44--- qreator/qrcodes/QRCodeSoftwareCenterApp.py 2012-11-23 08:34:02 +0000
45+++ qreator/qrcodes/QRCodeSoftwareCenterApp.py 2013-05-20 06:15:31 +0000
46@@ -14,6 +14,14 @@
47 # with this program. If not, see <http://www.gnu.org/licenses/>.
48 ### END LICENSE
49
50+from qreator_lib import VendorError
51+import platform
52+
53+
54+# this is a vendor specific plugin
55+if not platform.linux_distribution()[0] == "Ubuntu":
56+ raise VendorError
57+
58 from qreator_lib.i18n import _
59 from QRCodeType import QRCodeType
60 from QRCodeSoftwareCenterAppGtk import QRCodeSoftwareCenterAppGtk
61
62=== modified file 'qreator_lib/__init__.py'
63--- qreator_lib/__init__.py 2012-11-22 08:43:25 +0000
64+++ qreator_lib/__init__.py 2013-05-20 06:15:31 +0000
65@@ -22,4 +22,4 @@
66 from . helpers import set_up_logging
67 from . Window import Window
68 from . qreatorconfig import get_version
69-
70+from . helpers import VendorError
71
72=== modified file 'qreator_lib/helpers.py'
73--- qreator_lib/helpers.py 2013-05-08 18:21:38 +0000
74+++ qreator_lib/helpers.py 2013-05-20 06:15:31 +0000
75@@ -26,6 +26,16 @@
76
77 from locale import gettext as _
78
79+class VendorError(Exception):
80+ """Raised by plugins if the required vendor infractucture is missing"""
81+ def __init__(self, value=None):
82+ if value is None:
83+ value = "Disabled due to missing vendor infrastructure."
84+ self.value = value
85+ def __str__(self):
86+ return repr(self.value)
87+
88+
89 def get_builder(builder_file_name):
90 """Return a fully-instantiated Gtk.Builder instance from specified ui
91 file

Subscribers

People subscribed via source and target branches

to all changes: