1 |
commit: 10cccf7e0a1423f77a0962bcd7bf9658d2a15343 |
2 |
Author: Arfrever Frehtes Taifersar Arahesis <Arfrever <AT> Apache <DOT> Org> |
3 |
AuthorDate: Tue Dec 1 06:49:05 2015 +0000 |
4 |
Commit: Arfrever Frehtes Taifersar Arahesis <arfrever <AT> apache <DOT> org> |
5 |
CommitDate: Tue Dec 1 06:49:05 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=10cccf7e |
7 |
|
8 |
Support environmental variables overriding parts of configuration of repositories. |
9 |
|
10 |
PORTAGE_REPOSITORY:${repository_name}:${attribute} overrides value of given attribute. |
11 |
PORTAGE_ADDED_REPOSITORIES specifies names of repositories added to configuration. |
12 |
PORTAGE_DELETED_REPOSITORIES specifies names of repositories deleted from configuration. |
13 |
|
14 |
man/portage.5 | 19 ++++++++++++---- |
15 |
.../package/ebuild/_config/special_env_vars.py | 13 ++++++++--- |
16 |
pym/portage/package/ebuild/config.py | 5 +++-- |
17 |
pym/portage/repository/config.py | 25 ++++++++++++++++++++-- |
18 |
4 files changed, 51 insertions(+), 11 deletions(-) |
19 |
|
20 |
diff --git a/man/portage.5 b/man/portage.5 |
21 |
index c9e70a0..6c41332 100644 |
22 |
--- a/man/portage.5 |
23 |
+++ b/man/portage.5 |
24 |
@@ -1,4 +1,4 @@ |
25 |
-.TH "PORTAGE" "5" "Nov 2015" "Portage VERSION" "Portage" |
26 |
+.TH "PORTAGE" "5" "Dec 2015" "Portage VERSION" "Portage" |
27 |
.SH NAME |
28 |
portage \- the heart of Gentoo |
29 |
.SH "DESCRIPTION" |
30 |
@@ -862,9 +862,6 @@ only. |
31 |
.TP |
32 |
.BR repos.conf |
33 |
Specifies \fIsite\-specific\fR repository configuration information. |
34 |
-.br |
35 |
-Configuration specified in \fBrepos.conf\fR can be overriden by \fBPORTAGE_REPOSITORIES\fR |
36 |
-environmental variable, which has the same format as \fBrepos.conf\fR. |
37 |
|
38 |
.I Format: |
39 |
.nf |
40 |
@@ -874,6 +871,20 @@ environmental variable, which has the same format as \fBrepos.conf\fR. |
41 |
\- attributes are specified in "${attribute} = ${value}" format |
42 |
.fi |
43 |
|
44 |
+.I Environmental variables overriding configuration: |
45 |
+.nf |
46 |
+\- \fBPORTAGE_REPOSITORIES\fR overrides full configuration. |
47 |
+ Format: Format of repos.conf |
48 |
+ Environmental variables described below are ignored when PORTAGE_REPOSITORIES is set. |
49 |
+\- \fBPORTAGE_REPOSITORY:${repository_name}:${attribute}\fR overrides value of given attribute. |
50 |
+ Usage of \fBenv\fR(1) tool is needed if ":" character is not supported in names of shell variables. |
51 |
+ Example: env PORTAGE_REPOSITORY:gentoo:location=/var/repositories/gentoo emerge ... |
52 |
+\- \fBPORTAGE_ADDED_REPOSITORIES\fR specifies names of repositories added to configuration. |
53 |
+ Format: Whitespace\-separated list of names of repositories |
54 |
+\- \fBPORTAGE_DELETED_REPOSITORIES\fR specifies names of repositories deleted from configuration. |
55 |
+ Format: Whitespace\-separated list of names of repositories |
56 |
+.fi |
57 |
+ |
58 |
.I Attributes supported in DEFAULT section: |
59 |
.RS |
60 |
.RS |
61 |
|
62 |
diff --git a/pym/portage/package/ebuild/_config/special_env_vars.py b/pym/portage/package/ebuild/_config/special_env_vars.py |
63 |
index 905d5e7..8479cf5 100644 |
64 |
--- a/pym/portage/package/ebuild/_config/special_env_vars.py |
65 |
+++ b/pym/portage/package/ebuild/_config/special_env_vars.py |
66 |
@@ -1,15 +1,18 @@ |
67 |
-# Copyright 2010-2014 Gentoo Foundation |
68 |
+# Copyright 2010-2015 Gentoo Foundation |
69 |
# Distributed under the terms of the GNU General Public License v2 |
70 |
|
71 |
from __future__ import unicode_literals |
72 |
|
73 |
__all__ = ( |
74 |
- 'case_insensitive_vars', 'default_globals', 'env_blacklist', \ |
75 |
- 'environ_filter', 'environ_whitelist', 'environ_whitelist_re', |
76 |
+ 'case_insensitive_vars', 'default_globals', 'env_blacklist', |
77 |
+ 'environ_filter', 'environ_filter_re', 'environ_whitelist', |
78 |
+ 'environ_whitelist_re', 'global_only_vars', 'validate_commands' |
79 |
) |
80 |
|
81 |
import re |
82 |
|
83 |
+from portage.repository.config import _repo_attr_override_var_re |
84 |
+ |
85 |
# Blacklisted variables are internal variables that are never allowed |
86 |
# to enter the config instance from the external environment or |
87 |
# configuration files. |
88 |
@@ -157,10 +160,12 @@ environ_filter += [ |
89 |
"FETCHCOMMAND_HTTP", "FETCHCOMMAND_HTTPS", |
90 |
"FETCHCOMMAND_RSYNC", "FETCHCOMMAND_SFTP", |
91 |
"GENTOO_MIRRORS", "NOCONFMEM", "O", |
92 |
+ "PORTAGE_ADDED_REPOSITORIES", |
93 |
"PORTAGE_BACKGROUND", "PORTAGE_BACKGROUND_UNMERGE", |
94 |
"PORTAGE_BINHOST", "PORTAGE_BINPKG_FORMAT", |
95 |
"PORTAGE_BUILDDIR_LOCKED", |
96 |
"PORTAGE_CHECKSUM_FILTER", |
97 |
+ "PORTAGE_DELETED_REPOSITORIES", |
98 |
"PORTAGE_ELOG_CLASSES", |
99 |
"PORTAGE_ELOG_MAILFROM", "PORTAGE_ELOG_MAILSUBJECT", |
100 |
"PORTAGE_ELOG_MAILURI", "PORTAGE_ELOG_SYSTEM", |
101 |
@@ -190,6 +195,8 @@ environ_filter += [ |
102 |
|
103 |
environ_filter = frozenset(environ_filter) |
104 |
|
105 |
+environ_filter_re = re.compile(r"(" + _repo_attr_override_var_re.pattern + r")") |
106 |
+ |
107 |
# Variables that are not allowed to have per-repo or per-package |
108 |
# settings. |
109 |
global_only_vars = frozenset([ |
110 |
|
111 |
diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py |
112 |
index da9a936..7cf5a4c 100644 |
113 |
--- a/pym/portage/package/ebuild/config.py |
114 |
+++ b/pym/portage/package/ebuild/config.py |
115 |
@@ -168,6 +168,7 @@ class config(object): |
116 |
_default_globals = special_env_vars.default_globals |
117 |
_env_blacklist = special_env_vars.env_blacklist |
118 |
_environ_filter = special_env_vars.environ_filter |
119 |
+ _environ_filter_re = special_env_vars.environ_filter_re |
120 |
_environ_whitelist = special_env_vars.environ_whitelist |
121 |
_environ_whitelist_re = special_env_vars.environ_whitelist_re |
122 |
_global_only_vars = special_env_vars.global_only_vars |
123 |
@@ -2712,7 +2713,7 @@ class config(object): |
124 |
|
125 |
environ_whitelist = self._environ_whitelist |
126 |
for x in self: |
127 |
- if x in environ_filter: |
128 |
+ if x in environ_filter or self._environ_filter_re.match(x) is not None: |
129 |
continue |
130 |
myvalue = self.get(x) |
131 |
if myvalue is None: |
132 |
@@ -2723,7 +2724,7 @@ class config(object): |
133 |
continue |
134 |
if filter_calling_env and \ |
135 |
x not in environ_whitelist and \ |
136 |
- not self._environ_whitelist_re.match(x): |
137 |
+ self._environ_whitelist_re.match(x) is None: |
138 |
# Do not allow anything to leak into the ebuild |
139 |
# environment unless it is explicitly whitelisted. |
140 |
# This ensures that variables unset by the ebuild |
141 |
|
142 |
diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py |
143 |
index a21c891..b987b56 100644 |
144 |
--- a/pym/portage/repository/config.py |
145 |
+++ b/pym/portage/repository/config.py |
146 |
@@ -50,6 +50,8 @@ _portage1_profiles_allow_directories = frozenset( |
147 |
|
148 |
_repo_name_sub_re = re.compile(r'[^\w-]') |
149 |
|
150 |
+_repo_attr_override_var_re = re.compile(r'^PORTAGE_REPOSITORY:([^:]+):([^:]+)$') |
151 |
+ |
152 |
def _gen_valid_repo(name): |
153 |
""" |
154 |
Substitute hyphen in place of characters that don't conform to PMS 3.1.5, |
155 |
@@ -546,7 +548,7 @@ class RepoConfigLoader(object): |
156 |
return portdir |
157 |
|
158 |
@staticmethod |
159 |
- def _parse(paths, prepos, local_config, default_opts): |
160 |
+ def _parse(paths, prepos, local_config, default_opts, added_repos, deleted_repos, attrs_overrides): |
161 |
"""Parse files in paths to load config""" |
162 |
parser = SafeConfigParser(defaults=default_opts) |
163 |
|
164 |
@@ -595,11 +597,24 @@ class RepoConfigLoader(object): |
165 |
prepos['DEFAULT'] = RepoConfig("DEFAULT", |
166 |
parser.defaults(), local_config=local_config) |
167 |
|
168 |
+ # Apply overrides from PORTAGE_ADDED_REPOSITORIES and PORTAGE_DELETED_REPOSITORIES environmental variables. |
169 |
+ for added_repo in added_repos: |
170 |
+ if not parser.has_section(added_repo): |
171 |
+ parser.add_section(added_repo) |
172 |
+ for deleted_repo in deleted_repos: |
173 |
+ parser.remove_section(deleted_repo) |
174 |
+ |
175 |
for sname in parser.sections(): |
176 |
optdict = {} |
177 |
for oname in parser.options(sname): |
178 |
optdict[oname] = parser.get(sname, oname) |
179 |
|
180 |
+ # Apply overrides from PORTAGE_REPOSITORY:${repository_name}:${attribute} environmental variables. |
181 |
+ for k, v in attrs_overrides.items(): |
182 |
+ m = _repo_attr_override_var_re.match(k) |
183 |
+ if m is not None and m.group(1) == sname: |
184 |
+ optdict[m.group(2)] = v |
185 |
+ |
186 |
repo = RepoConfig(sname, optdict, local_config=local_config) |
187 |
for o in portage.sync.module_specific_options(repo): |
188 |
if parser.has_option(sname, o): |
189 |
@@ -628,11 +643,17 @@ class RepoConfigLoader(object): |
190 |
} |
191 |
|
192 |
if "PORTAGE_REPOSITORIES" in settings: |
193 |
+ added_repos = [] |
194 |
+ deleted_repos = [] |
195 |
+ attrs_overrides = {} |
196 |
portdir = "" |
197 |
portdir_overlay = "" |
198 |
# deprecated portdir_sync |
199 |
portdir_sync = "" |
200 |
else: |
201 |
+ added_repos = settings.get("PORTAGE_ADDED_REPOSITORIES", "").split() |
202 |
+ deleted_repos = settings.get("PORTAGE_DELETED_REPOSITORIES", "").split() |
203 |
+ attrs_overrides = {x: settings[x] for x in settings if _repo_attr_override_var_re.match(x) is not None} |
204 |
portdir = settings.get("PORTDIR", "") |
205 |
portdir_overlay = settings.get("PORTDIR_OVERLAY", "") |
206 |
# deprecated portdir_sync |
207 |
@@ -642,7 +663,7 @@ class RepoConfigLoader(object): |
208 |
settings.get("PORTAGE_RSYNC_EXTRA_OPTS", None) |
209 |
|
210 |
try: |
211 |
- self._parse(paths, prepos, settings.local_config, default_opts) |
212 |
+ self._parse(paths, prepos, settings.local_config, default_opts, added_repos, deleted_repos, attrs_overrides) |
213 |
except ConfigParserError as e: |
214 |
writemsg( |
215 |
_("!!! Error while reading repo config file: %s\n") % e, |