Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanmansum committed Nov 27, 2023
1 parent b0fd29f commit 64b6c9a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dans-datastation-tools"
version = "0.34.0"
version = "0.35.0"
description = "Command line utilities for Data Station application management"
authors = ["DANS-KNAW"]
packages = [
Expand Down Expand Up @@ -49,3 +49,4 @@ dv-user-import = "datastation.dv_user_import:main"
dv-notifications-cleanup="datastation.dv_notifications_cleanup:main"
ingest-flow = "datastation.ingest_flow:main"
dv-dataverse-root-collect-storage-usage = "datastation.dv_dataverse_root_collect_storage_usage:main"
datastation-module-versions = "datastation.datastation_module_versions:main"
44 changes: 44 additions & 0 deletions src/datastation/common/module_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
from re import match


def rpm_qa():
return os.popen('rpm -qa')

Check warning on line 6 in src/datastation/common/module_info.py

View check run for this annotation

Codecov / codecov/patch

src/datastation/common/module_info.py#L6

Added line #L6 was not covered by tests


evr_pattern = r'(?P<name>.*?)-(?P<version>\d+\.\d+\.\d+)-(?P<release>\d+)'


def get_rpm_versions(prefix):
"""Get the versions of the RPMs installed on the system."""
rpm_versions = {}
for line in rpm_qa():
if line.startswith(prefix):
evr = match(evr_pattern, line)
version = evr.group('version')
module = evr.group('name')
rpm_versions[module] = version

return rpm_versions


def get_dataverse_version(dataverse_application_path):
with open(os.path.join(dataverse_application_path, 'WEB-INF', 'classes', 'META-INF',

Check warning on line 26 in src/datastation/common/module_info.py

View check run for this annotation

Codecov / codecov/patch

src/datastation/common/module_info.py#L26

Added line #L26 was not covered by tests
'microprofile-config.properties'), 'r') as f:
for line in f:
if 'dataverse.version' in line:
return line.split('"')[1]

Check warning on line 30 in src/datastation/common/module_info.py

View check run for this annotation

Codecov / codecov/patch

src/datastation/common/module_info.py#L28-L30

Added lines #L28 - L30 were not covered by tests


def get_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]

Check warning on line 37 in src/datastation/common/module_info.py

View check run for this annotation

Codecov / codecov/patch

src/datastation/common/module_info.py#L34-L37

Added lines #L34 - L37 were not covered by tests


def get_payara_version(payara_application_path):
with open(os.path.join(payara_application_path, 'glassfish', 'modules', 'org', 'glassfish', 'main', 'glassfish-api.jar'), 'r') as f:
for line in f:
if 'Implementation-Version' in line:
return line.split(' ')[1].strip()

Check warning on line 44 in src/datastation/common/module_info.py

View check run for this annotation

Codecov / codecov/patch

src/datastation/common/module_info.py#L41-L44

Added lines #L41 - L44 were not covered by tests
14 changes: 14 additions & 0 deletions src/datastation/datastation_module_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os

import rich

from datastation.common.module_info import get_rpm_versions


def main():
rpm_modules = get_rpm_versions('dans.knaw.nl-')
rich.print(rpm_modules)


if __name__ == '__main__':
main()
27 changes: 27 additions & 0 deletions src/tests/test_module_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from unittest.mock import patch

from datastation.common.module_info import get_rpm_versions


def test_only_modules_with_matching_prefix_found():
# Mock Rpm.qa
with patch('datastation.common.module_info.rpm_qa') as mock_qa:
mock_qa.return_value = ['dans.knaw.nl-dd-vault-metadata-2.2.0-1.noarch',
'dans.knaw.nl-dans-schema-0.10.0-1.noarch',
'python3-rpm-generators-5-8.el8.noarch',
'dans.knaw.nl-dd-verify-dataset-0.10.0-1.noarch',
]
versions = get_rpm_versions('dans.knaw.nl-')
assert versions == {
'dans.knaw.nl-dd-vault-metadata': '2.2.0',
'dans.knaw.nl-dans-schema': '0.10.0',
'dans.knaw.nl-dd-verify-dataset': '0.10.0'
}


def test_no_modules_found():
# Mock Rpm.qa
with patch('datastation.common.module_info.rpm_qa') as mock_qa:
mock_qa.return_value = ['python3-rpm-generators-5-8.el8.noarch']
versions = get_rpm_versions('dans.knaw.nl-')
assert versions == {}

0 comments on commit 64b6c9a

Please sign in to comment.