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

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Guillermo Gonzalez
Approved revision: 13
Merged at revision: 12
Proposed branch: lp:~verterok/unity-scope-askubuntu/askubuntu-logging
Merge into: lp:unity-scope-askubuntu
Diff against target: 89 lines (+15/-9)
2 files modified
src/unity_askubuntu_daemon.py (+13/-7)
tests/test_askubuntu.py (+2/-2)
To merge this branch: bzr merge lp:~verterok/unity-scope-askubuntu/askubuntu-logging
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
David Callé Approve
Review via email: mp+186876@code.launchpad.net

Commit message

Add basic logging

Description of the change

Add basic logging to help debugging in the server

To post a comment you must log in.
Revision history for this message
David Callé (davidc3) wrote :

+1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
13. By Guillermo Gonzalez

fix tests to work with latest libunity

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/unity_askubuntu_daemon.py'
2--- src/unity_askubuntu_daemon.py 2013-09-18 09:53:51 +0000
3+++ src/unity_askubuntu_daemon.py 2013-09-20 21:29:53 +0000
4@@ -14,7 +14,7 @@
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 GLib, Gio
9+from gi.repository import Gio
10 from gi.repository import Unity
11 import gettext
12 import urllib.request
13@@ -23,6 +23,7 @@
14 import json
15 import gzip
16 import io
17+import logging
18
19 APP_NAME = 'unity-scope-askubuntu'
20 LOCAL_PATH = '/usr/share/locale/'
21@@ -66,6 +67,7 @@
22 SE_API_KEY = "BmtlCGm1UU-Cmn8FAvfT4Q"
23 NUMS = '0123456789'
24
25+logger = logging.getLogger("unity.scope.askubuntu")
26
27 def search(search, filters):
28 '''
29@@ -75,13 +77,15 @@
30 if not search or len(search) < 3:
31 return results
32 query = urllib.parse.quote(search)
33+ logger.debug("Search: %s", query)
34 url = "%s/similar?title=%s&pagesize=30" % (QUESTIONS_SERVER, query)
35- print (url)
36 try:
37+ logger.debug("Requesting: %s", url)
38 response = urllib.request.urlopen(url, timeout=0.5).read()
39 response = response.decode('utf8')
40 result = json.loads(response)
41 except Exception:
42+ logger.exception("Error while fetching questions.")
43 result = "{}"
44 if 'questions' in result:
45 for question in result['questions']:
46@@ -111,14 +115,16 @@
47 'comment': text,
48 'tags': ', '.join(question['tags']),
49 'date': question['creation_date']})
50- for search in search.split():
51- if not all(i in NUMS for i in search):
52- url = '%stags?filter=%s&pagesize=3&key=%s' % (TAGS_SERVER, search, SE_API_KEY)
53- response = urllib.request.urlopen(url).read()
54- unzipped = gzip.GzipFile(fileobj=io.BytesIO(response))
55+ for search_term in search.split():
56+ if not all(i in NUMS for i in search_term):
57+ url = '%stags?filter=%s&pagesize=3&key=%s' % (TAGS_SERVER, search_term, SE_API_KEY)
58 try:
59+ logger.debug("Requesting tags similar to: %s", search_term)
60+ response = urllib.request.urlopen(url).read()
61+ unzipped = gzip.GzipFile(fileobj=io.BytesIO(response))
62 data = json.load(io.TextIOWrapper(unzipped, encoding='utf-8'))
63 except:
64+ logger.exception("Error while fetching tags (%s)", search_term)
65 data = "{}"
66 if "tags" in data:
67 for i in data['tags']:
68
69=== modified file 'tests/test_askubuntu.py'
70--- tests/test_askubuntu.py 2013-02-13 15:22:14 +0000
71+++ tests/test_askubuntu.py 2013-09-20 21:29:53 +0000
72@@ -29,7 +29,7 @@
73 def perform_query(self, query, filter_set = Unity.FilterSet.new()):
74 result_set = ResultSet()
75 ctx = Unity.SearchContext.create(query, 0, filter_set,
76- None, result_set, None)
77+ {}, result_set, None)
78 s = self.scope.create_search_for_query(ctx)
79 s.run()
80 return result_set
81@@ -47,7 +47,7 @@
82 self.scope_module.QUESTIONS_SERVER = 'file:tests/data/mock_askubuntu_questions_pass#'
83 self.scope_module.TAGS_SERVER = 'file:tests/data/mock_askubuntu_tags_pass.gz#'
84 expected_results = ["",
85- "Gtalk and empathy",
86+ "Gtalk and empathy",
87 "How to install Empathy 3.x in ubuntu 11.04",
88 "http://www.askubuntu.com/questions/40459"]
89 results = []

Subscribers

People subscribed via source and target branches