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
1=== modified file 'plugins/landing.py'
2--- plugins/landing.py 2014-07-10 13:40:08 +0000
3+++ plugins/landing.py 2014-07-16 18:32:22 +0000
4@@ -5,12 +5,17 @@
5 import threading
6 import traceback
7 import urllib2
8+import re
9
10 URL = "https://docs.google.com/spreadsheet/ccc" \
11 "?key=0AuDk72Lpx8U5dFVHQ3FuMDJGLUZCamJfSjYzbWh3Wnc" \
12 "&usp=sharing&output=csv"
13
14
15+class COL:
16+ pass
17+
18+
19 class LandingScanner(threading.Thread):
20 notices = list()
21
22@@ -31,44 +36,55 @@
23
24 try:
25 reader = csv.reader(opener.open(URL))
26+ # First two lines are ignorable
27+ reader.next() and reader.next()
28 except Exception as e:
29 print("Unable to read spreadsheet: %s" % e)
30 return
31
32+ # Map column header names to column numbers
33+ for i, heading in enumerate(reader.next()):
34+ setattr(COL, re.split('\W', heading.lower())[0], i)
35+
36 landing_ready = set()
37- line_num = 0
38- for line in reader:
39- line_num += 1
40-
41+ for line_num, line in enumerate(reader, start=4):
42 # Do some basic validation
43 if len(line) < 17:
44 continue
45
46- old_status = self.testing_state[self.queue].get(line[0])
47- if old_status != line[12]:
48- self.testing_state[self.queue][line[0]] = line[12]
49- if "Testing pass" in line[12]:
50- self.notices.append(("%s: trainguards, silo %s: %s"
51- % (self.queue, line[11], line[12]),
52- ("landing",)))
53-
54- if line[8] != "Yes" or line[10]:
55+ description = line[COL.description]
56+ new_status = line[COL.computed]
57+ silo_name = line[COL.assigned]
58+ landers = line[COL.lander]
59+ ready = line[COL.ready]
60+ request = line[COL.request]
61+
62+ old_status = self.testing_state[self.queue].get(description)
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:
72 continue
73
74- landing_ready.add(line[0])
75+ landing_ready.add(description)
76
77 if self.queue not in self.landing_state:
78 continue
79
80 if self.queue in self.landing_state and \
81- line[0] in self.landing_state[self.queue]:
82+ description in self.landing_state[self.queue]:
83 continue
84
85 self.notices.append(("%s: trainguards, new landing "
86 "ready for assignment "
87 "(line %s, lander is %s)"
88 % (self.queue, line_num,
89- ", ".join(line[1].split())),
90+ ", ".join(landers.split())),
91 ("landing",)))
92
93 self.landing_state[self.queue] = landing_ready

Subscribers

People subscribed via source and target branches