Merge lp:~facundo/unity-scope-openclipart/add-logging into lp:unity-scope-openclipart

Proposed by Facundo Batista
Status: Merged
Approved by: Facundo Batista
Approved revision: 31
Merged at revision: 31
Proposed branch: lp:~facundo/unity-scope-openclipart/add-logging
Merge into: lp:unity-scope-openclipart
Diff against target: 78 lines (+14/-22)
1 file modified
src/unity_openclipart_daemon.py (+14/-22)
To merge this branch: bzr merge lp:~facundo/unity-scope-openclipart/add-logging
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Guillermo Gonzalez Approve
Review via email: mp+192933@code.launchpad.net

Commit message

Add logging.

Description of the change

Add logging.

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity_openclipart_daemon.py'
2--- src/unity_openclipart_daemon.py 2013-05-22 20:45:58 +0000
3+++ src/unity_openclipart_daemon.py 2013-10-28 19:10:21 +0000
4@@ -14,12 +14,14 @@
5 # You should have received a copy of the GNU General Public License along
6 # with this program. If not, see <http://www.gnu.org/licenses/>.
7
8-from gi.repository import Unity, UnityExtras
9+from gi.repository import Unity
10 from gi.repository import Gio, GLib
11-import urllib
12+
13 import feedparser
14 import gettext
15+import logging
16 import shutil
17+import urllib
18
19 APP_NAME = 'unity-scope-openclipart'
20 LOCAL_PATH = '/usr/share/locale/'
21@@ -58,30 +60,20 @@
22 'field':Unity.SchemaFieldType.OPTIONAL}
23 EXTRA_METADATA = [m1, m2, m3]
24
25+logger = logging.getLogger("unity.scope.openclipart")
26+
27 def search(search, filters):
28- '''
29- Any search method returning results as a list of tuples.
30- Available tuple fields:
31- uri (string)
32- icon (string)
33- title (string)
34- comment (string)
35- dnd_uri (string)
36- mimetype (string)
37- category (int)
38- result_type (Unity ResultType)
39- extras metadata fields (variant)
40- '''
41+ """Do the search in OpenClipArt."""
42 results = []
43 if not search:
44 return results
45 search = urllib.parse.quote(search)
46 uri = "%sapi/search/?query=%s" % (SEARCH_URI, search)
47- print(uri)
48+ logger.debug("Request: %s", uri)
49 try:
50 feed = feedparser.parse(uri)
51- except Exception as error:
52- print(error)
53+ except Exception:
54+ logger.exception("Error while fetching data.")
55 feed = None
56 if not feed or not 'entries' in feed:
57 return results
58@@ -105,8 +97,8 @@
59 'published':published,
60 'author':f['author'],
61 'resource':resource})
62- except Exception as error:
63- print(error)
64+ except Exception:
65+ logger.exception("Error while building search response.")
66 return results
67
68
69@@ -145,8 +137,8 @@
70 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
71 i['dnd_uri'] = i['uri']
72 result_set.add_result(**i)
73- except Exception as error:
74- print (error)
75+ except Exception:
76+ logger.exception("Error while running search.")
77
78 class Preview (Unity.ResultPreviewer):
79

Subscribers

People subscribed via source and target branches