Merge lp:~verterok/unity-scope-reddit/reddit-logging into lp:unity-scope-reddit

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: David Callé
Approved revision: 5
Merged at revision: 4
Proposed branch: lp:~verterok/unity-scope-reddit/reddit-logging
Merge into: lp:unity-scope-reddit
Diff against target: 103 lines (+22/-18)
2 files modified
src/unity_reddit_daemon.py (+21/-17)
tests/test_reddit.py (+1/-1)
To merge this branch: bzr merge lp:~verterok/unity-scope-reddit/reddit-logging
Reviewer Review Type Date Requested Status
David Callé Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+187385@code.launchpad.net

Commit message

Add basic logging (replace print with logging)

Description of the change

Add basic logging (replace print with logging)

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
5. By Guillermo Gonzalez

fix test

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
David Callé (davidc3) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity_reddit_daemon.py'
2--- src/unity_reddit_daemon.py 2013-08-14 14:52:46 +0000
3+++ src/unity_reddit_daemon.py 2013-09-25 03:02:00 +0000
4@@ -2,24 +2,25 @@
5 # -*- coding: utf-8 -*-
6
7 # Copyright (C) 2013 David Callé <davidc@framli.eu>
8-# This program is free software: you can redistribute it and/or modify it
9-# under the terms of the GNU General Public License version 3, as published
10+# This program is free software: you can redistribute it and/or modify it
11+# under the terms of the GNU General Public License version 3, as published
12 # by the Free Software Foundation.
13-#
14-# This program is distributed in the hope that it will be useful, but
15-# WITHOUT ANY WARRANTY; without even the implied warranties of
16-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
17+#
18+# This program is distributed in the hope that it will be useful, but
19+# WITHOUT ANY WARRANTY; without even the implied warranties of
20+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
21 # PURPOSE. See the GNU General Public License for more details.
22-#
23-# You should have received a copy of the GNU General Public License along
24+#
25+# You should have received a copy of the GNU General Public License along
26 # with this program. If not, see <http://www.gnu.org/licenses/>.
27
28-from gi.repository import Unity, UnityExtras
29-from gi.repository import Gio, GLib
30+from gi.repository import Unity
31+from gi.repository import Gio
32 import urllib.parse
33 import urllib.request
34 import json
35 import gettext
36+import logging
37
38 APP_NAME = 'unity-scope-reddit'
39 LOCAL_PATH = '/usr/share/locale/'
40@@ -65,6 +66,8 @@
41 'field':Unity.SchemaFieldType.OPTIONAL}
42 EXTRA_METADATA = [m1, m2, m3, m4, m5]
43
44+logger = logging.getLogger("unity.scope.reddit")
45+
46 def search(search, filters):
47 '''
48 Any search method returning results as a list of tuples.
49@@ -88,16 +91,16 @@
50 else:
51 search_cleaned = urllib.parse.quote(search.split('#')[0])
52 uri = '%sr/%s/hot.json?limit=25' % (SEARCH_URI, search_cleaned)
53- print(uri)
54 data = None
55 try:
56+ logger.debug("Request: %s", uri)
57 hdr = { 'User-Agent' : 'unity-scope-reddit' }
58- req = urllib.request.Request(url=uri,
59+ req = urllib.request.Request(url=uri,
60 headers=hdr)
61 response = urllib.request.urlopen(req).read()
62 data = json.loads(response.decode('utf-8'))
63- except Exception as error:
64- print(error)
65+ except Exception:
66+ logger.exception("Error while fetching: %r", uri)
67 return results
68 if not data or not 'data' in data:
69 return results
70@@ -160,8 +163,9 @@
71 if not 'dnd_uri' in i or not i['dnd_uri'] or i['dnd_uri'] == '':
72 i['dnd_uri'] = i['uri']
73 result_set.add_result(**i)
74- except Exception as error:
75- print (error)
76+ except Exception:
77+ logger.exception("Error while building result set.")
78+
79
80 class Preview (Unity.ResultPreviewer):
81
82@@ -225,7 +229,7 @@
83 '''
84 fs = Unity.FilterSet.new ()
85 # if FILTERS:
86-#
87+#
88 return fs
89
90 def do_get_group_name (self):
91
92=== modified file 'tests/test_reddit.py'
93--- tests/test_reddit.py 2013-08-13 16:30:30 +0000
94+++ tests/test_reddit.py 2013-09-25 03:02:00 +0000
95@@ -24,7 +24,7 @@
96 def perform_query(self, query, filter_set = Unity.FilterSet.new()):
97 result_set = ResultSet()
98 ctx = Unity.SearchContext.create(query, 0, filter_set,
99- None, result_set, None)
100+ {}, result_set, None)
101 s = self.scope.create_search_for_query(ctx)
102 s.run()
103 return result_set

Subscribers

People subscribed via source and target branches