Skip to content

Commit

Permalink
Move get_local_machine_dver() to utils, where it belongs
Browse files Browse the repository at this point in the history
  • Loading branch information
matyasselmeci committed Oct 3, 2019
1 parent ab30c6d commit 55d6d0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
20 changes: 1 addition & 19 deletions osgbuild/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import logging
from optparse import OptionGroup, OptionParser, OptionValueError
import re
import os
import sys
import tempfile

from .constants import *
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand Down
14 changes: 14 additions & 0 deletions osgbuild/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 55d6d0b

Please sign in to comment.