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
=== modified file 'citrain/prepare-silo-using-spreadsheet-info'
--- citrain/prepare-silo-using-spreadsheet-info 2014-04-04 07:35:59 +0000
+++ citrain/prepare-silo-using-spreadsheet-info 2014-07-28 16:53:19 +0000
@@ -27,10 +27,14 @@
27import sys27import sys
28import tempfile28import tempfile
2929
30from cupstream2distro.settings import SPREADSHEET_CSV_URL, LANDERS_COL_NUM, SPREADSHEET_ID_COL_NUM, SPREADSHEET_SILONAME_COL_NUM, SPREADSHEET_MPS_COL_NUM, SPREADSHEET_SOURCES_COL_NUM30from cupstream2distro.settings import SPREADSHEET_CSV_URL
31from cupstream2distro.tools import parse_and_clean_entry31from cupstream2distro.tools import parse_and_clean_entry
3232
3333
34class COL:
35 pass
36
37
34if __name__ == '__main__':38if __name__ == '__main__':
3539
36 logging.basicConfig(level=logging.INFO)40 logging.basicConfig(level=logging.INFO)
@@ -82,23 +86,32 @@
82 unique_silo_name = True86 unique_silo_name = True
83 with open(filename, 'rb') as f:87 with open(filename, 'rb') as f:
84 content = csv.reader(f)88 content = csv.reader(f)
89
90 # First two rows are misc header data that don't conform to the columns
91 content.next() and content.next()
92
93 # Map column header names to column numbers
94 for i, heading in enumerate(content.next()):
95 setattr(COL, re.split('\W', heading.lower())[0], i)
96
97 # Now iterate over the remaining rows, which are just the actual data
85 for row in content:98 for row in content:
86 if args.reconfigure_for_silo:99 if args.reconfigure_for_silo:
87 if row[SPREADSHEET_SILONAME_COL_NUM] == args.reconfigure_for_silo:100 if row[COL.assigned] == args.reconfigure_for_silo:
88 # second matching101 # second matching
89 if request_found:102 if request_found:
90 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))103 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))
91 unique_silo_name = False104 unique_silo_name = False
92 args.request_id = row[SPREADSHEET_ID_COL_NUM]105 args.request_id = row[COL.request]
93 raw_mps = row[SPREADSHEET_MPS_COL_NUM]106 raw_mps = row[COL.merge]
94 raw_sources = row[SPREADSHEET_SOURCES_COL_NUM]107 raw_sources = row[COL.additional]
95 raw_landers = row[LANDERS_COL_NUM]108 raw_landers = row[COL.lander]
96 request_found = True109 request_found = True
97 else:110 else:
98 if row[SPREADSHEET_ID_COL_NUM] == args.request_id:111 if row[COL.request] == args.request_id:
99 raw_mps = row[SPREADSHEET_MPS_COL_NUM]112 raw_mps = row[COL.merge]
100 raw_sources = row[SPREADSHEET_SOURCES_COL_NUM]113 raw_sources = row[COL.additional]
101 raw_landers = row[LANDERS_COL_NUM]114 raw_landers = row[COL.lander]
102 request_found = True115 request_found = True
103 break116 break
104 os.remove(filename)117 os.remove(filename)
105118
=== modified file 'cupstream2distro/settings.py'
--- cupstream2distro/settings.py 2014-07-22 14:17:37 +0000
+++ cupstream2distro/settings.py 2014-07-28 16:53:19 +0000
@@ -20,11 +20,6 @@
20import os20import os
2121
22SPREADSHEET_CSV_URL = "https://docs.google.com/a/canonical.com/spreadsheet/ccc?key=0AuDk72Lpx8U5dFVHQ3FuMDJGLUZCamJfSjYzbWh3Wnc&output=csv"22SPREADSHEET_CSV_URL = "https://docs.google.com/a/canonical.com/spreadsheet/ccc?key=0AuDk72Lpx8U5dFVHQ3FuMDJGLUZCamJfSjYzbWh3Wnc&output=csv"
23LANDERS_COL_NUM = 1
24SPREADSHEET_ID_COL_NUM = 10
25SPREADSHEET_SILONAME_COL_NUM = 11
26SPREADSHEET_MPS_COL_NUM = 5
27SPREADSHEET_SOURCES_COL_NUM = 6
2823
29REV_STRING_FORMAT = "Automatic snapshot from revision"24REV_STRING_FORMAT = "Automatic snapshot from revision"
30NEW_CHANGELOG_PATTERN = "^{} \(.*\) (?!UNRELEASED)"25NEW_CHANGELOG_PATTERN = "^{} \(.*\) (?!UNRELEASED)"

Subscribers

People subscribed via source and target branches