Align custom scripts with generic scripts (#445)
Align custom scripts with generic scripts, making them configurable. This has a few advantages: - script code is more unified, - no more hard-coded method names in scripts, which is less error prone and make it easier to rename scripts, - no more hard coded product names in scripts, which is less error prone and make it easier to rename products, - less hard-coded URLs and regexes in scripts, which makes auto-configuration more expressive / updatable, Also added method `endoflife.list_configs_from_argv()` so that it is easier to manipulate scripts arguments.
This commit is contained in:
@@ -1,33 +1,34 @@
|
||||
import logging
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from common import dates, http, releasedata
|
||||
from common import dates, endoflife, http, releasedata
|
||||
|
||||
"""Fetches NetBSD versions and EOL information from https://www.netbsd.org/."""
|
||||
|
||||
with releasedata.ProductData('netbsd') as product_data:
|
||||
response = http.fetch_url('https://www.netbsd.org/releases/formal.html')
|
||||
soup = BeautifulSoup(response.text, features="html5lib")
|
||||
for config in endoflife.list_configs_from_argv():
|
||||
with releasedata.ProductData(config.product) as product_data:
|
||||
response = http.fetch_url(config.url)
|
||||
soup = BeautifulSoup(response.text, features="html5lib")
|
||||
|
||||
for row in soup.select('table tbody tr'):
|
||||
cells = [cell.get_text(strip=True) for cell in row.select('td')]
|
||||
for row in soup.select('table tbody tr'):
|
||||
cells = [cell.get_text(strip=True) for cell in row.select('td')]
|
||||
|
||||
version = cells[0]
|
||||
if not version.startswith('NetBSD'):
|
||||
logging.info(f"Skipping row {cells}, version does not start with 'NetBSD'")
|
||||
continue
|
||||
version = version.split(' ')[1]
|
||||
version = cells[0]
|
||||
if not version.startswith('NetBSD'):
|
||||
logging.info(f"Skipping row {cells}, version does not start with 'NetBSD'")
|
||||
continue
|
||||
version = version.split(' ')[1]
|
||||
|
||||
try:
|
||||
release_date = dates.parse_date(cells[1])
|
||||
product_data.declare_version(version, release_date)
|
||||
except ValueError:
|
||||
logging.warning(f"Skipping row {cells}, could not parse release date")
|
||||
try:
|
||||
release_date = dates.parse_date(cells[1])
|
||||
product_data.declare_version(version, release_date)
|
||||
except ValueError:
|
||||
logging.warning(f"Skipping row {cells}, could not parse release date")
|
||||
|
||||
eol_str = cells[2]
|
||||
if not eol_str:
|
||||
continue
|
||||
eol_str = cells[2]
|
||||
if not eol_str:
|
||||
continue
|
||||
|
||||
eol = dates.parse_date(eol_str)
|
||||
major_version = version.split('.')[0]
|
||||
product_data.get_release(major_version).set_eol(eol)
|
||||
eol = dates.parse_date(eol_str)
|
||||
major_version = version.split('.')[0]
|
||||
product_data.get_release(major_version).set_eol(eol)
|
||||
|
||||
Reference in New Issue
Block a user