Created
April 8, 2020 18:57
-
-
Save kmaglione/87168dd978d190be40304c5953961af4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim:se sts=4 sw=4 et fenc=utf-8 ft=python: | |
import os.path | |
import pickle | |
from google_auth_oauthlib.flow import InstalledAppFlow | |
from google.auth.transport.requests import Request | |
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
CREDS_JSON = os.path.join(BASE_DIR, 'credentials.json') | |
CREDS_PICKLE = os.path.join(BASE_DIR, 'credentials.pickle') | |
SCOPES = ['https://www.googleapis.com/auth/spreadsheets'] | |
def auth(): | |
creds = None | |
if os.path.exists(CREDS_PICKLE): | |
with open(CREDS_PICKLE, 'rb') as fh: | |
creds = pickle.load(fh) | |
if creds and creds.expired and creds.refresh_token: | |
creds.refresh(Request()) | |
elif not (creds and creds.valid): | |
flow = InstalledAppFlow.from_client_secrets_file( | |
CREDS_JSON, SCOPES) | |
creds = flow.run_local_server(port=0) | |
with open(CREDS_PICKLE, 'wb') as fh: | |
pickle.dump(creds, fh) | |
return creds |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim:se sts=4 sw=4 et fenc=utf-8 ft=python: | |
import csv | |
import json | |
import re | |
import sys | |
from collections import defaultdict | |
not_fission_re = re.compile(r'(?<!!)fission') | |
debug_re = re.compile(r'fission && \(?debug') | |
comment_re = re.compile(r'fission[^\n#]#\s*([^\n]*)') | |
def match(thing, debug): | |
return (thing and not_fission_re.search(thing) and | |
(debug or not debug_re.search(thing))) | |
def get_status(test, debug): | |
if match(test.get('skip-if'), debug): | |
return 'skipped' | |
if match(test.get('fail-if'), debug): | |
return 'fails' | |
return 'passes' | |
def get_comment(expr): | |
if expr: | |
match = comment_re.search(expr) | |
if match: | |
return match.group(1) | |
class Test(object): | |
def __init__(self, group, data): | |
self.group = group | |
self.test = data['test'] | |
self.opt_status = get_status(data, False) | |
self.debug_status = get_status(data, True) | |
self.comment = (get_comment(data.get('skip-if')) or | |
get_comment(data.get('fail-if'))) | |
def write_csv(self, csv): | |
csv.writerow(['', self.test, self.opt_status, self.debug_status, '', | |
self.comment]) | |
def write_csv_status(self, csv): | |
csv.writerow([self.test, self.opt_status, self.debug_status, | |
self.group.name]) | |
class Group(object): | |
def __init__(self): | |
self.tests = [] | |
def write_csv(self, csv): | |
csv.writerow([self.name]) | |
for test in self.tests: | |
test.write_csv(csv) | |
def write_csv_status(self, csv): | |
for test in self.tests: | |
test.write_csv_status(csv) | |
data = json.load(sys.stdin)['tests'] | |
output = csv.writer(sys.stdout) | |
groups = defaultdict(Group) | |
for comp, tests in data.items(): | |
group = groups[comp] | |
group.name = comp | |
for test in tests: | |
group.tests.append(Test(group, test)) | |
group_list = sorted(groups.values(), key=lambda g: g.name) | |
if False: | |
for group in group_list: | |
group.tests.sort(key=lambda t: t.test) | |
group.write_csv(output) | |
else: | |
tests = [] | |
for group in group_list: | |
tests.extend(group.tests) | |
for test in sorted(tests, key=lambda t: t.test): | |
test.write_csv_status(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim:se sts=4 sw=4 et fenc=utf-8 ft=python: | |
import csv | |
import json | |
import os.path | |
import sys | |
import googleapiclient.discovery | |
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
sys.path.insert(0, BASE_DIR) | |
from fission import auth # noqa | |
SPREADSHEET_ID = '1kjp32JTuB4axM3wKx0iIYL2Ado-HcyeBhoY-siGxYAs' | |
STATUSES_RANGE = 'TestStatuses' | |
service = googleapiclient.discovery.build('sheets', 'v4', credentials=auth()) | |
sheets = service.spreadsheets() | |
values = list(csv.reader(sys.stdin)) | |
result = sheets.values().clear( | |
spreadsheetId=SPREADSHEET_ID, | |
range=STATUSES_RANGE).execute() | |
print(json.dumps(result)) | |
result = sheets.values().update( | |
spreadsheetId=SPREADSHEET_ID, | |
range=STATUSES_RANGE, | |
valueInputOption='RAW', | |
body={ | |
'majorDimension': 'ROWS', | |
'values': values, | |
}).execute() | |
print(json.dumps(result)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment