-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated poetry lockfile * corrected import of Console * Test for get_dataverse_version * Test for get_dataverse_version * Correct calls in main * get_payara_version * print as JSON * Renamed command
- Loading branch information
1 parent
b0fd29f
commit 80354d8
Showing
6 changed files
with
467 additions
and
280 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import os | ||
from re import match | ||
|
||
|
||
def rpm_qa(): | ||
return os.popen('rpm -qa') | ||
|
||
|
||
evr_pattern = r'(?P<name>.*?)-(?P<version>\d+\.\d+\.\d+)-(?P<release>\d+)' | ||
payara_version_pattern = r'Thank you for downloading Payara Server (.*).' | ||
|
||
|
||
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', | ||
'microprofile-config.properties'), 'r') as f: | ||
for line in f: | ||
if 'dataverse.version' in line: | ||
return (line.split('=')[1]).strip() | ||
|
||
|
||
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() | ||
|
||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import argparse | ||
|
||
import rich | ||
from rich.console import Console | ||
from rich.table import Table | ||
|
||
from datastation.common.config import init | ||
from datastation.common.version_info import get_rpm_versions, get_dataverse_version, get_dataverse_build_number, \ | ||
get_payara_version | ||
|
||
|
||
def main(): | ||
config = init() | ||
|
||
parser = argparse.ArgumentParser( | ||
description='Gets the version of all Data Station components in this installation.') | ||
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']) | ||
components['dataverse'] = f'{dataverse_version} build {dataverse_build_number}' | ||
payara_version = get_payara_version(config['version_info']['payara_install_path']) | ||
components['payara'] = payara_version | ||
|
||
if args.json: | ||
rich.print(components) | ||
return | ||
else: | ||
table = Table(title="Data Station Component Versions") | ||
table.add_column("Component") | ||
table.add_column("Version") | ||
for component in components: | ||
table.add_row(component, components[component]) | ||
console = Console() | ||
console.print(table) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from unittest.mock import patch | ||
|
||
from datastation.common.version_info import get_rpm_versions, get_dataverse_version, get_payara_version | ||
|
||
|
||
def test_some_modules_with_matching_prefix_found(): | ||
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', | ||
'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_matching_modules_found(): | ||
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_dataverse_version(): | ||
with patch('builtins.open') as mock_open: | ||
mock_open.return_value.__enter__.return_value = ['dataverse.version=5.0.1\n'] | ||
version = get_dataverse_version('/opt/dv/application') | ||
assert version == '5.0.1' | ||
|
||
|
||
def test_get_payara_version(): | ||
with patch('builtins.open') as mock_open: | ||
mock_open.return_value.__enter__.return_value = ['Thank you for downloading Payara Server 5.2021.1!\n'] | ||
version = get_payara_version('/opt/payara') | ||
assert version == '5.2021.1' |