1 |
Author: zmedico |
2 |
Date: 2010-02-25 07:33:32 +0000 (Thu, 25 Feb 2010) |
3 |
New Revision: 15453 |
4 |
|
5 |
Added: |
6 |
main/trunk/pym/portage/util/ExtractKernelVersion.py |
7 |
Modified: |
8 |
main/trunk/pym/portage/__init__.py |
9 |
main/trunk/pym/portage/package/ebuild/doebuild.py |
10 |
Log: |
11 |
Move ExtractKernelVersion portage.util.ExtractKernelVersion. |
12 |
|
13 |
|
14 |
Modified: main/trunk/pym/portage/__init__.py |
15 |
=================================================================== |
16 |
--- main/trunk/pym/portage/__init__.py 2010-02-25 07:17:51 UTC (rev 15452) |
17 |
+++ main/trunk/pym/portage/__init__.py 2010-02-25 07:33:32 UTC (rev 15453) |
18 |
@@ -121,6 +121,7 @@ |
19 |
'writemsg_stdout,write_atomic', |
20 |
'portage.util.digraph:digraph', |
21 |
'portage.util.env_update:env_update', |
22 |
+ 'portage.util.ExtractKernelVersion:ExtractKernelVersion', |
23 |
'portage.util.listdir:cacheddir,listdir', |
24 |
'portage.versions', |
25 |
'portage.versions:best,catpkgsplit,catsplit,cpv_getkey,' + \ |
26 |
@@ -533,73 +534,6 @@ |
27 |
mylink=mydir+"/"+mylink |
28 |
return os.path.normpath(mylink) |
29 |
|
30 |
-def ExtractKernelVersion(base_dir): |
31 |
- """ |
32 |
- Try to figure out what kernel version we are running |
33 |
- @param base_dir: Path to sources (usually /usr/src/linux) |
34 |
- @type base_dir: string |
35 |
- @rtype: tuple( version[string], error[string]) |
36 |
- @returns: |
37 |
- 1. tuple( version[string], error[string]) |
38 |
- Either version or error is populated (but never both) |
39 |
- |
40 |
- """ |
41 |
- lines = [] |
42 |
- pathname = os.path.join(base_dir, 'Makefile') |
43 |
- try: |
44 |
- f = codecs.open(_unicode_encode(pathname, |
45 |
- encoding=_encodings['fs'], errors='strict'), mode='r', |
46 |
- encoding=_encodings['content'], errors='replace') |
47 |
- except OSError as details: |
48 |
- return (None, str(details)) |
49 |
- except IOError as details: |
50 |
- return (None, str(details)) |
51 |
- |
52 |
- try: |
53 |
- for i in range(4): |
54 |
- lines.append(f.readline()) |
55 |
- except OSError as details: |
56 |
- return (None, str(details)) |
57 |
- except IOError as details: |
58 |
- return (None, str(details)) |
59 |
- |
60 |
- lines = [l.strip() for l in lines] |
61 |
- |
62 |
- version = '' |
63 |
- |
64 |
- #XXX: The following code relies on the ordering of vars within the Makefile |
65 |
- for line in lines: |
66 |
- # split on the '=' then remove annoying whitespace |
67 |
- items = line.split("=") |
68 |
- items = [i.strip() for i in items] |
69 |
- if items[0] == 'VERSION' or \ |
70 |
- items[0] == 'PATCHLEVEL': |
71 |
- version += items[1] |
72 |
- version += "." |
73 |
- elif items[0] == 'SUBLEVEL': |
74 |
- version += items[1] |
75 |
- elif items[0] == 'EXTRAVERSION' and \ |
76 |
- items[-1] != items[0]: |
77 |
- version += items[1] |
78 |
- |
79 |
- # Grab a list of files named localversion* and sort them |
80 |
- localversions = os.listdir(base_dir) |
81 |
- for x in range(len(localversions)-1,-1,-1): |
82 |
- if localversions[x][:12] != "localversion": |
83 |
- del localversions[x] |
84 |
- localversions.sort() |
85 |
- |
86 |
- # Append the contents of each to the version string, stripping ALL whitespace |
87 |
- for lv in localversions: |
88 |
- version += "".join( " ".join( grabfile( base_dir+ "/" + lv ) ).split() ) |
89 |
- |
90 |
- # Check the .config for a CONFIG_LOCALVERSION and append that too, also stripping whitespace |
91 |
- kernelconfig = getconfig(base_dir+"/.config") |
92 |
- if kernelconfig and "CONFIG_LOCALVERSION" in kernelconfig: |
93 |
- version += "".join(kernelconfig["CONFIG_LOCALVERSION"].split()) |
94 |
- |
95 |
- return (version,None) |
96 |
- |
97 |
_doebuild_manifest_exempt_depend = 0 |
98 |
|
99 |
def digestgen(myarchives=None, mysettings=None, |
100 |
|
101 |
Modified: main/trunk/pym/portage/package/ebuild/doebuild.py |
102 |
=================================================================== |
103 |
--- main/trunk/pym/portage/package/ebuild/doebuild.py 2010-02-25 07:17:51 UTC (rev 15452) |
104 |
+++ main/trunk/pym/portage/package/ebuild/doebuild.py 2010-02-25 07:33:32 UTC (rev 15453) |
105 |
@@ -21,23 +21,34 @@ |
106 |
import portage |
107 |
portage.proxy.lazyimport.lazyimport(globals(), |
108 |
'portage.package.ebuild.config:check_config_instance', |
109 |
+ 'portage.util.ExtractKernelVersion:ExtractKernelVersion' |
110 |
) |
111 |
|
112 |
-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 |
113 |
-from portage.const import EBUILD_SH_ENV_FILE, EBUILD_SH_BINARY, INVALID_ENV_FILE, MISC_SH_BINARY |
114 |
-from portage.data import portage_gid, portage_uid, secpass, uid, userpriv_groups |
115 |
+from portage import auxdbkeys, bsd_chflags, dep_check, digestcheck, \ |
116 |
+ digestgen, eapi_is_supported, merge, os, selinux, StringIO, \ |
117 |
+ unmerge, _encodings, _parse_eapi_ebuild_head, _os_merge, \ |
118 |
+ _shell_quote, _split_ebuild_name_glep55, _unicode_decode, _unicode_encode |
119 |
+from portage.const import EBUILD_SH_ENV_FILE, EBUILD_SH_BINARY, \ |
120 |
+ INVALID_ENV_FILE, MISC_SH_BINARY |
121 |
+from portage.data import portage_gid, portage_uid, secpass, \ |
122 |
+ uid, userpriv_groups |
123 |
from portage.dbapi.virtual import fakedbapi |
124 |
-from portage.dep import Atom, paren_enclose, paren_normalize, paren_reduce, use_reduce |
125 |
+from portage.dep import Atom, paren_enclose, paren_normalize, \ |
126 |
+ paren_reduce, use_reduce |
127 |
from portage.elog import elog_process |
128 |
from portage.elog.messages import eerror, eqawarn |
129 |
-from portage.exception import DigestException, FileNotFound, IncorrectParameter, InvalidAtom, InvalidDependString, PermissionDenied, UnsupportedAPIException |
130 |
+from portage.exception import DigestException, FileNotFound, \ |
131 |
+ IncorrectParameter, InvalidAtom, InvalidDependString, PermissionDenied, \ |
132 |
+ UnsupportedAPIException |
133 |
from portage.localization import _ |
134 |
from portage.manifest import Manifest |
135 |
from portage.output import style_to_ansi_code |
136 |
from portage.package.ebuild.fetch import fetch |
137 |
from portage.package.ebuild.prepare_build_dirs import prepare_build_dirs |
138 |
from portage.package.ebuild._pty import _create_pty_or_pipe |
139 |
-from portage.util import apply_recursive_permissions, apply_secpass_permissions, noiselimit, normalize_path, writemsg, writemsg_stdout, write_atomic |
140 |
+from portage.util import apply_recursive_permissions, \ |
141 |
+ apply_secpass_permissions, noiselimit, normalize_path, \ |
142 |
+ writemsg, writemsg_stdout, write_atomic |
143 |
from portage.versions import _pkgsplit |
144 |
|
145 |
def doebuild_environment(myebuild, mydo, myroot, mysettings, |
146 |
|
147 |
Added: main/trunk/pym/portage/util/ExtractKernelVersion.py |
148 |
=================================================================== |
149 |
--- main/trunk/pym/portage/util/ExtractKernelVersion.py (rev 0) |
150 |
+++ main/trunk/pym/portage/util/ExtractKernelVersion.py 2010-02-25 07:33:32 UTC (rev 15453) |
151 |
@@ -0,0 +1,77 @@ |
152 |
+# Copyright 2010 Gentoo Foundation |
153 |
+# Distributed under the terms of the GNU General Public License v2 |
154 |
+# $Id$ |
155 |
+ |
156 |
+__all__ = ['ExtractKernelVersion'] |
157 |
+ |
158 |
+import codecs |
159 |
+ |
160 |
+from portage import os, _encodings, _unicode_encode |
161 |
+from portage.util import getconfig, grabfile |
162 |
+ |
163 |
+def ExtractKernelVersion(base_dir): |
164 |
+ """ |
165 |
+ Try to figure out what kernel version we are running |
166 |
+ @param base_dir: Path to sources (usually /usr/src/linux) |
167 |
+ @type base_dir: string |
168 |
+ @rtype: tuple( version[string], error[string]) |
169 |
+ @returns: |
170 |
+ 1. tuple( version[string], error[string]) |
171 |
+ Either version or error is populated (but never both) |
172 |
+ |
173 |
+ """ |
174 |
+ lines = [] |
175 |
+ pathname = os.path.join(base_dir, 'Makefile') |
176 |
+ try: |
177 |
+ f = codecs.open(_unicode_encode(pathname, |
178 |
+ encoding=_encodings['fs'], errors='strict'), mode='r', |
179 |
+ encoding=_encodings['content'], errors='replace') |
180 |
+ except OSError as details: |
181 |
+ return (None, str(details)) |
182 |
+ except IOError as details: |
183 |
+ return (None, str(details)) |
184 |
+ |
185 |
+ try: |
186 |
+ for i in range(4): |
187 |
+ lines.append(f.readline()) |
188 |
+ except OSError as details: |
189 |
+ return (None, str(details)) |
190 |
+ except IOError as details: |
191 |
+ return (None, str(details)) |
192 |
+ |
193 |
+ lines = [l.strip() for l in lines] |
194 |
+ |
195 |
+ version = '' |
196 |
+ |
197 |
+ #XXX: The following code relies on the ordering of vars within the Makefile |
198 |
+ for line in lines: |
199 |
+ # split on the '=' then remove annoying whitespace |
200 |
+ items = line.split("=") |
201 |
+ items = [i.strip() for i in items] |
202 |
+ if items[0] == 'VERSION' or \ |
203 |
+ items[0] == 'PATCHLEVEL': |
204 |
+ version += items[1] |
205 |
+ version += "." |
206 |
+ elif items[0] == 'SUBLEVEL': |
207 |
+ version += items[1] |
208 |
+ elif items[0] == 'EXTRAVERSION' and \ |
209 |
+ items[-1] != items[0]: |
210 |
+ version += items[1] |
211 |
+ |
212 |
+ # Grab a list of files named localversion* and sort them |
213 |
+ localversions = os.listdir(base_dir) |
214 |
+ for x in range(len(localversions)-1,-1,-1): |
215 |
+ if localversions[x][:12] != "localversion": |
216 |
+ del localversions[x] |
217 |
+ localversions.sort() |
218 |
+ |
219 |
+ # Append the contents of each to the version string, stripping ALL whitespace |
220 |
+ for lv in localversions: |
221 |
+ version += "".join( " ".join( grabfile( base_dir+ "/" + lv ) ).split() ) |
222 |
+ |
223 |
+ # Check the .config for a CONFIG_LOCALVERSION and append that too, also stripping whitespace |
224 |
+ kernelconfig = getconfig(base_dir+"/.config") |
225 |
+ if kernelconfig and "CONFIG_LOCALVERSION" in kernelconfig: |
226 |
+ version += "".join(kernelconfig["CONFIG_LOCALVERSION"].split()) |
227 |
+ |
228 |
+ return (version,None) |
229 |
|
230 |
|
231 |
Property changes on: main/trunk/pym/portage/util/ExtractKernelVersion.py |
232 |
___________________________________________________________________ |
233 |
Added: svn:keywords |
234 |
+ Id |