mirror of
git://git.yoctoproject.org/yocto-autobuilder-helper.git
synced 2025-07-19 20:59:02 +02:00
scripts/abint: add argument parser
Add an argument parser so that the use of the cache or verbose logging can be enabled/disabled without having to edit the source code. Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
e2ede6667a
commit
d277a1ce1d
|
@ -1,5 +1,6 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import collections
|
||||
import dataclasses
|
||||
import logging
|
||||
|
@ -11,19 +12,6 @@ import arrow
|
|||
import bugzilla
|
||||
import requests
|
||||
|
||||
MOCK = False
|
||||
# logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
def save_pickle(name, data):
|
||||
with open(name, "wb") as f:
|
||||
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
|
||||
|
||||
|
||||
def load_pickle(name):
|
||||
with open(name, "rb") as f:
|
||||
return pickle.load(f)
|
||||
|
||||
|
||||
http = requests.Session()
|
||||
|
||||
|
@ -104,15 +92,9 @@ def get_data():
|
|||
except requests.exceptions.HTTPError as e:
|
||||
logging.debug(f"Couldn't find build for {builder=} {build=}")
|
||||
|
||||
save_pickle("bugs.data", bugs)
|
||||
return bugs
|
||||
|
||||
|
||||
if MOCK:
|
||||
|
||||
def get_data():
|
||||
return load_pickle("bugs.data")
|
||||
|
||||
|
||||
def last_seen_report(data):
|
||||
import jinja2
|
||||
|
@ -129,5 +111,26 @@ def last_seen_report(data):
|
|||
f.write(template.render(bugs=data, start=start, now=arrow.now()))
|
||||
|
||||
|
||||
data = get_data()
|
||||
last_seen_report(data)
|
||||
CACHE_NAME = "bugs.data"
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--verbose", action="store_true", help="Enable verbose logging")
|
||||
parser.add_argument("--cached", action="store_true", help="Use the local cached data instead of fetching")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.verbose:
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
if args.cached:
|
||||
logging.debug(f"Loading cached data from {CACHE_NAME}")
|
||||
with open(CACHE_NAME, "rb") as f:
|
||||
data = pickle.load(f)
|
||||
else:
|
||||
data = get_data()
|
||||
# Always save a cache because it's quick
|
||||
logging.debug(f"Saving data to cache {CACHE_NAME}")
|
||||
with open(CACHE_NAME, "wb") as f:
|
||||
pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
|
||||
|
||||
last_seen_report(data)
|
||||
|
|
Loading…
Reference in New Issue
Block a user