diff options
author | Zac Medico <zmedico@gentoo.org> | 2010-08-30 20:55:11 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2010-08-30 20:55:11 -0700 |
commit | 50daef1ab961c42a3352281e915da5a89297e3a9 (patch) | |
tree | 8396db45ae2ec7ba70067f9b20c2ffedf92a9939 /pym/portage | |
parent | 74c61b80af137fea93e5cbe7b59567812bb92d5c (diff) | |
download | portage-50daef1ab961c42a3352281e915da5a89297e3a9.tar.gz portage-50daef1ab961c42a3352281e915da5a89297e3a9.tar.bz2 portage-50daef1ab961c42a3352281e915da5a89297e3a9.zip |
Bug #335340 - Add support for PORTAGE_BZIP2_COMMAND and
PORTAGE_BUNZIP2_COMMAND settings in make.conf. This only adds support
for binary packages, since that's where pbzip2 can provide the most
benefit in common cases.
Diffstat (limited to 'pym/portage')
-rw-r--r-- | pym/portage/package/ebuild/_config/env_var_validation.py | 23 | ||||
-rw-r--r-- | pym/portage/package/ebuild/_config/special_env_vars.py | 14 | ||||
-rw-r--r-- | pym/portage/package/ebuild/config.py | 39 |
3 files changed, 70 insertions, 6 deletions
diff --git a/pym/portage/package/ebuild/_config/env_var_validation.py b/pym/portage/package/ebuild/_config/env_var_validation.py new file mode 100644 index 000000000..d3db545cb --- /dev/null +++ b/pym/portage/package/ebuild/_config/env_var_validation.py @@ -0,0 +1,23 @@ +# Copyright 2010 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +from portage import os +from portage.process import find_binary +from portage.util import shlex_split + +def validate_cmd_var(v): + """ + Validate an evironment variable value to see if it + contains an executable command as the first token. + returns (valid, token_list) where 'valid' is boolean and 'token_list' + is the (possibly empty) list of tokens split by shlex. + """ + invalid = False + v_split = shlex_split(v) + if not v_split: + invalid = True + elif os.path.isabs(v_split[0]): + invalid = not os.access(v_split[0], os.EX_OK) + elif find_binary(v_split[0]) is None: + invalid = True + return (not invalid, v_split) diff --git a/pym/portage/package/ebuild/_config/special_env_vars.py b/pym/portage/package/ebuild/_config/special_env_vars.py index 2a515dd0d..4a29b1446 100644 --- a/pym/portage/package/ebuild/_config/special_env_vars.py +++ b/pym/portage/package/ebuild/_config/special_env_vars.py @@ -43,7 +43,8 @@ environ_whitelist += [ "PORTAGE_BINPKG_FILE", "PORTAGE_BINPKG_TAR_OPTS", "PORTAGE_BINPKG_TMPFILE", "PORTAGE_BIN_PATH", - "PORTAGE_BUILDDIR", "PORTAGE_COLORMAP", + "PORTAGE_BUILDDIR", "PORTAGE_BUNZIP2_COMMAND", "PORTAGE_BZIP2_COMMAND", + "PORTAGE_COLORMAP", "PORTAGE_CONFIGROOT", "PORTAGE_DEBUG", "PORTAGE_DEPCACHEDIR", "PORTAGE_EBUILD_EXIT_FILE", "PORTAGE_FEATURES", "PORTAGE_GID", "PORTAGE_GRPNAME", @@ -152,10 +153,13 @@ environ_filter += [ environ_filter = frozenset(environ_filter) -default_globals = ( - ('ACCEPT_LICENSE', '* -@EULA'), - ('ACCEPT_PROPERTIES', '*'), -) +default_globals = { + 'ACCEPT_LICENSE': '* -@EULA', + 'ACCEPT_PROPERTIES': '*', + 'PORTAGE_BZIP2_COMMAND': 'bzip2', +} + +validate_commands = ('PORTAGE_BZIP2_COMMAND', 'PORTAGE_BUNZIP2_COMMAND',) # To enhance usability, make some vars case insensitive # by forcing them to lower case. diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index 847ac1ccb..01950f9af 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -46,6 +46,7 @@ from portage.util import ensure_dirs, getconfig, grabdict, \ from portage.versions import catpkgsplit, catsplit, cpv_getkey from portage.package.ebuild._config import special_env_vars +from portage.package.ebuild._config.env_var_validation import validate_cmd_var from portage.package.ebuild._config.features_set import features_set from portage.package.ebuild._config.LicenseManager import LicenseManager from portage.package.ebuild._config.UseManager import UseManager @@ -444,7 +445,7 @@ class config(object): if self.mygcfg is None: self.mygcfg = {} - for k, v in self._default_globals: + for k, v in self._default_globals.items(): self.mygcfg.setdefault(k, v) self.configlist.append(self.mygcfg) @@ -773,6 +774,8 @@ class config(object): self._iuse_implicit_match = _iuse_implicit_match_cache(self) + self._validate_commands() + for k in self._case_insensitive_vars: if k in self: self[k] = self[k].lower() @@ -781,6 +784,40 @@ class config(object): if mycpv: self.setcpv(mycpv) + def _validate_commands(self): + for k in special_env_vars.validate_commands: + v = self.get(k) + if v is not None: + valid, v_split = validate_cmd_var(v) + + if not valid: + if v_split: + writemsg_level(_("%s setting is invalid: '%s'\n") % \ + (k, v), level=logging.ERROR, noiselevel=-1) + + # before deleting the invalid setting, backup + # the default value if available + v = self.configdict['globals'].get(k) + if v is not None: + default_valid, v_split = validate_cmd_var(v) + if not default_valid: + if v_split: + writemsg_level( + _("%s setting from make.globals" + \ + " is invalid: '%s'\n") % \ + (k, v), level=logging.ERROR, noiselevel=-1) + # make.globals seems corrupt, so try for + # a hardcoded default instead + v = self._default_globals.get(k) + + # delete all settings for this key, + # including the invalid one + del self[k] + self.backupenv.pop(k, None) + if v: + # restore validated default + self.configdict['globals'][k] = v + def _init_dirs(self): """ Create a few directories that are critical to portage operation |