Simplify argument parsing (#459)
With the current state of automation scripts, this is not possible anymore to launch script with multiple auto configs.
This commit is contained in:
@@ -2,7 +2,8 @@ import logging
|
||||
import re
|
||||
from datetime import date, datetime, time, timezone
|
||||
|
||||
from common import dates, endoflife, http, releasedata
|
||||
from common import dates, endoflife, http
|
||||
from common.releasedata import ProductData, parse_argv
|
||||
|
||||
"""Detect new models and aggregate EOL data for Samsung Mobile devices.
|
||||
|
||||
@@ -12,64 +13,63 @@ it retains the date and use it as the model's EOL date.
|
||||
|
||||
TODAY = dates.today()
|
||||
|
||||
frontmatter, configs = releasedata.parse_argv()
|
||||
for config in configs:
|
||||
with releasedata.ProductData(config.product) as product_data:
|
||||
frontmatter_release_names = frontmatter.get_release_names()
|
||||
frontmatter, config = parse_argv()
|
||||
with ProductData(config.product) as product_data:
|
||||
frontmatter_release_names = frontmatter.get_release_names()
|
||||
|
||||
# Copy EOL dates from frontmatter to product data
|
||||
for frontmatter_release in frontmatter.get_releases():
|
||||
eol = frontmatter_release.get("eol")
|
||||
eol = datetime.combine(eol, time.min, tzinfo=timezone.utc) if isinstance(eol, date) else eol
|
||||
# Copy EOL dates from frontmatter to product data
|
||||
for frontmatter_release in frontmatter.get_releases():
|
||||
eol = frontmatter_release.get("eol")
|
||||
eol = datetime.combine(eol, time.min, tzinfo=timezone.utc) if isinstance(eol, date) else eol
|
||||
|
||||
release = product_data.get_release(frontmatter_release.get("releaseCycle"))
|
||||
release.set_eol(eol)
|
||||
release = product_data.get_release(frontmatter_release.get("releaseCycle"))
|
||||
release.set_eol(eol)
|
||||
|
||||
|
||||
html = http.fetch_html(config.url)
|
||||
html = http.fetch_html(config.url)
|
||||
|
||||
sections = config.data.get("sections", {})
|
||||
for update_cadence, title in sections.items():
|
||||
models_list = html.find(string=lambda text, search=title: search in text if text else False).find_next("ul")
|
||||
sections = config.data.get("sections", {})
|
||||
for update_cadence, title in sections.items():
|
||||
models_list = html.find(string=lambda text, search=title: search in text if text else False).find_next("ul")
|
||||
|
||||
for item in models_list.find_all("li"):
|
||||
models = item.text.replace("Enterprise Models:", "")
|
||||
logging.info(f"Found {models} for {update_cadence} security updates")
|
||||
for item in models_list.find_all("li"):
|
||||
models = item.text.replace("Enterprise Models:", "")
|
||||
logging.info(f"Found {models} for {update_cadence} security updates")
|
||||
|
||||
for model in re.split(r',\s*', models):
|
||||
name = endoflife.to_identifier(model)
|
||||
if config.is_excluded(name):
|
||||
logging.debug(f"Ignoring model '{name}', excluded by configuration")
|
||||
continue
|
||||
for model in re.split(r',\s*', models):
|
||||
name = endoflife.to_identifier(model)
|
||||
if config.is_excluded(name):
|
||||
logging.debug(f"Ignoring model '{name}', excluded by configuration")
|
||||
continue
|
||||
|
||||
release = product_data.get_release(name)
|
||||
release.set_label(model.strip())
|
||||
release = product_data.get_release(name)
|
||||
release.set_label(model.strip())
|
||||
|
||||
if name in frontmatter_release_names:
|
||||
frontmatter_release_names.remove(name)
|
||||
current_eol = release.get_eol()
|
||||
if current_eol is True or (isinstance(current_eol, datetime) and current_eol <= TODAY):
|
||||
logging.info(f"Known model {name} is incorrectly marked as EOL, updating eol")
|
||||
release.set_eol(False)
|
||||
else:
|
||||
logging.debug(f"Known model {name} is not EOL, keeping eol as {current_eol}")
|
||||
|
||||
else:
|
||||
logging.debug(f"Found new model {name}")
|
||||
if name in frontmatter_release_names:
|
||||
frontmatter_release_names.remove(name)
|
||||
current_eol = release.get_eol()
|
||||
if current_eol is True or (isinstance(current_eol, datetime) and current_eol <= TODAY):
|
||||
logging.info(f"Known model {name} is incorrectly marked as EOL, updating eol")
|
||||
release.set_eol(False)
|
||||
else:
|
||||
logging.debug(f"Known model {name} is not EOL, keeping eol as {current_eol}")
|
||||
|
||||
# the remaining models in frontmatter_release_names are not listed anymore on the Samsung page => they are EOL
|
||||
for eol_model_name in frontmatter_release_names:
|
||||
release = product_data.get_release(eol_model_name)
|
||||
current_eol = release.get_eol()
|
||||
if config.is_excluded(eol_model_name):
|
||||
logging.debug(f"Skipping model {eol_model_name}, excluded by configuration")
|
||||
elif current_eol is False:
|
||||
logging.info(f"Model {eol_model_name} is not EOL, setting eol")
|
||||
release.set_eol(TODAY)
|
||||
elif isinstance(current_eol, datetime):
|
||||
if current_eol > TODAY:
|
||||
logging.info(f"Model {eol_model_name} is not marked as EOL, setting eol as {TODAY}")
|
||||
release.set_eol(TODAY)
|
||||
else:
|
||||
logging.debug(f"Model {eol_model_name} is already EOL, keeping eol as {current_eol}")
|
||||
logging.debug(f"Found new model {name}")
|
||||
release.set_eol(False)
|
||||
|
||||
# the remaining models in frontmatter_release_names are not listed anymore on the Samsung page => they are EOL
|
||||
for eol_model_name in frontmatter_release_names:
|
||||
release = product_data.get_release(eol_model_name)
|
||||
current_eol = release.get_eol()
|
||||
if config.is_excluded(eol_model_name):
|
||||
logging.debug(f"Skipping model {eol_model_name}, excluded by configuration")
|
||||
elif current_eol is False:
|
||||
logging.info(f"Model {eol_model_name} is not EOL, setting eol")
|
||||
release.set_eol(TODAY)
|
||||
elif isinstance(current_eol, datetime):
|
||||
if current_eol > TODAY:
|
||||
logging.info(f"Model {eol_model_name} is not marked as EOL, setting eol as {TODAY}")
|
||||
release.set_eol(TODAY)
|
||||
else:
|
||||
logging.debug(f"Model {eol_model_name} is already EOL, keeping eol as {current_eol}")
|
||||
|
||||
Reference in New Issue
Block a user