Merge lp:~jml/pkgme/debug-logging into lp:pkgme

Proposed by Jonathan Lange
Status: Merged
Approved by: James Westby
Approved revision: 83
Merged at revision: 71
Proposed branch: lp:~jml/pkgme/debug-logging
Merge into: lp:pkgme
Diff against target: 256 lines (+79/-9)
8 files modified
.testr.conf (+1/-1)
pkgme/backend.py (+7/-0)
pkgme/bin/main.py (+9/-1)
pkgme/project_info.py (+10/-3)
pkgme/run_script.py (+4/-1)
pkgme/tests/test_trace.py (+26/-0)
pkgme/trace.py (+11/-2)
pkgme/write.py (+11/-1)
To merge this branch: bzr merge lp:~jml/pkgme/debug-logging
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+69812@code.launchpad.net

Description of the change

This branch adds a debug flag and quite a few more debug logging statements.

Partly addresses bug 809440 and 809431.

Fixes a bug in the logging where it would truncate the log on each run.

There's no way to turn debugging off, but there's no use case for that yet.

To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :
Download full text (4.3 KiB)

Example log output::

2011-07-29 15:54:51,607 - DEBUG - Building packaging for /home/jml/src/pkgme/examples/brukkon-2.1.5.9.orig
2011-07-29 15:54:51,736 - DEBUG - Loading backends from: /home/jml/src/pkgme/debug-logging/pkgme/backends
2011-07-29 15:54:51,736 - DEBUG - Found backend python
2011-07-29 15:54:51,736 - DEBUG - Found backend binary
2011-07-29 15:54:51,736 - DEBUG - Found backend vala
2011-07-29 15:54:51,736 - DEBUG - Found backend cmake
2011-07-29 15:54:51,736 - DEBUG - Loading backends from: /usr/share/pkgme/backends
2011-07-29 15:54:51,736 - DEBUG - Finding backend for /home/jml/src/pkgme/examples/brukkon-2.1.5.9.orig
2011-07-29 15:54:51,736 - DEBUG - Running script /home/jml/src/pkgme/debug-logging/pkgme/backends/python/want...
2011-07-29 15:54:51,761 - DEBUG - python scored 0
2011-07-29 15:54:51,762 - DEBUG - Running script /home/jml/src/pkgme/debug-logging/pkgme/backends/binary/want...
2011-07-29 15:54:51,999 - DEBUG - binary scored 10
2011-07-29 15:54:51,999 - DEBUG - Running script /home/jml/src/pkgme/debug-logging/pkgme/backends/vala/want...
2011-07-29 15:54:52,003 - DEBUG - vala scored 0
2011-07-29 15:54:52,004 - DEBUG - Running script /home/jml/src/pkgme/debug-logging/pkgme/backends/cmake/want...
2011-07-29 15:54:52,030 - DEBUG - cmake scored 0
2011-07-29 15:54:52,030 - DEBUG - Running script /home/jml/src/pkgme/debug-logging/pkgme/backends/binary/extra_files...
2011-07-29 15:54:52,274 - DEBUG - extra_files returned '{"debian/brukkon.desktop": "[Desktop Entry]\\nType=Application\\nVersion=1.0\\nExec=/opt/brukkon/src/Brukkon\\nCategories=\\nName=Brukkon\\nComment=\\n", "debian/install": "argparse opt/brukkon\\nos opt/brukkon\\nsrc opt/brukkon\\nsys opt/brukkon\\ndebian/brukkon.desktop usr/share/application\\n"}'
2011-07-29 15:54:52,275 - DEBUG - Running script /home/jml/src/pkgme/debug-logging/pkgme/backends/binary/depends...
2011-07-29 15:54:52,510 - DEBUG - depends returned '${shlibs:Depends}, ${misc:Depends}'
2011-07-29 15:54:52,510 - DEBUG - Running script /home/jml/src/pkgme/debug-logging/pkgme/backends/binary/architecture...
2011-07-29 15:54:52,514 - DEBUG - architecture returned None
2011-07-29 15:54:52,515 - DEBUG - Running script /home/jml/src/pkgme/debug-logging/pkgme/backends/binary/debhelper_addons...
2011-07-29 15:54:52,522 - DEBUG - debhelper_addons returned None
2011-07-29 15:54:52,523 - DEBUG - Running script /home/jml/src/pkgme/debug-logging/pkgme/backends/binary/description...
2011-07-29 15:54:52,528 - DEBUG - description returned None
2011-07-29 15:54:52,528 - DEBUG - Running script /home/jml/src/pkgme/debug-logging/pkgme/backends/binary/build_depends...
2011-07-29 15:55:29,113 - DEBUG - build_depends returned 'ia32-libs, lib32stdc++6, lib32gcc1, lib32asound2, libc6-i386'
2011-07-29 15:55:29,114 - DEBUG - Running script /home/jml/src/pkgme/debug-logging/pkgme/backends/binary/homepage...
2011-07-29 15:55:29,118 - DEBUG - homepage returned None
2011-07-29 15:55:29,119 - DEBUG - Running script /home/jml/src/pkgme/debug-logging/pkgme/backends/binary/version...
2011-07-29 15:55:29,122 - DEBUG - version returned None
2011-07-29 15:55:29,123 - DEBUG - Running script /home/jml/src/pkgme/debug-lo...

Read more...

Revision history for this message
James Westby (james-w) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.testr.conf'
2--- .testr.conf 2010-11-03 00:32:55 +0000
3+++ .testr.conf 2011-07-29 14:58:42 +0000
4@@ -1,3 +1,3 @@
5 [DEFAULT]
6-test_command=python -m subunit.run $IDLIST
7+test_command=PYTHONPATH=`pwd` python -m subunit.run $IDLIST
8 test_id_list_default=pkgme.tests.test_suite
9
10=== modified file 'pkgme/backend.py'
11--- pkgme/backend.py 2011-07-12 16:34:59 +0000
12+++ pkgme/backend.py 2011-07-29 14:58:42 +0000
13@@ -11,6 +11,7 @@
14 SingleExternalHelperInfo,
15 )
16 from pkgme.run_script import run_script, ScriptMissing
17+from pkgme import trace
18
19
20 def get_backend_dir(underunder_file, backend):
21@@ -173,8 +174,10 @@
22 def get_info(self, path):
23 high_score = 0
24 eligble = []
25+ trace.debug('Finding backend for %s' % (path,))
26 for backend in self.backends:
27 score = backend.want(path)
28+ trace.debug(' %s scored %s' % (backend.name, score))
29 if score > high_score:
30 eligble = [backend]
31 high_score = score
32@@ -187,6 +190,8 @@
33 if len(eligble) > 1:
34 eligble.sort(key=attrgetter('name'))
35 backend = eligble[0]
36+ trace.debug(
37+ '%s eligble backends. Picked %s' % (len(eligble), backend.name))
38 return backend.get_info(path)
39
40
41@@ -205,6 +210,7 @@
42 backends = []
43 names = set()
44 for path in self.paths:
45+ trace.debug("Loading backends from: %s" % (path,))
46 path = os.path.abspath(path)
47 if not os.path.isdir(path):
48 continue
49@@ -217,6 +223,7 @@
50 backend_path = os.path.join(path, fname)
51 if not os.path.isdir(backend_path):
52 continue
53+ trace.debug(" Found backend %s" % (fname,))
54 backends.append(
55 ExternalHelpersBackend(fname, backend_path))
56 names.add(fname)
57
58=== modified file 'pkgme/bin/main.py'
59--- pkgme/bin/main.py 2011-07-15 16:04:28 +0000
60+++ pkgme/bin/main.py 2011-07-29 14:58:42 +0000
61@@ -1,8 +1,11 @@
62+#!/usr/bin/python
63+
64 import argparse
65 import os
66 import sys
67
68 from pkgme import __version__, write_packaging
69+from pkgme import trace
70
71
72 def main(argv=None, target_dir=None):
73@@ -14,10 +17,15 @@
74 '-v', '--version',
75 action='version', version='pkgme {0}'.format(__version__),
76 help='Print this version string and exit')
77- parser.parse_args(args=argv)
78+ parser.add_argument('-D', '--debug', action='store_true')
79+ options = parser.parse_args(args=argv)
80+ if options.debug:
81+ trace.set_debug()
82 if target_dir is None:
83 target_dir = os.getcwd()
84+ trace.debug("Building packaging for %s" % (target_dir,))
85 write_packaging(target_dir)
86+ trace.debug("Built packaging for %s" % (target_dir,))
87
88
89 if __name__ == '__main__':
90
91=== modified file 'pkgme/project_info.py'
92--- pkgme/project_info.py 2011-03-04 22:06:58 +0000
93+++ pkgme/project_info.py 2011-07-29 14:58:42 +0000
94@@ -1,6 +1,8 @@
95 import json
96+from pprint import pformat
97
98 from pkgme.run_script import run_script, ScriptMissing
99+from pkgme import trace
100
101
102 class ProjectInfo(object):
103@@ -37,7 +39,9 @@
104 out = run_script(
105 self.basepath, self.INFO_SCRIPT_NAME, self.cwd,
106 to_write=json.dumps(keys))
107- return json.loads(out)
108+ ret = json.loads(out)
109+ trace.debug('%s returned %s' % (self.INFO_SCRIPT_NAME, pformat(ret)))
110+ return ret
111
112
113 class MultipleExternalHelpersInfo(_ExternalHelpersInfo):
114@@ -46,8 +50,11 @@
115 try:
116 out = run_script(self.basepath, key, self.cwd)
117 except ScriptMissing:
118- return None
119- return out.rstrip("\n")
120+ ret = None
121+ else:
122+ ret = out.rstrip("\n")
123+ trace.debug('%s returned %s' % (key, pformat(ret)))
124+ return ret
125
126 def get_all(self, keys):
127 values = {}
128
129=== modified file 'pkgme/run_script.py'
130--- pkgme/run_script.py 2011-04-15 19:18:29 +0000
131+++ pkgme/run_script.py 2011-07-29 14:58:42 +0000
132@@ -2,6 +2,8 @@
133 import os
134 import subprocess
135
136+from pkgme import trace
137+
138
139 class ScriptProblem(Exception):
140
141@@ -38,10 +40,11 @@
142 env = os.environ.copy()
143 if os.path.isdir(helperpath):
144 if 'PATH' in env:
145- env['PATH'] = env['PATH'] + ':' + helperpath
146+ env['PATH'] = os.pathsep.join([env['PATH'], helperpath])
147 else:
148 env['PATH'] = helperpath
149 try:
150+ trace.debug("Running script %s..." % (script_path,))
151 proc = subprocess.Popen(
152 [script_path], stdout=subprocess.PIPE,
153 stderr=subprocess.STDOUT, stdin=subprocess.PIPE,
154
155=== modified file 'pkgme/tests/test_trace.py'
156--- pkgme/tests/test_trace.py 2011-07-19 14:47:30 +0000
157+++ pkgme/tests/test_trace.py 2011-07-29 14:58:42 +0000
158@@ -18,6 +18,7 @@
159 return temp_dir
160
161 def with_temp_log(self):
162+ self.with_temp_home()
163 self.useFixture(trace.LoggingFixture.get_default())
164
165 def test_log_location(self):
166@@ -50,3 +51,28 @@
167 MatchesRegex(
168 r'%s - INFO - first\n%s - INFO - second\n' % (
169 _date_time_re, _date_time_re)))
170+
171+ def test_log_appends(self):
172+ self.with_temp_log()
173+ trace.log("first")
174+ trace.LoggingFixture.get_default()
175+ trace.log("second")
176+ log_location = trace.get_log_location()
177+ with open(log_location) as f:
178+ log_contents = f.read()
179+ self.assertThat(
180+ log_contents,
181+ MatchesRegex(
182+ r'%s - INFO - first\n%s - INFO - second\n' % (
183+ _date_time_re, _date_time_re)))
184+
185+ def test_set_debug(self):
186+ self.with_temp_log()
187+ trace.set_debug()
188+ trace.debug("Hello")
189+ with open(trace.get_log_location()) as f:
190+ log_contents = f.read()
191+ self.assertThat(
192+ log_contents,
193+ MatchesRegex(
194+ r'%s - DEBUG - Hello\n' % (_date_time_re,)))
195
196=== modified file 'pkgme/trace.py'
197--- pkgme/trace.py 2011-07-19 14:53:32 +0000
198+++ pkgme/trace.py 2011-07-29 14:58:42 +0000
199@@ -3,7 +3,7 @@
200
201 from fixtures import Fixture
202
203-from pkgme.write import write_file
204+from pkgme.write import touch
205
206
207 def get_log_location():
208@@ -23,7 +23,7 @@
209
210 def _make_handler(self):
211 # Make sure that the log file exists.
212- write_file(self._filename, '')
213+ touch(self._filename)
214 handler = logging.FileHandler(self._filename)
215 handler.setLevel(self._level)
216 formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
217@@ -54,5 +54,14 @@
218 _logging_fixture.setUp()
219
220
221+def debug(message):
222+ _logger.debug(message)
223+
224 def log(message):
225 _logger.info(message)
226+
227+
228+def set_debug():
229+ _logger.setLevel(logging.DEBUG)
230+ for handler in _logger.handlers:
231+ handler.setLevel(logging.DEBUG)
232
233=== modified file 'pkgme/write.py'
234--- pkgme/write.py 2010-11-05 20:29:46 +0000
235+++ pkgme/write.py 2011-07-29 14:58:42 +0000
236@@ -1,10 +1,20 @@
237 import os
238
239
240-def write_file(path, content):
241+def ensure_containing_directory_exists(path):
242 dirname, basename = os.path.split(path)
243 if dirname != '' and not os.path.exists(dirname):
244 os.makedirs(dirname)
245+
246+
247+def touch(path):
248+ ensure_containing_directory_exists(path)
249+ with open(path, 'a'):
250+ pass
251+
252+
253+def write_file(path, content):
254+ ensure_containing_directory_exists(path)
255 with open(path, "w") as f:
256 f.write(content)
257

Subscribers

People subscribed via source and target branches