gstepanov | 71764e9 | 2015-02-02 16:33:11 +0200 | [diff] [blame^] | 1 | import gspread |
| 2 | from config import EMAIL, PASSWORD, DOCUMENT_ID, WORK_SHEET |
| 3 | from make_report import get_work_sheet, append_row |
| 4 | |
| 5 | |
| 6 | class Measurement(object): |
| 7 | def __init__(self): |
| 8 | self.build = "" |
| 9 | self.build_type = 0 # GA/Master/Other |
| 10 | self.md5 = "" |
| 11 | self.results = { |
| 12 | "": (float, float) |
| 13 | } |
| 14 | |
| 15 | |
| 16 | class Storage(object): |
| 17 | |
| 18 | def __init__(self, email, password, doc_id, work_sheet_name): |
| 19 | self.gc = gspread.login(email, password) |
| 20 | self.sh = self.gc.open_by_key(doc_id) |
| 21 | self.work_sheet = get_work_sheet(self.sh, work_sheet_name, 40) |
| 22 | |
| 23 | def store(self, data): |
| 24 | append_row(self.work_sheet, data) |
| 25 | |
| 26 | def retrieve(self, id): |
| 27 | row_number = self.find_by_id(id) |
| 28 | |
| 29 | if row_number != -1: |
| 30 | vals = self.work_sheet.row_values(row_number) |
| 31 | m = Measurement() |
| 32 | m.build = vals["build_id"] |
| 33 | del vals["build_id"] |
| 34 | m.build_type = vals["type"] |
| 35 | del vals["type"] |
| 36 | m.md5 = vals["iso_md5"] |
| 37 | del vals["iso_md5"] |
| 38 | m.results = {k: vals[k] for k in vals.keys()} |
| 39 | else: |
| 40 | return None |
| 41 | |
| 42 | def find_by_id(self, row_id): |
| 43 | for i in range(1, self.work_sheet): |
| 44 | if self.work_sheet.cell(i, 1) == row_id: |
| 45 | return i |
| 46 | |
| 47 | return -1 |
| 48 | |
| 49 | |