Make releasedata.Product usable in 'with' expression (#294)
This way the writing of the JSON file is handled automatically if the update does not fail. It pave the way to further global improvements, such as a better error handling.
This commit is contained in:
42
src/cgit.py
42
src/cgit.py
@@ -10,29 +10,27 @@ METHOD = "cgit"
|
||||
|
||||
p_filter = sys.argv[1] if len(sys.argv) > 1 else None
|
||||
for product in endoflife.list_products(METHOD, p_filter):
|
||||
product_data = releasedata.Product(product.name)
|
||||
for config in product.get_auto_configs(METHOD):
|
||||
response = http.fetch_url(config.url + '/refs/tags')
|
||||
soup = BeautifulSoup(response.text, features="html5lib")
|
||||
with releasedata.ProductData(product.name) as product_data:
|
||||
for config in product.get_auto_configs(METHOD):
|
||||
response = http.fetch_url(config.url + '/refs/tags')
|
||||
soup = BeautifulSoup(response.text, features="html5lib")
|
||||
|
||||
for table in soup.find_all("table", class_="list"):
|
||||
for row in table.find_all("tr"):
|
||||
columns = row.find_all("td")
|
||||
if len(columns) != 4:
|
||||
continue
|
||||
for table in soup.find_all("table", class_="list"):
|
||||
for row in table.find_all("tr"):
|
||||
columns = row.find_all("td")
|
||||
if len(columns) != 4:
|
||||
continue
|
||||
|
||||
version_str = columns[0].text.strip()
|
||||
version_match = config.first_match(version_str)
|
||||
if not version_match:
|
||||
continue
|
||||
version_str = columns[0].text.strip()
|
||||
version_match = config.first_match(version_str)
|
||||
if not version_match:
|
||||
continue
|
||||
|
||||
datetime_td = columns[3].find_next("span")
|
||||
datetime_str = datetime_td.attrs["title"] if datetime_td else None
|
||||
if not datetime_str:
|
||||
continue
|
||||
datetime_td = columns[3].find_next("span")
|
||||
datetime_str = datetime_td.attrs["title"] if datetime_td else None
|
||||
if not datetime_str:
|
||||
continue
|
||||
|
||||
version = config.render(version_match)
|
||||
date = dates.parse_datetime(datetime_str)
|
||||
product_data.declare_version(version, date)
|
||||
|
||||
product_data.write()
|
||||
version = config.render(version_match)
|
||||
date = dates.parse_datetime(datetime_str)
|
||||
product_data.declare_version(version, date)
|
||||
|
||||
Reference in New Issue
Block a user