Merge lp:~davidpbritton/lp2kanban/use-logging into lp:lp2kanban

Proposed by David Britton on 2016-08-29
Status: Merged
Approved by: David Britton on 2016-09-01
Approved revision: 165
Merged at revision: 143
Proposed branch: lp:~davidpbritton/lp2kanban/use-logging
Merge into: lp:lp2kanban
Prerequisite: lp:~davidpbritton/lp2kanban/filter-bugs-correct-movement
Diff against target: 432 lines (+81/-81)
2 files modified
src/lp2kanban/bugs2cards.py (+74/-73)
src/lp2kanban/tests/test_bugs2cards.py (+7/-8)
To merge this branch: bzr merge lp:~davidpbritton/lp2kanban/use-logging
Reviewer Review Type Date Requested Status
Landscape Builder test results Approve on 2016-09-02
Alberto Donato 2016-08-29 Approve on 2016-08-30
Review via email: mp+304293@code.launchpad.net

Commit message

bugs2cards.py: Convert prints to logs

Description of the change

Convert prints to logs

To post a comment you must log in.
review: Abstain (executing tests)

Command: make check
Result: Fail
Revno: 163
Branch: lp:~davidpbritton/lp2kanban/use-logging
Jenkins: https://ci.lscape.net/job/latch-test/9628/

review: Needs Fixing (test results)
164. By David Britton on 2016-08-29

Merge up along filter branch

review: Abstain (executing tests)

Command: http_proxy=$ci_proxy https_proxy=$ci_proxy make ci-test
Result: Success
Revno: 164
Branch: lp:~davidpbritton/lp2kanban/use-logging
Jenkins: https://ci.lscape.net/job/latch-test/9631/

review: Approve (test results)
review: Abstain (executing tests)

Command: http_proxy=$CI_PROXY https_proxy=$CI_PROXY make ci-test
Result: Success
Revno: 164
Branch: lp:~davidpbritton/lp2kanban/use-logging
Jenkins: https://ci.lscape.net/job/latch-test/9633/

review: Approve (test results)
Alberto Donato (ack) wrote :

Nice! +1

Small nit inline.

Also, it'd be nice to convert all %-formatting to .format() while you are at it.

review: Approve
165. By David Britton on 2016-09-01

Merge up from filter-bugs...

review: Abstain (executing tests)

Command: http_proxy=$CI_PROXY https_proxy=$CI_PROXY make ci-test
Result: Fail
Revno: 165
Branch: lp:~davidpbritton/lp2kanban/use-logging
Jenkins: https://ci.lscape.net/job/latch-test/10139/

review: Needs Fixing (test results)
David Britton (davidpbritton) wrote :

fixed all comments from ack

review: Abstain (executing tests)

Command: http_proxy=$CI_PROXY https_proxy=$CI_PROXY make ci-test
Result: Success
Revno: 165
Branch: lp:~davidpbritton/lp2kanban/use-logging
Jenkins: https://ci.lscape.net/job/latch-test/10141/

review: Approve (test results)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lp2kanban/bugs2cards.py'
2--- src/lp2kanban/bugs2cards.py 2016-09-01 21:41:15 +0000
3+++ src/lp2kanban/bugs2cards.py 2016-09-01 21:41:15 +0000
4@@ -19,8 +19,8 @@
5 import os.path
6 import re
7 import sys
8-from traceback import print_exc
9
10+log = logging.getLogger(__name__)
11 TITLE_MARKER = "sync:"
12 DESCRIPTION_MARKER = "Synced with Launchpad"
13 NO_SYNC_MARKER = "(no-sync)"
14@@ -127,9 +127,8 @@
15 for user in board.users:
16 lp_user = lp.people.getByEmail(email=user)
17 if lp_user is None:
18- print (
19- "WARNING: There is no matching Launchpad user for kanban"
20- " user %s." % (user,))
21+ log.warning(
22+ "No matching lp user for kanban user {}.".format(user))
23 continue
24 self.lp_to_kanban[lp_user.name] = board.users[user]
25 self.kanban_to_lp[board.users[user].id] = lp_user
26@@ -154,16 +153,18 @@
27 self.feature_lanes[group_tag] = lane
28 for card in board.getFeatureCards():
29 if not card.tags:
30- print ("Info: feature card '%s' has no tags. New bugs tagged "
31- "for this feature will not be moved to the proper "
32- "new_lane." % card.title)
33+ log.warning(
34+ "Feature card '%s' has no tags. New bugs tagged "
35+ "for this feature will not be moved to the proper "
36+ "new_lane." % card.title)
37 continue
38 if "${group}" in new_lane:
39 lp_user = self.kanban_to_lp.get(card.assigned_user_id)
40 if not lp_user:
41- print ("Info: feature card '%s' has no assigned user. New "
42- "bugs tagged for this feature will not be moved to "
43- "the proper new_lane." % card.title)
44+ log.debug(
45+ "Feature card '%s' has no assigned user. New "
46+ "bugs tagged for this feature will not be moved to "
47+ "the proper new_lane." % card.title)
48 continue
49 lane_path = new_lane.replace(
50 "${group}", self.lp_to_group[lp_user.name])
51@@ -201,14 +202,15 @@
52 try:
53 bug_id = int(card.external_card_id)
54 except ValueError:
55- print "Invalid external id (%s) for card '%s'" % (
56- card.external_card_id, card.title)
57+ log.execption(
58+ "Invalid external id (%s) for card '%s'" % (
59+ card.external_card_id, card.title))
60 return None
61 try:
62 lp_bug = launchpad.bugs[bug_id]
63 except KeyError:
64- print (
65- " * %d is not accessible "
66+ log.exception(
67+ " * %d is not accessible "
68 "(does not exist or forbidden)." % (bug_id))
69 return None
70 return lp_bug
71@@ -234,13 +236,13 @@
72 continue
73 card_path = card.lane.path
74 if card_path in source_lanes:
75- print "Moving to taskboard '{}' card-{}".format(
76- feature_card.title, card.title)
77+ log.info(" * Moving to taskboard '{}' card-{}".format(
78+ feature_card.title, card.title))
79 card.moveToTaskBoard(feature_card)
80 else:
81- print (
82- "Card in progress, not moving to taskboard '%s' card-%s." %
83- (feature_card.title, card.title))
84+ log.debug(
85+ "Card in progress, not moving to taskboard '%s' card-%s." % (
86+ feature_card.title, card.title))
87
88
89 def get_cards_for_feature(feature_card, feature_bug=None, card_type=None):
90@@ -359,13 +361,13 @@
91 """
92 if conf.get('sync_cards', 'off') == 'off':
93 return False
94- logging.debug("Should I sync? - {}".format(card.title))
95+ log.debug("Should I sync? - {}".format(card.title))
96 no_sync_lanes = [
97 lane_path.strip()
98 for lane_path in conf.get("no_sync_lanes", "").split(",")]
99 for no_sync_lane_path in no_sync_lanes:
100 if no_sync_lane_path and card.lane.path.endswith(no_sync_lane_path):
101- logging.debug("Not syncing, {} in no_sync_lanes".format(
102+ log.debug("Not syncing, {} in no_sync_lanes".format(
103 card.lane.path))
104 return False
105 if conf.get('autosync', None) in ['on', 'active-projects']:
106@@ -452,8 +454,8 @@
107 try:
108 bugid = int(card.external_card_id)
109 except ValueError:
110- print "Invalid external id (%s) for card '%s'" % (
111- card.external_card_id, card.title)
112+ log.exception("Invalid external id (%s) for card '%s'" % (
113+ card.external_card_id, card.title))
114 continue
115 existing_bugs.add(bugid)
116 for bug in bugs:
117@@ -579,7 +581,7 @@
118 If a bug is tagged with the given tag, a new card will be created in
119 the board and the tag will be removed from the bug.
120 """
121- print " Creating new cards for %s:" % launchpad_project.name
122+ log.info("Creating new cards for %s:" % launchpad_project.name)
123 if not feature_lanes:
124 feature_lanes = {}
125 new_cardtype = board.default_cardtype.id
126@@ -606,7 +608,7 @@
127 if not feature_lane:
128 card = next_lane.addCard()
129
130- bug_msg = " Creating card for bug %s in %s: %%s" % (
131+ bug_msg = " * Creating card for bug %s in %s: %%s" % (
132 bug.id, card.lane.title)
133 card.title = bug.title
134 # Leankit empirically has a max description length of 19997 bytes
135@@ -616,11 +618,11 @@
136 saved = card.save()
137 # Only update bug tags if card was successfully saved.
138 if saved is not None:
139- print bug_msg % "DONE"
140+ log.info(bug_msg % "DONE")
141 bug.tags = [tag for tag in bug.tags if tag != bug_tag]
142 bug.lp_save()
143 else:
144- print bug_msg % "ERROR"
145+ log.info(bug_msg % "ERROR")
146
147
148 def get_lp(config):
149@@ -637,13 +639,14 @@
150 'lp2kanban', config['lp_server'], version="devel",
151 credentials_file=credentials_file,
152 launchpadlib_dir=launchpadlib_dir)
153- print " Logged in as", lp.me.name
154+ log.info("Logged in as", lp.me.name)
155 else:
156 lp = Launchpad.login_anonymously(
157 'lp2kanban', config['lp_server'], version="devel",
158 launchpadlib_dir=launchpadlib_dir)
159- print (" Accessing Launchpad anonymously. "
160- "Private bugs will not be synced.")
161+ log.info(
162+ "Accessing Launchpad anonymously -- "
163+ "Private bugs will not be synced.")
164 return lp
165
166
167@@ -679,7 +682,7 @@
168
169 def create_cards(board, bconf, lp_users, lp_projects):
170 """Create new cards on all projects."""
171- logging.info("Creating new cards")
172+ log.info("Creating new cards")
173 new_bug_tag = bconf.get("bug_to_card_tag")
174 if new_bug_tag is not None:
175 for lp_project in lp_projects:
176@@ -691,7 +694,7 @@
177 def sync_cards_linked_branches(
178 board, bconf, lp, lp_users, filter_card=None):
179 """Sync any cards that have linked external branches."""
180- logging.info("Syncing branch cards")
181+ log.info("Syncing branch cards")
182 for card in board.getCardsWithExternalLinks(only_branches=True):
183 if filter_card and filter_card != card.id:
184 continue
185@@ -701,8 +704,8 @@
186 branch_name = get_lp_branch_name(card.external_system_url)
187 branch = lp.branches.getByUniqueName(unique_name=branch_name)
188 if not branch:
189- print "Invalid branch url ({}) for card '{}'".format(
190- card.external_system_url, card.title)
191+ log.warning("Invalid branch url ({}) for card '{}'".format(
192+ card.external_system_url, card.title))
193 continue
194 if should_sync_card(card, bconf):
195 branch_info = get_branch_info([branch])
196@@ -719,23 +722,22 @@
197 try:
198 move_card(card, card_status, bconf, [assignee], lp_users)
199 except IOError as e:
200- print " * %s (in %s)" % (card.title, card_path)
201- print " >>> Error moving card:"
202- print " ", e
203+ log.exception("Error moving card: %s (in %s)" % (
204+ card.title, card_path))
205 continue
206 kanban_user = lp_users.lp_to_kanban.get(assignee.name, None)
207 if kanban_user:
208 card.assigned_user_id = kanban_user.id
209 card.kanban_user = kanban_user
210 else:
211- print " * %s (in %s)" % (card.title, card_path)
212+ log.info("* Synced: %s (in %s)" % (card.title, card_path))
213
214
215 def sync_cards_external_ids(
216 board, bconf, lp, lp_users, lp_projects, filter_bug=None,
217 filter_card=None):
218 """Sync any cards that have linked external ids (bugs in launchpad)."""
219- logging.info("Syncing cards with external ids")
220+ log.info("Syncing cards with external ids")
221 for card in board.getCardsWithExternalIds():
222 if filter_bug and card.external_card_id != filter_bug:
223 continue
224@@ -763,10 +765,8 @@
225 try:
226 move_card(card, card_status, bconf, assignees, lp_users)
227 except IOError as e:
228- print " * %s: %s (in %s)" % (
229- lp_bug.id, card.title, card_path)
230- print " >>> Error moving card:"
231- print " ", e
232+ log.exception("Error Moving: lp:%s: %s (in %s)" % (
233+ lp_bug.id, card.title, card_path))
234 continue
235 if synced:
236 card.title = lp_bug.title
237@@ -782,15 +782,16 @@
238 if mp_url and mp_type:
239 card.external_system_url = mp_url
240 card.external_system_name = mp_type
241- print " * %s: %s (in %s)" % (lp_bug.id, card.title, card_path)
242+ log.debug("Synced: lp:%s - %s (in %s)" % (
243+ lp_bug.id, card.title, card_path))
244 else:
245- print " * %s: %s -- Not synced" % (
246- lp_bug.id, card.title)
247+ log.debug("NOT Synced: lp:%s: %s" % (lp_bug.id, card.title))
248+
249
250 def move_cards_to_taskboards(
251 board, bconf, lp, lp_users, filter_card=None):
252 """Move branch cards to feature cards if they are landed."""
253- logging.info("Move cards to taskboards")
254+ log.info("Move cards to taskboards")
255 if "${group}" in bconf["landing_lanes"]:
256 # Replace the optional template ${group} with configured board groups.
257 # This creates a list of landing_lanes, one per group on the board.
258@@ -810,17 +811,17 @@
259
260 def convert_cards_to_work_items(board, bconf, lp, lp_users, lp_projects):
261 """Create work items out of cards if desired."""
262- logging.info("Convert cards to work items")
263+ log.info("Convert cards to work items")
264 if bconf.get("convert_cards_to_work_items", False) == "on":
265 # Sync cards to blueprint work items, if so configured.
266- print " Checking for cards to sync with work items..."
267+ log.info("Checking for cards to sync with work items")
268 cards_to_convert = get_blueprint_linked_cards(board)
269 work_items = convert_cards_to_work_items(
270 cards_to_convert, board, lp_users)
271 if len(work_items) == 0:
272- print "No cards converted to work items."
273+ log.info("No cards converted to work items.")
274 else:
275- print "Updating blueprints from work items."
276+ log.info("Updating blueprints from work items.")
277 update_blueprints_from_work_items(lp, work_items)
278
279
280@@ -835,7 +836,7 @@
281
282 If a card is located in a "no_move" lane, the card won't get moved.
283 """
284- logging.debug("Evaluating for move: {}".format(card.title))
285+ log.debug("Evaluating for move: {}".format(card.title))
286 target_lane_path = bconf[ConfigOptionByStatus[bug_status]]
287 if "${group}" in target_lane_path:
288 if assignees:
289@@ -843,12 +844,12 @@
290 if group:
291 target_lane_path = target_lane_path.replace("${group}", group)
292 else:
293- logging.debug(
294- "Not moving, assignee: {} not in group: {}".format(
295+ log.debug(
296+ "Not moving, assignee:{} not in group: {}".format(
297 assignees[0].name, group))
298 return
299 else:
300- logging.debug("Not moving, not assigned")
301+ log.debug("Not moving, not assigned")
302 return
303
304 omnidirectional_card_moves = (
305@@ -859,7 +860,7 @@
306 if lane_path]
307 for no_move_lane_path in no_move_lanes:
308 if no_move_lane_path and card.lane.path.endswith(no_move_lane_path):
309- logging.debug("Not moving, {} in no_move_lanes".format(
310+ log.debug("Not moving, {} in no_move_lanes".format(
311 card.lane.path))
312 return
313
314@@ -870,11 +871,11 @@
315 target_lane = find_card_target_lane_next(
316 card.lane, target_lane_path)
317 if card.lane.path == target_lane_path:
318- logging.debug("Not moving, already in {}".format(card.lane.path))
319+ log.debug("Not moving, already in {}".format(card.lane.path))
320 return
321
322- logging.debug(
323- " * Moving: {} -> {}".format(card.lane.path, target_lane_path))
324+ log.info(
325+ " * Moving card#{}: {} -> {}".format(card.id, card.lane.path, target_lane_path))
326 card.move(target_lane)
327
328
329@@ -886,18 +887,19 @@
330 card.description += '\n' + DESCRIPTION_MARKER
331 card.description = card.description.strip()
332
333- print " Saving '%s' for #%s." % (
334- "', '".join(card.dirty_attrs), card.external_card_id)
335+ log.info(" * Saving {} for lp:%s.".format(
336+ "', '".join(card.dirty_attrs), card.external_card_id))
337 # Attempt to save the card. If is it not dirty or new then nothing
338 # happens.
339 try:
340 card.save()
341 except IOError as e:
342- print "Exception caught. Skipping board."
343- print " desc:", card.description
344- print " kanban id:", card.assigned_user_id
345- print " LP bug id:", card.external_card_id
346- print_exc()
347+ log.exception("Exception caught. Skipping board.\n"
348+ " desc:{}\n"
349+ " kanban id:{}\n"
350+ " LP bug id:{}\n".format(
351+ card.description, card.assigned_user_id,
352+ card.external_card_id))
353 continue
354
355
356@@ -947,10 +949,10 @@
357 kanban = LeankitKanban(global_config['account'], user, password)
358
359 if args.list:
360- print "All active boards:"
361+ log.info("All active boards:")
362 boards = kanban.getBoards()
363 for board in boards:
364- print " * %s (%d)" % (board.title, board.id)
365+ log.info(" * %s (%d)" % (board.title, board.id))
366 return
367
368 if args.board:
369@@ -960,19 +962,18 @@
370 board_names = [args.board]
371 else:
372 board_names = boards_config.keys()
373- print "Requested boards:"
374+ log.info("Requested boards:")
375 for board_name in board_names:
376- print " * %s" % board_name
377+ log.info(" * %s" % board_name)
378 try:
379 board = kanban.getBoard(title=board_name)
380 if board is None:
381- print "Could not retrieve board. Skipping."
382+ log.info("Could not retrieve board. Skipping.")
383 continue
384 bconf = boards_config[board_name]
385 process_board(board, bconf, args.bug, args.card)
386 except (KeyError, AssertionError) as e:
387- print "Exception caught. Skipping board."
388- print_exc()
389+ log.exception("Exception caught. Skipping board.")
390 continue
391
392
393
394=== modified file 'src/lp2kanban/tests/test_bugs2cards.py'
395--- src/lp2kanban/tests/test_bugs2cards.py 2016-09-01 21:41:15 +0000
396+++ src/lp2kanban/tests/test_bugs2cards.py 2016-09-01 21:41:15 +0000
397@@ -1497,8 +1497,8 @@
398 move_card(card, CardStatus.QA, self.bconf, [], self.lp_users)
399 self.assertEqual(None, card.moved_to)
400 testlog.check(
401- ('root', 'DEBUG', 'Evaluating for move: '),
402- ('root', 'DEBUG', 'Not moving, already in qa'))
403+ ('lp2kanban.bugs2cards', 'DEBUG', 'Evaluating for move: '),
404+ ('lp2kanban.bugs2cards', 'DEBUG', 'Not moving, already in qa'))
405
406 @log_capture()
407 def test_group_no_assignee(self, testlog):
408@@ -1510,8 +1510,8 @@
409 move_card(card, CardStatus.CODING, self.bconf, [], self.lp_users)
410 self.assertEqual(None, card.moved_to)
411 testlog.check(
412- ('root', 'DEBUG', 'Evaluating for move: '),
413- ('root', 'DEBUG', 'Not moving, not assigned'))
414+ ('lp2kanban.bugs2cards', 'DEBUG', 'Evaluating for move: '),
415+ ('lp2kanban.bugs2cards', 'DEBUG', 'Not moving, not assigned'))
416
417 def test_group_assignee_in_group(self):
418 # If a target lane requires a group, and the card has an
419@@ -1539,10 +1539,9 @@
420 self.lp_users)
421 self.assertEqual(None, card.moved_to)
422 testlog.check(
423- ('root', 'DEBUG', 'Evaluating for move: '),
424- ('root', 'DEBUG', 'Not moving, assignee: bar not in group: None'))
425-
426-
427+ ('lp2kanban.bugs2cards', 'DEBUG', 'Evaluating for move: '),
428+ ('lp2kanban.bugs2cards', 'DEBUG',
429+ 'Not moving, assignee:bar not in group: None'))
430
431 def test_no_move_lanes(self):
432 # Cards in a "no_move" lane doesn't get moved by move_card().

Subscribers

People subscribed via source and target branches

to all changes: