Merge lp:~robru/queuebot/future-proofing into lp:queuebot

Proposed by Robert Bruce Park
Status: Merged
Merged at revision: 91
Proposed branch: lp:~robru/queuebot/future-proofing
Merge into: lp:queuebot
Diff against target: 93 lines (+32/-16)
1 file modified
plugins/landing.py (+32/-16)
To merge this branch: bzr merge lp:~robru/queuebot/future-proofing
Reviewer Review Type Date Requested Status
Stéphane Graber Pending
Review via email: mp+226948@code.launchpad.net

Description of the change

In order to support RTM, the citrain spreadsheet is going to grow an extra column or two. This branch makes queuebot find data by column header name rather than by hard-coding column numbers, which means it should have no problem adapting to the new column numbers in the future, whatever might need to change.

To post a comment you must log in.
lp:~robru/queuebot/future-proofing updated
95. By Robert Bruce Park

Key off just the first word of the header.

96. By Robert Bruce Park

Use attributes instead of a dict for better readability.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/landing.py'
--- plugins/landing.py 2014-07-10 13:40:08 +0000
+++ plugins/landing.py 2014-07-16 18:32:22 +0000
@@ -5,12 +5,17 @@
5import threading5import threading
6import traceback6import traceback
7import urllib27import urllib2
8import re
89
9URL = "https://docs.google.com/spreadsheet/ccc" \10URL = "https://docs.google.com/spreadsheet/ccc" \
10 "?key=0AuDk72Lpx8U5dFVHQ3FuMDJGLUZCamJfSjYzbWh3Wnc" \11 "?key=0AuDk72Lpx8U5dFVHQ3FuMDJGLUZCamJfSjYzbWh3Wnc" \
11 "&usp=sharing&output=csv"12 "&usp=sharing&output=csv"
1213
1314
15class COL:
16 pass
17
18
14class LandingScanner(threading.Thread):19class LandingScanner(threading.Thread):
15 notices = list()20 notices = list()
1621
@@ -31,44 +36,55 @@
3136
32 try:37 try:
33 reader = csv.reader(opener.open(URL))38 reader = csv.reader(opener.open(URL))
39 # First two lines are ignorable
40 reader.next() and reader.next()
34 except Exception as e:41 except Exception as e:
35 print("Unable to read spreadsheet: %s" % e)42 print("Unable to read spreadsheet: %s" % e)
36 return43 return
3744
45 # Map column header names to column numbers
46 for i, heading in enumerate(reader.next()):
47 setattr(COL, re.split('\W', heading.lower())[0], i)
48
38 landing_ready = set()49 landing_ready = set()
39 line_num = 050 for line_num, line in enumerate(reader, start=4):
40 for line in reader:
41 line_num += 1
42
43 # Do some basic validation51 # Do some basic validation
44 if len(line) < 17:52 if len(line) < 17:
45 continue53 continue
4654
47 old_status = self.testing_state[self.queue].get(line[0])55 description = line[COL.description]
48 if old_status != line[12]:56 new_status = line[COL.computed]
49 self.testing_state[self.queue][line[0]] = line[12]57 silo_name = line[COL.assigned]
50 if "Testing pass" in line[12]:58 landers = line[COL.lander]
51 self.notices.append(("%s: trainguards, silo %s: %s"59 ready = line[COL.ready]
52 % (self.queue, line[11], line[12]),60 request = line[COL.request]
53 ("landing",)))61
5462 old_status = self.testing_state[self.queue].get(description)
55 if line[8] != "Yes" or line[10]:63 if old_status != new_status:
64 self.testing_state[self.queue][description] = new_status
65 if "Testing pass" in new_status:
66 self.notices.append((
67 "%s: trainguards, silo %s: %s"
68 % (self.queue, silo_name, new_status),
69 ("landing",)))
70
71 if ready != "Yes" or request:
56 continue72 continue
5773
58 landing_ready.add(line[0])74 landing_ready.add(description)
5975
60 if self.queue not in self.landing_state:76 if self.queue not in self.landing_state:
61 continue77 continue
6278
63 if self.queue in self.landing_state and \79 if self.queue in self.landing_state and \
64 line[0] in self.landing_state[self.queue]:80 description in self.landing_state[self.queue]:
65 continue81 continue
6682
67 self.notices.append(("%s: trainguards, new landing "83 self.notices.append(("%s: trainguards, new landing "
68 "ready for assignment "84 "ready for assignment "
69 "(line %s, lander is %s)"85 "(line %s, lander is %s)"
70 % (self.queue, line_num,86 % (self.queue, line_num,
71 ", ".join(line[1].split())),87 ", ".join(landers.split())),
72 ("landing",)))88 ("landing",)))
7389
74 self.landing_state[self.queue] = landing_ready90 self.landing_state[self.queue] = landing_ready

Subscribers

People subscribed via source and target branches