Align custom scripts with generic scripts (#445)
Align custom scripts with generic scripts, making them configurable. This has a few advantages: - script code is more unified, - no more hard-coded method names in scripts, which is less error prone and make it easier to rename scripts, - no more hard coded product names in scripts, which is less error prone and make it easier to rename products, - less hard-coded URLs and regexes in scripts, which makes auto-configuration more expressive / updatable, Also added method `endoflife.list_configs_from_argv()` so that it is easier to manipulate scripts arguments.
This commit is contained in:
@@ -5,17 +5,18 @@ from common import dates, endoflife, http, releasedata
|
||||
|
||||
DATE_PATTERN = re.compile(r"\d{4}-\d{2}-\d{2}")
|
||||
|
||||
with releasedata.ProductData("unrealircd") as product_data:
|
||||
response = http.fetch_url("https://www.unrealircd.org/docwiki/index.php?title=History_of_UnrealIRCd_releases&action=raw")
|
||||
wikicode = mwparserfromhell.parse(response.text)
|
||||
for config in endoflife.list_configs_from_argv():
|
||||
with releasedata.ProductData(config.product) as product_data:
|
||||
response = http.fetch_url(config.url)
|
||||
wikicode = mwparserfromhell.parse(response.text)
|
||||
|
||||
for tr in wikicode.ifilter_tags(matches=lambda node: node.tag == "tr"):
|
||||
items = tr.contents.filter_tags(matches=lambda node: node.tag == "td")
|
||||
if len(items) < 2:
|
||||
continue
|
||||
for tr in wikicode.ifilter_tags(matches=lambda node: node.tag == "tr"):
|
||||
items = tr.contents.filter_tags(matches=lambda node: node.tag == "td")
|
||||
if len(items) < 2:
|
||||
continue
|
||||
|
||||
version = items[0].__strip__()
|
||||
date_str = items[1].__strip__()
|
||||
if endoflife.DEFAULT_VERSION_PATTERN.match(version) and DATE_PATTERN.match(date_str):
|
||||
date = dates.parse_date(date_str)
|
||||
product_data.declare_version(version, date)
|
||||
version = items[0].__strip__()
|
||||
date_str = items[1].__strip__()
|
||||
if config.first_match(version) and DATE_PATTERN.match(date_str):
|
||||
date = dates.parse_date(date_str)
|
||||
product_data.declare_version(version, date)
|
||||
|
||||
Reference in New Issue
Block a user