[redhat-satellite] Refactor script (#244)
Make the script more readable, mostly by: - using the Product class, - a little bit of renaming and documentation.
This commit is contained in:
@@ -1,36 +1,31 @@
|
|||||||
import re
|
import re
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from common import http
|
from common import dates
|
||||||
from common import endoflife
|
from common import endoflife
|
||||||
|
from common import http
|
||||||
|
|
||||||
"""Fetch versions with their dates from access.redhat.com.
|
"""Fetches Satellite versions from access.redhat.com.
|
||||||
|
|
||||||
A few of the older versions, such as 'Satellite 6.1 GA Release (Build 6.1.1)',
|
A few of the older versions, such as 'Satellite 6.1 GA Release (Build 6.1.1)', were ignored because too hard to parse."""
|
||||||
were ignored because too hard to parse.
|
|
||||||
"""
|
|
||||||
|
|
||||||
URL = "https://access.redhat.com/articles/1365633"
|
|
||||||
# https://regex101.com/r/m8aWXG/1
|
# https://regex101.com/r/m8aWXG/1
|
||||||
regex = r"^Satellite (?P<version>\d+\.\d+\.\d+([.-]\d+)?) ([Uu]pdate|[Rr]elease)$"
|
VERSION_PATTERN = re.compile(r"^Satellite (?P<version>\d+\.\d+\.\d+([.-]\d+)?) ([Uu]pdate|[Rr]elease)$")
|
||||||
|
|
||||||
print("::group::redhat-satellite")
|
product = endoflife.Product("redhat-satellite")
|
||||||
response = http.fetch_url(URL)
|
print(f"::group::{product.name}")
|
||||||
|
response = http.fetch_url("https://access.redhat.com/articles/1365633")
|
||||||
soup = BeautifulSoup(response.text, features="html5lib")
|
soup = BeautifulSoup(response.text, features="html5lib")
|
||||||
|
|
||||||
versions = {}
|
|
||||||
for table in soup.findAll("tbody"):
|
for table in soup.findAll("tbody"):
|
||||||
for tr in table.findAll("tr"):
|
for tr in table.findAll("tr"):
|
||||||
td_list = tr.findAll("td")
|
td_list = tr.findAll("td")
|
||||||
|
|
||||||
# Versions x.y GA are transformed to x.y.0
|
version_str = td_list[0].get_text().replace(' GA', '.0').strip() # x.y GA => x.y.0
|
||||||
version = td_list[0].get_text().replace(' GA', '.0').strip()
|
version_match = VERSION_PATTERN.match(version_str)
|
||||||
m = re.match(regex, version)
|
if version_match:
|
||||||
if m:
|
version = version_match["version"].replace('-', '.') # a.b.c-d => a.b.c.d
|
||||||
# Versions a.b.c-d are transformed to a.b.c.d
|
date = dates.parse_date(td_list[1].get_text().strip())
|
||||||
version = m["version"].replace('-', '.')
|
product.declare_version(version, date)
|
||||||
date = td_list[1].get_text().strip()
|
|
||||||
versions[version] = date
|
|
||||||
print(f"{version}: {date}")
|
|
||||||
|
|
||||||
endoflife.write_releases('redhat-satellite', versions)
|
product.write()
|
||||||
print("::endgroup::")
|
print("::endgroup::")
|
||||||
|
|||||||
Reference in New Issue
Block a user