Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanmansum committed Dec 1, 2023
1 parent 2f752be commit e96960b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 21 deletions.
48 changes: 30 additions & 18 deletions src/datastation/common/version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,47 @@ 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


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'
24 changes: 21 additions & 3 deletions src/datastation/datastation_get_component_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit e96960b

Please sign in to comment.