From 55d6d0b0fad0691c04a2bb164e68f026e3a59e4c Mon Sep 17 00:00:00 2001 From: Matyas Selmeci Date: Thu, 3 Oct 2019 12:43:36 -0500 Subject: [PATCH] Move get_local_machine_dver() to utils, where it belongs --- osgbuild/main.py | 20 +------------------- osgbuild/utils.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/osgbuild/main.py b/osgbuild/main.py index 3b21f481..c4aab36a 100644 --- a/osgbuild/main.py +++ b/osgbuild/main.py @@ -22,8 +22,6 @@ import logging from optparse import OptionGroup, OptionParser, OptionValueError import re -import os -import sys import tempfile from .constants import * @@ -691,7 +689,7 @@ def get_buildopts(options, task): else: buildopts['enabled_dvers'] = set(DEFAULT_DVERS) else: - machine_dver = get_local_machine_dver() or FALLBACK_DVER + machine_dver = utils.get_local_machine_dver() or FALLBACK_DVER buildopts['enabled_dvers'] = set([machine_dver]) # Hack: make --mock-config on command line override @@ -758,22 +756,6 @@ def same_or_none(*args): return dver or dist_dver or target_dver or tag_dver -def get_local_machine_dver(): - "Return the distro version (e.g. 'el6', 'el7') of the local machine or None" - try: - redhat_release_contents = utils.slurp('/etc/redhat-release') - except EnvironmentError: # some error reading the file - return - - for rhellike in ['Scientific', 'Red Hat Enterprise', 'CentOS']: - try: - if rhellike in redhat_release_contents: - match = re.search(r'release (\d+)', redhat_release_contents) - return 'el' + match.group(1) - except (TypeError, AttributeError): # empty file or no match - return - - def guess_pkg_dir(start_dir): guess_dir = os.path.realpath(os.path.expanduser(start_dir)) if os.path.basename(guess_dir) == 'osg' or os.path.basename(guess_dir) == 'upstream': diff --git a/osgbuild/utils.py b/osgbuild/utils.py index e102509f..1e03def8 100644 --- a/osgbuild/utils.py +++ b/osgbuild/utils.py @@ -461,3 +461,17 @@ def popd(): raise IndexError("Directory stack empty") +def get_local_machine_dver(): + "Return the distro version (e.g. 'el6', 'el7') of the local machine or None" + try: + redhat_release_contents = slurp("/etc/redhat-release") + except EnvironmentError: # some error reading the file + return + + for rhellike in ["Scientific", "Red Hat Enterprise", "CentOS"]: + try: + if rhellike in redhat_release_contents: + match = re.search(r"release (\d+)", redhat_release_contents) + return "el" + match.group(1) + except (TypeError, AttributeError): # empty file or no match + return