[sles] Refactor script (#248)

Make the script more readable, mostly by:

- using the Product class,
- removing the use of functions when unnecessary,
- a little bit of renaming and documentation.
This commit is contained in:
Marc Wrobel
2023-12-12 07:42:03 +01:00
committed by GitHub
parent edc825a5f1
commit 4dec3ceca2

View File

@@ -1,54 +1,35 @@
import logging
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from common import http
from common import dates from common import dates
from common import endoflife from common import endoflife
from common import http
PRODUCT = "sles" product = endoflife.Product("sles")
URL = "https://www.suse.com/lifecycle" print(f"::group::{product.name}")
response = http.fetch_url("https://www.suse.com/lifecycle")
soup = BeautifulSoup(response.text, features="html5lib")
products_table = soup.find("tbody", id="productSupportLifecycle")
sles_header_rows = products_table.find_all("tr", class_="row", attrs={"data-productfilter": "SUSE Linux Enterprise Server"})
def strip_version(version_str): # Extract rows' IDs to find related sub-rows with details (normally hidden until a user expands a section)
return version_str.strip("SUSE Linux Enterprise Server ").replace(' SP', '.') for detail_id in [f"detail{row['id']}" for row in sles_header_rows]:
detail_row = products_table.find("tr", id=detail_id)
# There is a table with info about minor releases and after it, optionally, a table with info about modules
minor_versions_table = detail_row.find_all("tbody")[0]
# The first sub-row is a header, the rest contains info about the first release and later minor releases
for row in minor_versions_table.find_all("tr")[1:]:
# For each minor release there is an FCS date, general support end date and LTSS end date
cells = row.find_all("td")
version = cells[0].text.strip("SUSE Linux Enterprise Server ").replace(' SP', '.')
date_str = cells[1].text
def fetch_releases(): try:
response = http.fetch_url(URL) date = dates.parse_date(date_str)
soup = BeautifulSoup(response.text, features="html5lib") product.declare_version(version, date)
products_table = soup.find("tbody", id="productSupportLifecycle") except ValueError:
# Get rows with SLES products logging.info(f"Ignoring {version}: date '{date_str}' could not be parsed")
sles_header_rows = products_table.find_all("tr", class_="row", attrs={"data-productfilter": "SUSE Linux Enterprise Server"})
# Extract rows' IDs to find related sub-rows with details (normally hidden
# until a user expands a section)
sles_detail_ids = [f"detail{row['id']}" for row in sles_header_rows]
versions = {} product.write()
# for all release tables
for detail_id in sles_detail_ids:
detail_row = products_table.find("tr", id=detail_id)
# There is a table with info about minor releases and after it
# optionally a table with info about modules
minor_versions_table = detail_row.find_all("tbody")[0]
# The first sub-row is a header, the rest contains info about the first
# release and later minor releases of a SLES product
minor_version_rows = minor_versions_table.find_all("tr")[1:]
for row in minor_version_rows:
# For each minor release there is an FCS date, general support end
# date and LTSS end date
cells = row.find_all("td")
version = strip_version(cells[0].text)
try:
release_date = dates.parse_date(cells[1].text).strftime("%Y-%m-%d")
versions[version] = release_date
print(f"{version}: {release_date}")
except ValueError as e:
print(f"Ignoring {version}: {e}")
continue
return versions
print(f"::group::{PRODUCT}")
versions = fetch_releases()
endoflife.write_releases(PRODUCT, versions)
print("::endgroup::") print("::endgroup::")