Created
October 17, 2018 14:15
-
-
Save evgeni/18e65f302c44a5dd94251d5b6306f71a to your computer and use it in GitHub Desktop.
0001-move-duplicated-code-to-module_utils.patch
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
From 81fc9955fd1c1410432fcd75c845479882f68e75 Mon Sep 17 00:00:00 2001 | |
From: Evgeni Golov <evgeni@golov.de> | |
Date: Wed, 17 Oct 2018 16:11:28 +0200 | |
Subject: [PATCH] move duplicated code to module_utils | |
--- | |
obal/data/ansible.cfg | 1 + | |
obal/data/module_utils/obal.py | 21 ++++++++++++++++++ | |
obal/data/modules/changelog.py | 12 ++-------- | |
obal/data/modules/rpmspec_changelog_check.py | 23 +------------------- | |
4 files changed, 25 insertions(+), 32 deletions(-) | |
create mode 100644 obal/data/module_utils/obal.py | |
diff --git a/obal/data/ansible.cfg b/obal/data/ansible.cfg | |
index f9b3c26..c3914d0 100644 | |
--- a/obal/data/ansible.cfg | |
+++ b/obal/data/ansible.cfg | |
@@ -8,3 +8,4 @@ stdout_callback = yaml | |
display_skipped_hosts = false | |
roles_path = ./roles/ | |
library = ./modules | |
+module_utils = ./module_utils | |
diff --git a/obal/data/module_utils/obal.py b/obal/data/module_utils/obal.py | |
new file mode 100644 | |
index 0000000..c06cb74 | |
--- /dev/null | |
+++ b/obal/data/module_utils/obal.py | |
@@ -0,0 +1,21 @@ | |
+def get_changelog_evr(specfile): | |
+ evr = subprocess.check_output([ | |
+ 'rpm', | |
+ '--query', | |
+ '--changelog', | |
+ '--specfile', | |
+ specfile | |
+ ]) | |
+ return evr.split("\n")[0].split(" ")[-1] | |
+ | |
+def get_specfile_evr(specfile): | |
+ return subprocess.check_output([ | |
+ 'rpmspec', | |
+ '--query', | |
+ '--queryformat', | |
+ '%{evr}', | |
+ '--undefine', | |
+ 'dist', | |
+ '--srpm', | |
+ specfile | |
+ ]) | |
diff --git a/obal/data/modules/changelog.py b/obal/data/modules/changelog.py | |
index 8490758..a28fe86 100644 | |
--- a/obal/data/modules/changelog.py | |
+++ b/obal/data/modules/changelog.py | |
@@ -5,6 +5,7 @@ import time | |
from contextlib import contextmanager | |
from ansible.module_utils.basic import AnsibleModule | |
+from ansible.module_utils.obal import get_specfile_evr | |
@contextmanager | |
@@ -36,16 +37,7 @@ def main(): | |
changelog = module.params['changelog'] | |
user = subprocess.check_output(['rpmdev-packager']).strip() | |
- evr = subprocess.check_output([ | |
- 'rpmspec', | |
- '--query', | |
- '--queryformat', | |
- '%{evr}', | |
- '--undefine', | |
- 'dist', | |
- '--srpm', | |
- spec | |
- ]) | |
+ evr = get_specfile_evr(spec) | |
with open(spec) as spec_file: | |
lines = spec_file.readlines() | |
diff --git a/obal/data/modules/rpmspec_changelog_check.py b/obal/data/modules/rpmspec_changelog_check.py | |
index d321db7..471db8a 100644 | |
--- a/obal/data/modules/rpmspec_changelog_check.py | |
+++ b/obal/data/modules/rpmspec_changelog_check.py | |
@@ -13,28 +13,7 @@ ANSIBLE_METADATA = { | |
} | |
from ansible.module_utils.basic import AnsibleModule # pylint: disable=C0413 | |
- | |
-def get_changelog_evr(specfile): | |
- evr = subprocess.check_output([ | |
- 'rpm', | |
- '--query', | |
- '--changelog', | |
- '--specfile', | |
- specfile | |
- ]) | |
- return evr.split("\n")[0].split(" ")[-1] | |
- | |
-def get_specfile_evr(specfile): | |
- return subprocess.check_output([ | |
- 'rpmspec', | |
- '--query', | |
- '--queryformat', | |
- '%{evr}', | |
- '--undefine', | |
- 'dist', | |
- '--srpm', | |
- specfile | |
- ]) | |
+from ansible.module_utils.obal import get_changelog_evr, get_specfile_evr | |
def run_module(): | |
-- | |
2.17.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment