[palo-alto-network] Refactor script (#238)

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-11 22:21:14 +01:00
committed by GitHub
parent 22f9e2d4f1
commit 9d056bc41b

View File

@@ -1,54 +1,41 @@
import datetime
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
URL = "https://www.paloaltonetworks.com/services/support/end-of-life-announcements/end-of-life-summary" IDENTIFIERS_BY_PRODUCT = {
ID_MAPPING = { "pan-os": "pan-os-panorama",
"pan-os-panorama": "pan-os", "pan-gp": "globalprotect",
"globalprotect": "pan-gp", "pan-cortex-xdr": "traps-esm-and-cortex",
"traps-esm-and-cortex": "pan-cortex-xdr",
} }
# all products are on the same page, it's faster to fetch it only once
print("::group::palo-alto-networks")
response = http.fetch_url("https://www.paloaltonetworks.com/services/support/end-of-life-announcements/end-of-life-summary")
soup = BeautifulSoup(response.text, features="html5lib")
print("::endgroup::")
def update_releases(html_identifier, file): for product_name, identifier in IDENTIFIERS_BY_PRODUCT.items():
versions = {} print(f"::group::{product_name}")
product = endoflife.Product(product_name)
print(f"::group::{html_identifier}") table = soup.find(id=identifier)
response = http.fetch_url(URL)
soup = BeautifulSoup(response.text, features="html5lib")
table = soup.find(id=html_identifier)
for tr in table.findAll("tr")[3:]: for tr in table.findAll("tr")[3:]:
td_list = tr.findAll("td") td_list = tr.findAll("td")
version = ( if len(td_list) <= 1:
td_list[0].get_text().strip().lower().replace(" ", "-").replace("*", "")
)
if file == "pan-xdr":
if "xdr" not in version:
continue continue
version = td_list[0].get_text().strip().lower().replace(" ", "-").replace("*", "")
version = version.removesuffix("-(cortex-xdr-agent)") version = version.removesuffix("-(cortex-xdr-agent)")
version = version.removesuffix("-(vm-series-only)") version = version.removesuffix("-(vm-series-only)")
version = version.removesuffix("-(panorama-only)") version = version.removesuffix("-(panorama-only)")
if len(td_list) > 1 and version != "":
# Date formats differ between different products
try:
month, date, year = td_list[1].get_text().split("/")
abs_date = f"{year}-{month:0>2}-{date:0>2}"
except ValueError:
# A few dates have 1st, 2nd, 4th etc. Fix that:
d = td_list[1].get_text()
d = re.sub(r'(\w+) (\d{1,2})(?:\w{2}), (\d{4})', r'\1 \2, \3', d)
date = datetime.datetime.strptime(d, "%B %d, %Y")
abs_date = date.strftime("%Y-%m-%d")
versions[version] = abs_date # A few dates have 1st, 2nd, 4th... Remove it.
print(f"{version}: {abs_date}") date_str = re.sub(r'(\w+) (\d{1,2})\w{2}, (\d{4})', r'\1 \2, \3', td_list[1].get_text())
date = dates.parse_date(date_str)
endoflife.write_releases(file, versions) product.declare_version(version, date)
product.write()
print("::endgroup::") print("::endgroup::")
for html_id in ID_MAPPING:
update_releases(html_id, ID_MAPPING[html_id])