From e96960bc31361421242de05a51d8d3bf72be04a8 Mon Sep 17 00:00:00 2001 From: Jan van Mansum Date: Fri, 1 Dec 2023 12:13:23 +0100 Subject: [PATCH] WIP --- src/datastation/common/version_info.py | 48 ++++++++++++------- .../datastation_get_component_versions.py | 24 ++++++++-- 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/datastation/common/version_info.py b/src/datastation/common/version_info.py index 303df53..c6c7b9e 100644 --- a/src/datastation/common/version_info.py +++ b/src/datastation/common/version_info.py @@ -17,14 +17,17 @@ def get_rpm_versions(prefix): for line in rpm_qa(): if line.startswith(prefix): logging.debug(f'Found RPM matching prefix {prefix}: {line}') - evr = match(evr_pattern, line) - version = evr.group('version') - module = evr.group('name') - release = evr.group('release') - # Adding the release part of the EVR is not very informative for DANS modules, - # because it is always 1 for releases, except for SNAPSHOTs, in which case it is - # important to know the exact SNAPSHOT version. - rpm_versions[module] = f'{version}-{release}' if release != '1' else f'{version}' + try: + evr = match(evr_pattern, line) + version = evr.group('version') + module = evr.group('name') + release = evr.group('release') + # Adding the release part of the EVR is not very informative for DANS modules, + # because it is always 1 for releases, except for SNAPSHOTs, in which case it is + # important to know the exact SNAPSHOT version. + rpm_versions[module] = f'{version}-{release}' if release != '1' else f'{version}' + except: + rpm_versions[module] = 'ERROR' return rpm_versions @@ -32,20 +35,29 @@ def get_rpm_versions(prefix): def get_dataverse_version(dataverse_application_path): with open(os.path.join(dataverse_application_path, 'WEB-INF', 'classes', 'META-INF', 'microprofile-config.properties'), 'r') as f: - for line in f: - if 'dataverse.version' in line: - return (line.split('=')[1]).strip() + try: + for line in f: + if 'dataverse.version' in line: + return (line.split('=')[1]).strip() + except: + return 'ERROR' def get_dataverse_build_number(dataverse_application_path): with open(os.path.join(dataverse_application_path, 'WEB-INF', 'classes', 'BuildNumber.properties'), 'r') as f: - for line in f: - if 'build.number' in line: - return (line.split('=')[1]).strip() + try: + for line in f: + if 'build.number' in line: + return (line.split('=')[1]).strip() + except: + return 'ERROR' def get_payara_version(payara_application_path): - with open(os.path.join(payara_application_path, 'README.txt'), 'r') as f: - line = next((line for line in f if match(payara_version_pattern, line)), None) - payara_version = match(payara_version_pattern, line).group(1) - return payara_version + try: + with open(os.path.join(payara_application_path, 'README.txt'), 'r') as f: + line = next((line for line in f if match(payara_version_pattern, line)), None) + payara_version = match(payara_version_pattern, line).group(1) + return payara_version + except: + return 'ERROR' diff --git a/src/datastation/datastation_get_component_versions.py b/src/datastation/datastation_get_component_versions.py index d4d0c79..229cb9f 100644 --- a/src/datastation/datastation_get_component_versions.py +++ b/src/datastation/datastation_get_component_versions.py @@ -9,6 +9,21 @@ get_payara_version +def get_config_version_info(config): + if 'version_info' in config: + return config['version_info'] + else: + default_version_info = { + 'dans_rpm_module_prefix': 'dans.knaw.nl-', + 'dataverse_application_path': '/var/lib/payara5/glassfish/domains/domain1/applications/dataverse/', + 'payara_install_path': '/usr/local/payara5' + } + rich.print('WARNING: No version_info section in config file. Using default values.') + rich.print('To get rid of this warning, add a version_info section to your config file:') + rich.print(default_version_info); + return default_version_info + + def main(): config = init() @@ -17,9 +32,11 @@ def main(): parser.add_argument('--json', dest='json', action='store_true', help='Output as JSON') args = parser.parse_args() - components = get_rpm_versions(config['version_info']['dans_rpm_module_prefix']) - dataverse_version = get_dataverse_version(config['version_info']['dataverse_application_path']) - dataverse_build_number = get_dataverse_build_number(config['version_info']['dataverse_application_path']) + version_info = get_config_version_info(config) + + components = get_rpm_versions(version_info['dans_rpm_module_prefix']) + dataverse_version = get_dataverse_version(version_info['dataverse_application_path']) + dataverse_build_number = get_dataverse_build_number(version_info['dataverse_application_path']) components['dataverse'] = f'{dataverse_version} build {dataverse_build_number}' payara_version = get_payara_version(config['version_info']['payara_install_path']) components['payara'] = payara_version @@ -31,6 +48,7 @@ def main(): table = Table(title="Data Station Component Versions") table.add_column("Component") table.add_column("Version") + components.sort() for component in components: table.add_row(component, components[component]) console = Console()