[rds] Refactor script (#242)
Make the script more readable, mostly by: - using the Product class, - a little bit of renaming and documentation.
This commit is contained in:
40
src/rds.py
40
src/rds.py
@@ -4,33 +4,35 @@ from common import http
|
||||
from common import dates
|
||||
from common import endoflife
|
||||
|
||||
VERSION_REGEX = r"(?P<v>\d+(?:\.\d+)*)" # https://regex101.com/r/BY1vwV/1
|
||||
DBS = {
|
||||
"mysql": "https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Concepts.VersionMgmt.html",
|
||||
"postgresql": "https://docs.aws.amazon.com/AmazonRDS/latest/PostgreSQLReleaseNotes/postgresql-release-calendar.html",
|
||||
"""Fetches Amazon RDS versions from the version management pages on AWS docs.
|
||||
|
||||
Pages parsed by this script are expected to have version tables with a version in the first column and its release date
|
||||
in the third column (usually named 'RDS release date').
|
||||
"""
|
||||
|
||||
PRODUCTS = {
|
||||
"amazon-rds-mysql": "https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Concepts.VersionMgmt.html",
|
||||
"amazon-rds-postgresql": "https://docs.aws.amazon.com/AmazonRDS/latest/PostgreSQLReleaseNotes/postgresql-release-calendar.html",
|
||||
}
|
||||
VERSION_REGEX = re.compile(r"(?P<version>\d+(?:\.\d+)*)", flags=re.IGNORECASE) # https://regex101.com/r/BY1vwV/1
|
||||
|
||||
for db, url in DBS.items():
|
||||
print(f"::group::{db}")
|
||||
versions = {}
|
||||
|
||||
for product_name, url in PRODUCTS.items():
|
||||
print(f"::group::{product_name}")
|
||||
product = endoflife.Product(product_name)
|
||||
response = http.fetch_url(url)
|
||||
soup = BeautifulSoup(response.text, features="html5lib")
|
||||
|
||||
for table in soup.find_all("table"):
|
||||
for row in table.find_all("tr"):
|
||||
columns = row.find_all("td")
|
||||
if len(columns) <= 3:
|
||||
continue
|
||||
|
||||
# Must match both the 'Supported XXX minor versions' and
|
||||
# 'Supported XXX major versions' to have correct release dates
|
||||
if len(columns) > 3:
|
||||
m = re.search(VERSION_REGEX, columns[0].text.strip(), flags=re.IGNORECASE)
|
||||
if m:
|
||||
date = dates.parse_date(columns[2].text).strftime("%Y-%m-%d")
|
||||
if date:
|
||||
version = m.group("v")
|
||||
print(f"{version} : {date}")
|
||||
versions[version] = date
|
||||
version_match = VERSION_REGEX.search(columns[0].text.strip())
|
||||
if version_match:
|
||||
version = version_match.group("version")
|
||||
date = dates.parse_date(columns[2].text)
|
||||
product.declare_version(version, date)
|
||||
|
||||
endoflife.write_releases(f"amazon-rds-{db.lower()}", versions)
|
||||
product.write()
|
||||
print("::endgroup::")
|
||||
|
||||
Reference in New Issue
Block a user