Gentoo Archives: gentoo-commits

From: "Ulrich Mueller (ulm)" <ulm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] eselect r832 - in trunk: . modules
Date: Thu, 01 Sep 2011 20:21:45
Message-Id: 20110901202134.A3BF22004C@flycatcher.gentoo.org
1 Author: ulm
2 Date: 2011-09-01 20:21:33 +0000 (Thu, 01 Sep 2011)
3 New Revision: 832
4
5 Modified:
6 trunk/ChangeLog
7 trunk/NEWS
8 trunk/modules/profile.eselect
9 Log:
10 Support profiles in overlays, bug 265264.
11
12 Modified: trunk/ChangeLog
13 ===================================================================
14 --- trunk/ChangeLog 2011-08-28 19:40:21 UTC (rev 831)
15 +++ trunk/ChangeLog 2011-09-01 20:21:33 UTC (rev 832)
16 @@ -1,5 +1,10 @@
17 2011-08-28 Ulrich Mueller <ulm@g.o>
18
19 + * modules/profile.eselect (find_targets, set_symlink, do_show)
20 + (do_list): Support profiles in overlays, bug 265264. Thanks to
21 + <mishanq@×××××.com> and <lashzcore@×××××.com> for sending patches.
22 + (get_repos, get_repo_path): New functions.
23 +
24 * modules/bashcomp.eselect: Code cleaned up.
25 (find_targets): Simplified.
26 (do_enable): Don't search for completion files in current working
27
28 Modified: trunk/NEWS
29 ===================================================================
30 --- trunk/NEWS 2011-08-28 19:40:21 UTC (rev 831)
31 +++ trunk/NEWS 2011-09-01 20:21:33 UTC (rev 832)
32 @@ -5,6 +5,9 @@
33 - Fixed bug #363481: Don't search for completion files in current working
34 directory in bashcomp module.
35
36 + New features:
37 + - The profile module supports profiles in overlays (bug #265264).
38 +
39 1.2.16:
40 New features:
41 - Support for pkgcore (bug #304011).
42
43 Modified: trunk/modules/profile.eselect
44 ===================================================================
45 --- trunk/modules/profile.eselect 2011-08-28 19:40:21 UTC (rev 831)
46 +++ trunk/modules/profile.eselect 2011-09-01 20:21:33 UTC (rev 832)
47 @@ -1,6 +1,6 @@
48 # -*-eselect-*- vim: ft=eselect
49 -# Copyright 1999-2011 Gentoo Foundation
50 -# Distributed under the terms of the GNU General Public License v2
51 +# Copyright 2005-2011 Gentoo Foundation
52 +# Distributed under the terms of the GNU General Public License v2 or later
53 # $Id$
54
55 # This is a portage-only module.
56 @@ -11,6 +11,8 @@
57 SVN_DATE='$Date$'
58 VERSION=$(svn_date_to_version "${SVN_DATE}")
59
60 +DEFAULT_REPO="gentoo"
61 +
62 # get location of make.profile symlink
63 get_symlink_location() {
64 local oldloc=${EROOT%/}/etc/make.profile
65 @@ -27,18 +29,43 @@
66 fi
67 }
68
69 +# get list of repositories
70 +get_repos() {
71 + # sort: DEFAULT_REPO first, then alphabetical order
72 + portageq get_repos "${ROOT:-/}" \
73 + | sed "s/[[:space:]]\+/\n/g;s/\b${DEFAULT_REPO}\b/ &/" \
74 + | LC_ALL=C sort
75 + [[ -z ${PIPESTATUS[@]#0} ]]
76 +}
77 +
78 +# get paths for a given list of repositories
79 +get_repo_path() {
80 + portageq get_repo_path "${ROOT:-/}" "$@"
81 +}
82 +
83 # get a list of valid profiles
84 +# returns a line <repo>::<repo_path>::<profile> for every profile
85 find_targets() {
86 - local arch p portdir=$1
87 - [[ -n ${portdir} ]] || portdir=$(portageq portdir)
88 + local arch desc repos repo_paths i p
89
90 arch=$(arch)
91 - [[ -z ${arch} ]] && return 1
92 + [[ -z ${arch} ]] && die -q "Cannot determine architecture"
93
94 - for p in $(sed -n -e "s|^${arch}[[:space:]]\+\([^[:space:]]\+\).*$|\1|p" \
95 - "${ROOT}${portdir}/profiles/profiles.desc")
96 - do
97 - echo ${p}
98 + repos=( $(get_repos) ) || die -q "get_repos failed"
99 + repo_paths=( $(get_repo_path "${repos[@]}") ) \
100 + || die -q "get_repo_path failed"
101 + [[ ${#repos[@]} -eq 0 || ${#repos[@]} -ne ${#repo_paths[@]} ]] \
102 + && die -q "Cannot get list of repositories"
103 +
104 + for (( i = 0; i < ${#repos[@]}; i++ )); do
105 + desc=${repo_paths[i]}/profiles/profiles.desc
106 + [[ -r ${desc} ]] || continue
107 + # parse profiles.desc and find profiles suitable for arch
108 + for p in $(sed -n -e \
109 + "s|^${arch}[[:space:]]\+\([^[:space:]]\+\).*$|\1|p" "${desc}")
110 + do
111 + echo "${repos[i]}::${repo_paths[i]}::${p}"
112 + done
113 done
114 }
115
116 @@ -49,51 +76,57 @@
117
118 # set the make.profile symlink
119 set_symlink() {
120 - local portdir=$(portageq portdir) target=$1 force=$2 targets arch parch
121 + local target=$1 force=$2 targets arch parch repo repopath
122
123 if is_number "${target}"; then
124 - targets=( $(find_targets "${portdir}") )
125 - [[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles"
126 + targets=( $(find_targets) )
127 + [[ ${#targets[@]} -eq 0 ]] \
128 + && die -q "Failed to get a list of valid profiles"
129 target=${targets[target-1]}
130 - elif [[ -n ${target} && -d ${ROOT}${portdir}/profiles/${target} ]]
131 - then
132 + repo=${target%%::*}; target=${target#*::}
133 + repopath=${target%%::*}; target=${target#*::}
134 + elif [[ -n ${target} ]]; then
135 # if the profile was explicitly specified (rather than a number)
136 # double check and make sure it's valid
137 arch=$(arch)
138 - [[ -z ${arch} && -z ${force} ]] && return 1
139 -
140 + [[ -z ${arch} && -z ${force} ]] \
141 + && die -q "Cannot determine architecture"
142 + repo=${target%%:*}
143 + # assume default repo if not explicitly specified
144 + [[ ${repo} == "${target}" || -z ${repo} ]] && repo=${DEFAULT_REPO}
145 + target=${target#*:}
146 + repopath=$(get_repo_path "${repo}") || die -q "get_repo_path failed"
147 # do a reverse lookup and find the arch associated with ${target}
148 parch=$(sed -n -e \
149 "s|^\([[:alnum:]]\+\)[[:space:]].*${target}[[:space:]].*$|\1|p" \
150 - "${ROOT}${portdir}/profiles/profiles.desc")
151 + "${repopath}/profiles/profiles.desc")
152 + [[ ${arch} != "${parch}" && -z ${force} ]] \
153 + && die -q "${target} is not a valid profile for ${arch}"
154 + fi
155
156 - if [[ ${arch} != ${parch} && -z ${force} ]]; then
157 - die -q "${target} is not a valid profile for ${arch}"
158 - fi
159 + [[ -z ${target} || -z ${repopath} ]] \
160 + && die -q "Target \"$1\" doesn't appear to be valid!"
161 + [[ ! -d ${repopath}/profiles/${target} ]] \
162 + && die -q "No profile directory for target \"${target}\""
163 +
164 + # we must call remove_symlink() here instead of calling it from
165 + # do_set(), since if the link is removed, we cannot reliably
166 + # determine ${arch} in find_targets()
167 + if [[ -L ${MAKE_PROFILE} ]]; then
168 + remove_symlink \
169 + || die -q "Couldn't remove current ${MAKE_PROFILE} symlink"
170 fi
171
172 - if [[ -z ${target} ]]; then
173 - die -q "Target \"$1\" doesn't appear to be valid!"
174 - elif [[ -d ${ROOT}${portdir}/profiles/${target} ]]; then
175 - # we must call remove_symlink() here instead of calling
176 - # it from do_set(), since if the link is removed, we
177 - # cannot determine $ARCH in find_targets()
178 - if [[ -L ${MAKE_PROFILE} ]]; then
179 - remove_symlink \
180 - || die -q "Couldn't remove current ${MAKE_PROFILE} symlink"
181 - fi
182 - ln -s "$(relative_name \
183 - "${ROOT}${portdir}" "${MAKE_PROFILE%/*}")/profiles/${target}" \
184 - "${MAKE_PROFILE}"
185 - # check if the resulting symlink is sane
186 - if [[ $(canonicalise "${MAKE_PROFILE}") \
187 - != "$(canonicalise "${EROOT}")"/* ]]; then
188 - write_warning_msg \
189 - "Strange path. Check ${MAKE_PROFILE} symlink"
190 - fi
191 - else
192 - die -q "Target \"$1\" doesn't appear to be valid!"
193 - fi
194 + # set relative symlink
195 + ln -s "$(relative_name \
196 + "${repopath}" "${MAKE_PROFILE%/*}")/profiles/${target}" \
197 + "${MAKE_PROFILE}" \
198 + || die -q "Couldn't set new ${MAKE_PROFILE} symlink"
199 + # check if the resulting symlink is sane
200 + [[ $(canonicalise "${MAKE_PROFILE}") != "$(canonicalise "${EROOT}")"/* ]] \
201 + && write_warning_msg "Strange path. Check ${MAKE_PROFILE} symlink"
202 +
203 + return 0
204 }
205
206 ### show action ###
207 @@ -103,13 +136,30 @@
208 }
209
210 do_show() {
211 + local link repos repo_paths dir i
212 +
213 get_symlink_location
214 write_list_start "Current ${MAKE_PROFILE} symlink:"
215 if [[ -L ${MAKE_PROFILE} ]]; then
216 - local link=$(canonicalise "${MAKE_PROFILE}")
217 - local portdir=$(portageq portdir)
218 - local profiledir=$(canonicalise "${ROOT}${portdir}/profiles")
219 - link=${link##${profiledir}/}
220 + link=$(canonicalise "${MAKE_PROFILE}")
221 + repos=( $(get_repos) ) || die -q "get_repos failed"
222 + repo_paths=( $(get_repo_path "${repos[@]}") ) \
223 + || die -q "get_repo_path failed"
224 + [[ ${#repos[@]} -eq 0 || ${#repos[@]} -ne ${#repo_paths[@]} ]] \
225 + && die -q "Cannot get list of repositories"
226 +
227 + # Unfortunately, it's not obvious where to split a given path
228 + # in repository directory and profile. So loop over all
229 + # repositories and compare the canonicalised paths.
230 + for (( i = 0; i < ${#repos[@]}; i++ )); do
231 + dir=$(canonicalise "${repo_paths[i]}/profiles")
232 + if [[ ${link} == "${dir}"/* ]]; then
233 + link=${link##"${dir}/"}
234 + [[ ${repos[i]} != "${DEFAULT_REPO}" ]] \
235 + && link=${repos[i]}:${link}
236 + break
237 + fi
238 + done
239 write_kv_list_entry "${link}" ""
240 else
241 write_kv_list_entry "(unset)" ""
242 @@ -123,23 +173,27 @@
243 }
244
245 do_list() {
246 - local portdir profiledir active targets
247 + local targets active i target repo repopath
248 +
249 targets=( $(find_targets) )
250 + [[ ${#targets[@]} -eq 0 ]] \
251 + && die -q "Failed to get a list of valid profiles"
252
253 - [[ -z ${targets} ]] && die -q "Failed to get a list of valid profiles"
254 -
255 get_symlink_location
256 - portdir=$(portageq portdir)
257 - profiledir=$(canonicalise "${ROOT}${portdir}/profiles")
258 active=$(canonicalise "${MAKE_PROFILE}")
259 - active=${active##${profiledir}/}
260 - if [[ -n ${targets[@]} ]]; then
261 - local i
262 - for (( i = 0; i < ${#targets[@]}; i++ )); do
263 - [[ ${targets[i]} == ${active} ]] \
264 - && targets[i]=$(highlight_marker "${targets[i]}")
265 - done
266 - fi
267 +
268 + for (( i = 0; i < ${#targets[@]}; i++ )); do
269 + target=${targets[i]}
270 + repo=${target%%::*}; target=${target#*::}
271 + repopath=${target%%::*}; target=${target#*::}
272 + if [[ ${repo} == "${DEFAULT_REPO}" ]]; then
273 + targets[i]=${target}
274 + else
275 + targets[i]=${repo}:${target}
276 + fi
277 + [[ $(canonicalise "${repopath}/profiles/${target}") == "${active}" ]] \
278 + && targets[i]=$(highlight_marker "${targets[i]}")
279 + done
280 write_list_start "Available profile symlink targets:"
281 write_numbered_list "${targets[@]}"
282 }