summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pym/portage/__init__.py68
-rw-r--r--pym/portage/package/ebuild/doebuild.py23
-rw-r--r--pym/portage/util/ExtractKernelVersion.py77
3 files changed, 95 insertions, 73 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 6c872af9a..c459c1b31 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -121,6 +121,7 @@ try:
'writemsg_stdout,write_atomic',
'portage.util.digraph:digraph',
'portage.util.env_update:env_update',
+ 'portage.util.ExtractKernelVersion:ExtractKernelVersion',
'portage.util.listdir:cacheddir,listdir',
'portage.versions',
'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,' + \
@@ -533,73 +534,6 @@ def abssymlink(symlink):
mylink=mydir+"/"+mylink
return os.path.normpath(mylink)
-def ExtractKernelVersion(base_dir):
- """
- Try to figure out what kernel version we are running
- @param base_dir: Path to sources (usually /usr/src/linux)
- @type base_dir: string
- @rtype: tuple( version[string], error[string])
- @returns:
- 1. tuple( version[string], error[string])
- Either version or error is populated (but never both)
-
- """
- lines = []
- pathname = os.path.join(base_dir, 'Makefile')
- try:
- f = codecs.open(_unicode_encode(pathname,
- encoding=_encodings['fs'], errors='strict'), mode='r',
- encoding=_encodings['content'], errors='replace')
- except OSError as details:
- return (None, str(details))
- except IOError as details:
- return (None, str(details))
-
- try:
- for i in range(4):
- lines.append(f.readline())
- except OSError as details:
- return (None, str(details))
- except IOError as details:
- return (None, str(details))
-
- lines = [l.strip() for l in lines]
-
- version = ''
-
- #XXX: The following code relies on the ordering of vars within the Makefile
- for line in lines:
- # split on the '=' then remove annoying whitespace
- items = line.split("=")
- items = [i.strip() for i in items]
- if items[0] == 'VERSION' or \
- items[0] == 'PATCHLEVEL':
- version += items[1]
- version += "."
- elif items[0] == 'SUBLEVEL':
- version += items[1]
- elif items[0] == 'EXTRAVERSION' and \
- items[-1] != items[0]:
- version += items[1]
-
- # Grab a list of files named localversion* and sort them
- localversions = os.listdir(base_dir)
- for x in range(len(localversions)-1,-1,-1):
- if localversions[x][:12] != "localversion":
- del localversions[x]
- localversions.sort()
-
- # Append the contents of each to the version string, stripping ALL whitespace
- for lv in localversions:
- version += "".join( " ".join( grabfile( base_dir+ "/" + lv ) ).split() )
-
- # Check the .config for a CONFIG_LOCALVERSION and append that too, also stripping whitespace
- kernelconfig = getconfig(base_dir+"/.config")
- if kernelconfig and "CONFIG_LOCALVERSION" in kernelconfig:
- version += "".join(kernelconfig["CONFIG_LOCALVERSION"].split())
-
- return (version,None)
-
_doebuild_manifest_exempt_depend = 0
def digestgen(myarchives=None, mysettings=None,
diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py
index 3ac4581b9..edeb5aaa6 100644
--- a/pym/portage/package/ebuild/doebuild.py
+++ b/pym/portage/package/ebuild/doebuild.py
@@ -21,23 +21,34 @@ import time
import portage
portage.proxy.lazyimport.lazyimport(globals(),
'portage.package.ebuild.config:check_config_instance',
+ 'portage.util.ExtractKernelVersion:ExtractKernelVersion'
)
-from portage import auxdbkeys, bsd_chflags, dep_check, digestcheck, digestgen, eapi_is_supported, ExtractKernelVersion, merge, os, selinux, StringIO, unmerge, _encodings, _parse_eapi_ebuild_head, _os_merge, _shell_quote, _split_ebuild_name_glep55, _unicode_decode, _unicode_encode
-from portage.const import EBUILD_SH_ENV_FILE, EBUILD_SH_BINARY, INVALID_ENV_FILE, MISC_SH_BINARY
-from portage.data import portage_gid, portage_uid, secpass, uid, userpriv_groups
+from portage import auxdbkeys, bsd_chflags, dep_check, digestcheck, \
+ digestgen, eapi_is_supported, merge, os, selinux, StringIO, \
+ unmerge, _encodings, _parse_eapi_ebuild_head, _os_merge, \
+ _shell_quote, _split_ebuild_name_glep55, _unicode_decode, _unicode_encode
+from portage.const import EBUILD_SH_ENV_FILE, EBUILD_SH_BINARY, \
+ INVALID_ENV_FILE, MISC_SH_BINARY
+from portage.data import portage_gid, portage_uid, secpass, \
+ uid, userpriv_groups
from portage.dbapi.virtual import fakedbapi
-from portage.dep import Atom, paren_enclose, paren_normalize, paren_reduce, use_reduce
+from portage.dep import Atom, paren_enclose, paren_normalize, \
+ paren_reduce, use_reduce
from portage.elog import elog_process
from portage.elog.messages import eerror, eqawarn
-from portage.exception import DigestException, FileNotFound, IncorrectParameter, InvalidAtom, InvalidDependString, PermissionDenied, UnsupportedAPIException
+from portage.exception import DigestException, FileNotFound, \
+ IncorrectParameter, InvalidAtom, InvalidDependString, PermissionDenied, \
+ UnsupportedAPIException
from portage.localization import _
from portage.manifest import Manifest
from portage.output import style_to_ansi_code
from portage.package.ebuild.fetch import fetch
from portage.package.ebuild.prepare_build_dirs import prepare_build_dirs
from portage.package.ebuild._pty import _create_pty_or_pipe
-from portage.util import apply_recursive_permissions, apply_secpass_permissions, noiselimit, normalize_path, writemsg, writemsg_stdout, write_atomic
+from portage.util import apply_recursive_permissions, \
+ apply_secpass_permissions, noiselimit, normalize_path, \
+ writemsg, writemsg_stdout, write_atomic
from portage.versions import _pkgsplit
def doebuild_environment(myebuild, mydo, myroot, mysettings,
diff --git a/pym/portage/util/ExtractKernelVersion.py b/pym/portage/util/ExtractKernelVersion.py
new file mode 100644
index 000000000..9e6433b28
--- /dev/null
+++ b/pym/portage/util/ExtractKernelVersion.py
@@ -0,0 +1,77 @@
+# Copyright 2010 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+__all__ = ['ExtractKernelVersion']
+
+import codecs
+
+from portage import os, _encodings, _unicode_encode
+from portage.util import getconfig, grabfile
+
+def ExtractKernelVersion(base_dir):
+ """
+ Try to figure out what kernel version we are running
+ @param base_dir: Path to sources (usually /usr/src/linux)
+ @type base_dir: string
+ @rtype: tuple( version[string], error[string])
+ @returns:
+ 1. tuple( version[string], error[string])
+ Either version or error is populated (but never both)
+
+ """
+ lines = []
+ pathname = os.path.join(base_dir, 'Makefile')
+ try:
+ f = codecs.open(_unicode_encode(pathname,
+ encoding=_encodings['fs'], errors='strict'), mode='r',
+ encoding=_encodings['content'], errors='replace')
+ except OSError as details:
+ return (None, str(details))
+ except IOError as details:
+ return (None, str(details))
+
+ try:
+ for i in range(4):
+ lines.append(f.readline())
+ except OSError as details:
+ return (None, str(details))
+ except IOError as details:
+ return (None, str(details))
+
+ lines = [l.strip() for l in lines]
+
+ version = ''
+
+ #XXX: The following code relies on the ordering of vars within the Makefile
+ for line in lines:
+ # split on the '=' then remove annoying whitespace
+ items = line.split("=")
+ items = [i.strip() for i in items]
+ if items[0] == 'VERSION' or \
+ items[0] == 'PATCHLEVEL':
+ version += items[1]
+ version += "."
+ elif items[0] == 'SUBLEVEL':
+ version += items[1]
+ elif items[0] == 'EXTRAVERSION' and \
+ items[-1] != items[0]:
+ version += items[1]
+
+ # Grab a list of files named localversion* and sort them
+ localversions = os.listdir(base_dir)
+ for x in range(len(localversions)-1,-1,-1):
+ if localversions[x][:12] != "localversion":
+ del localversions[x]
+ localversions.sort()
+
+ # Append the contents of each to the version string, stripping ALL whitespace
+ for lv in localversions:
+ version += "".join( " ".join( grabfile( base_dir+ "/" + lv ) ).split() )
+
+ # Check the .config for a CONFIG_LOCALVERSION and append that too, also stripping whitespace
+ kernelconfig = getconfig(base_dir+"/.config")
+ if kernelconfig and "CONFIG_LOCALVERSION" in kernelconfig:
+ version += "".join(kernelconfig["CONFIG_LOCALVERSION"].split())
+
+ return (version,None)