[rhel] Refactor script (#245)
Make the script more readable, mostly by: - using the Product class, - a little bit of renaming and documentation.
This commit is contained in:
36
src/rhel.py
36
src/rhel.py
@@ -1,30 +1,30 @@
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
from common import http
|
||||
from common import dates
|
||||
from common import endoflife
|
||||
from common import http
|
||||
|
||||
URL = "https://access.redhat.com/articles/3078"
|
||||
# https://regex101.com/r/877ibq/1
|
||||
regex = r"RHEL (?P<major>\d)(\. ?(?P<minor>\d+))?(( Update (?P<minor2>\d))| GA)?"
|
||||
VERSION_PATTERN = re.compile(r"RHEL (?P<major>\d)(\. ?(?P<minor>\d+))?(( Update (?P<minor2>\d))| GA)?")
|
||||
|
||||
print("::group::rhel")
|
||||
response = http.fetch_url(URL)
|
||||
product = endoflife.Product("redhat")
|
||||
print(f"::group::{product.name}")
|
||||
response = http.fetch_url("https://access.redhat.com/articles/3078")
|
||||
soup = BeautifulSoup(response.text, features="html5lib")
|
||||
|
||||
versions = {}
|
||||
for tr in soup.findAll("tr"):
|
||||
td_list = tr.findAll("td")
|
||||
if len(td_list) > 0:
|
||||
version = td_list[0].get_text()
|
||||
m = re.match(regex, version.strip()).groupdict()
|
||||
version = m["major"]
|
||||
if m["minor"]:
|
||||
version += ".%s" % m["minor"]
|
||||
if m["minor2"]:
|
||||
version += ".%s" % m["minor2"]
|
||||
date = td_list[1].get_text()
|
||||
versions[version] = date
|
||||
print(f"{version}: {date}")
|
||||
if len(td_list) == 0:
|
||||
continue
|
||||
|
||||
endoflife.write_releases('redhat', versions)
|
||||
version_str = td_list[0].get_text().strip()
|
||||
version_match = VERSION_PATTERN.match(version_str).groupdict()
|
||||
version = version_match["major"]
|
||||
version += ("." + version_match["minor"]) if version_match["minor"] else ""
|
||||
version += ("." + version_match["minor2"]) if version_match["minor2"] else ""
|
||||
date = dates.parse_date(td_list[1].get_text())
|
||||
|
||||
product.declare_version(version, date)
|
||||
|
||||
product.write()
|
||||
print("::endgroup::")
|
||||
|
||||
Reference in New Issue
Block a user