Merge lp:~robru/cupstream2distro/stop-hardcoding-spreadsheet-column-numbers into lp:cupstream2distro

Proposed by Robert Bruce Park
Status: Merged
Merged at revision: 641
Proposed branch: lp:~robru/cupstream2distro/stop-hardcoding-spreadsheet-column-numbers
Merge into: lp:cupstream2distro
Diff against target: 77 lines (+23/-15)
2 files modified
citrain/prepare-silo-using-spreadsheet-info (+23/-10)
cupstream2distro/settings.py (+0/-5)
To merge this branch: bzr merge lp:~robru/cupstream2distro/stop-hardcoding-spreadsheet-column-numbers
Reviewer Review Type Date Requested Status
Ɓukasz Zemczak Pending
Review via email: mp+228540@code.launchpad.net

Description of the change

Stop hard-coding spreadsheet column numbers, adapt flexibly to spreadsheet modifications.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'citrain/prepare-silo-using-spreadsheet-info'
2--- citrain/prepare-silo-using-spreadsheet-info 2014-04-04 07:35:59 +0000
3+++ citrain/prepare-silo-using-spreadsheet-info 2014-07-28 16:53:19 +0000
4@@ -27,10 +27,14 @@
5 import sys
6 import tempfile
7
8-from cupstream2distro.settings import SPREADSHEET_CSV_URL, LANDERS_COL_NUM, SPREADSHEET_ID_COL_NUM, SPREADSHEET_SILONAME_COL_NUM, SPREADSHEET_MPS_COL_NUM, SPREADSHEET_SOURCES_COL_NUM
9+from cupstream2distro.settings import SPREADSHEET_CSV_URL
10 from cupstream2distro.tools import parse_and_clean_entry
11
12
13+class COL:
14+ pass
15+
16+
17 if __name__ == '__main__':
18
19 logging.basicConfig(level=logging.INFO)
20@@ -82,23 +86,32 @@
21 unique_silo_name = True
22 with open(filename, 'rb') as f:
23 content = csv.reader(f)
24+
25+ # First two rows are misc header data that don't conform to the columns
26+ content.next() and content.next()
27+
28+ # Map column header names to column numbers
29+ for i, heading in enumerate(content.next()):
30+ setattr(COL, re.split('\W', heading.lower())[0], i)
31+
32+ # Now iterate over the remaining rows, which are just the actual data
33 for row in content:
34 if args.reconfigure_for_silo:
35- if row[SPREADSHEET_SILONAME_COL_NUM] == args.reconfigure_for_silo:
36+ if row[COL.assigned] == args.reconfigure_for_silo:
37 # second matching
38 if request_found:
39 logging.error("{} is available more than once in the spreadsheet. Please request to fix some wrong metadata due to a bad automated sync.".format(args.reconfigure_for_silo))
40 unique_silo_name = False
41- args.request_id = row[SPREADSHEET_ID_COL_NUM]
42- raw_mps = row[SPREADSHEET_MPS_COL_NUM]
43- raw_sources = row[SPREADSHEET_SOURCES_COL_NUM]
44- raw_landers = row[LANDERS_COL_NUM]
45+ args.request_id = row[COL.request]
46+ raw_mps = row[COL.merge]
47+ raw_sources = row[COL.additional]
48+ raw_landers = row[COL.lander]
49 request_found = True
50 else:
51- if row[SPREADSHEET_ID_COL_NUM] == args.request_id:
52- raw_mps = row[SPREADSHEET_MPS_COL_NUM]
53- raw_sources = row[SPREADSHEET_SOURCES_COL_NUM]
54- raw_landers = row[LANDERS_COL_NUM]
55+ if row[COL.request] == args.request_id:
56+ raw_mps = row[COL.merge]
57+ raw_sources = row[COL.additional]
58+ raw_landers = row[COL.lander]
59 request_found = True
60 break
61 os.remove(filename)
62
63=== modified file 'cupstream2distro/settings.py'
64--- cupstream2distro/settings.py 2014-07-22 14:17:37 +0000
65+++ cupstream2distro/settings.py 2014-07-28 16:53:19 +0000
66@@ -20,11 +20,6 @@
67 import os
68
69 SPREADSHEET_CSV_URL = "https://docs.google.com/a/canonical.com/spreadsheet/ccc?key=0AuDk72Lpx8U5dFVHQ3FuMDJGLUZCamJfSjYzbWh3Wnc&output=csv"
70-LANDERS_COL_NUM = 1
71-SPREADSHEET_ID_COL_NUM = 10
72-SPREADSHEET_SILONAME_COL_NUM = 11
73-SPREADSHEET_MPS_COL_NUM = 5
74-SPREADSHEET_SOURCES_COL_NUM = 6
75
76 REV_STRING_FORMAT = "Automatic snapshot from revision"
77 NEW_CHANGELOG_PATTERN = "^{} \(.*\) (?!UNRELEASED)"

Subscribers

People subscribed via source and target branches