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:
51
src/veeam.py
51
src/veeam.py
@@ -1,7 +1,8 @@
|
||||
import logging
|
||||
import re
|
||||
|
||||
from common import dates, http, releasedata
|
||||
from common import dates, http
|
||||
from common.releasedata import ProductData, config_from_argv
|
||||
|
||||
"""Fetches Veeam products versions from https://www.veeam.com.
|
||||
|
||||
@@ -9,31 +10,31 @@ This script takes a single argument which is the url of the versions page on htt
|
||||
such as `https://www.veeam.com/kb2680`.
|
||||
"""
|
||||
|
||||
for config in releasedata.list_configs_from_argv():
|
||||
with releasedata.ProductData(config.product) as product_data:
|
||||
html = http.fetch_html(config.url)
|
||||
config = config_from_argv()
|
||||
with ProductData(config.product) as product_data:
|
||||
html = http.fetch_html(config.url)
|
||||
|
||||
version_column = config.data.get("version_column", "Build Number").lower()
|
||||
date_column = config.data.get("date_column", "Release Date").lower()
|
||||
for table in html.find_all("table"):
|
||||
headers = [header.get_text().strip().lower() for header in table.find("tr").find_all("td")]
|
||||
if version_column not in headers or date_column not in headers:
|
||||
logging.warning("Skipping table with headers %s as it does not contains '%s' or '%s'",
|
||||
headers, version_column, date_column)
|
||||
version_column = config.data.get("version_column", "Build Number").lower()
|
||||
date_column = config.data.get("date_column", "Release Date").lower()
|
||||
for table in html.find_all("table"):
|
||||
headers = [header.get_text().strip().lower() for header in table.find("tr").find_all("td")]
|
||||
if version_column not in headers or date_column not in headers:
|
||||
logging.warning("Skipping table with headers %s as it does not contains '%s' or '%s'",
|
||||
headers, version_column, date_column)
|
||||
continue
|
||||
|
||||
version_index = headers.index(version_column)
|
||||
date_index = headers.index(date_column)
|
||||
for row in table.find_all("tr")[1:]:
|
||||
cells = row.find_all("td")
|
||||
if len(cells) <= max(version_index, date_index):
|
||||
continue
|
||||
|
||||
version_index = headers.index(version_column)
|
||||
date_index = headers.index(date_column)
|
||||
for row in table.find_all("tr")[1:]:
|
||||
cells = row.find_all("td")
|
||||
if len(cells) <= max(version_index, date_index):
|
||||
continue
|
||||
date_str = cells[date_index].get_text().strip()
|
||||
if not date_str or date_str == "-":
|
||||
continue
|
||||
|
||||
date_str = cells[date_index].get_text().strip()
|
||||
if not date_str or date_str == "-":
|
||||
continue
|
||||
|
||||
# whitespaces in version numbers are replaced with dashes
|
||||
version = re.sub(r'\s+', "-", cells[version_index].get_text().strip())
|
||||
date = dates.parse_date(date_str)
|
||||
product_data.declare_version(version, date)
|
||||
# whitespaces in version numbers are replaced with dashes
|
||||
version = re.sub(r'\s+', "-", cells[version_index].get_text().strip())
|
||||
date = dates.parse_date(date_str)
|
||||
product_data.declare_version(version, date)
|
||||
|
||||
Reference in New Issue
Block a user