-
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.
- Loading branch information
1 parent
b0fd29f
commit 64b6c9a
Showing
4 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
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,44 @@ | ||
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+)' | ||
|
||
|
||
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] | ||
|
||
|
||
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] | ||
|
||
|
||
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() | ||
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,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() |
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,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 == {} |