Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanmansum committed Nov 29, 2023
1 parent 80354d8 commit 2f752be
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 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.35.0"
version = "0.36.0"
description = "Command line utilities for Data Station application management"
authors = ["DANS-KNAW"]
packages = [
Expand Down
12 changes: 8 additions & 4 deletions src/datastation/common/version_info.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os
from re import match

Expand All @@ -6,7 +7,7 @@ def rpm_qa():
return os.popen('rpm -qa')

Check warning on line 7 in src/datastation/common/version_info.py

View check run for this annotation

Codecov / codecov/patch

src/datastation/common/version_info.py#L7

Added line #L7 was not covered by tests


evr_pattern = r'(?P<name>.*?)-(?P<version>\d+\.\d+\.\d+)-(?P<release>\d+)'
evr_pattern = r'(?P<name>.*?)-(?P<version>\d+\.\d+\.\d+)-(?P<release>[^\.]+)\.(?P<arch>.+)'
payara_version_pattern = r'Thank you for downloading Payara Server (.*).'


Expand All @@ -15,10 +16,15 @@ def get_rpm_versions(prefix):
rpm_versions = {}
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')
rpm_versions[module] = version
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}'

return rpm_versions

Expand All @@ -40,8 +46,6 @@ def get_dataverse_build_number(dataverse_application_path):

def get_payara_version(payara_application_path):
with open(os.path.join(payara_application_path, 'README.txt'), 'r') as f:
# Find first line that matches pattern
line = next((line for line in f if match(payara_version_pattern, line)), None)
# get subgroup 1 of the match
payara_version = match(payara_version_pattern, line).group(1)
return payara_version
20 changes: 18 additions & 2 deletions src/tests/test_version_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datastation.common.version_info import get_rpm_versions, get_dataverse_version, get_payara_version


def test_some_modules_with_matching_prefix_found():
def test_get_rpm_modules_should_filter_out_packages_with_no_matching_prefix():
with patch('datastation.common.version_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',
Expand All @@ -18,13 +18,29 @@ def test_some_modules_with_matching_prefix_found():
}


def test_no_matching_modules_found():
def test_get_rpm_modules_should_return_empty_dictionary_if_no_packages_matched_prefix():
with patch('datastation.common.version_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 == {}


def test_get_rpm_modules_should_accept_non_digits_in_release_part_of_evr():
with patch('datastation.common.version_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-SNAPSHOT20231005095642.noarch',
'python3-rpm-generators-5-8.el8.noarch',
'dans.knaw.nl-dd-verify-dataset-0.10.0-1.noarch',
'dans.knaw.nl-dd-verify-dataset-0.10.0-1.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-SNAPSHOT20231005095642',
'dans.knaw.nl-dd-verify-dataset': '0.10.0'
}


def test_get_dataverse_version():
with patch('builtins.open') as mock_open:
mock_open.return_value.__enter__.return_value = ['dataverse.version=5.0.1\n']
Expand Down

0 comments on commit 2f752be

Please sign in to comment.