From: Zac Medico Date: Tue, 26 Mar 2013 19:14:50 +0000 (-0700) Subject: make.conf: recurse directories, bug #463266 X-Git-Tag: v2.2.0_alpha170~7 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=86e75790954e766beba75443d967b2c25055c5b0;p=portage.git make.conf: recurse directories, bug #463266 --- diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py index 5f3e1c6b7..1d2e4a60a 100644 --- a/pym/portage/package/ebuild/config.py +++ b/pym/portage/package/ebuild/config.py @@ -339,7 +339,7 @@ class config(object): for x in make_conf_paths: mygcfg = getconfig(x, tolerant=tolerant, allow_sourcing=True, - expand=make_conf) + expand=make_conf, recursive=True) if mygcfg is not None: make_conf.update(mygcfg) make_conf_count += 1 @@ -538,7 +538,7 @@ class config(object): for x in make_conf_paths: mygcfg.update(getconfig(x, tolerant=tolerant, allow_sourcing=True, - expand=expand_map) or {}) + expand=expand_map, recursive=True) or {}) # Don't allow the user to override certain variables in make.conf profile_only_variables = self.configdict["defaults"].get( diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py index dafc3e34d..59d4fa4c4 100644 --- a/pym/portage/util/__init__.py +++ b/pym/portage/util/__init__.py @@ -483,6 +483,9 @@ def grabfile_package(myfilename, compatlevel=0, recursive=0, allow_wildcard=Fals atoms.append(pkg_orig) return atoms +def _recursive_basename_filter(f): + return not f.startswith(".") and not f.endswith("~") + def grablines(myfilename, recursive=0, remember_source_file=False): mylines=[] if recursive and os.path.isdir(myfilename): @@ -499,7 +502,7 @@ def grablines(myfilename, recursive=0, remember_source_file=False): raise dirlist.sort() for f in dirlist: - if not f.startswith(".") and not f.endswith("~"): + if _recursive_basename_filter(f): mylines.extend(grablines( os.path.join(myfilename, f), recursive, remember_source_file)) else: @@ -558,7 +561,9 @@ class _tolerant_shlex(shlex.shlex): _invalid_var_name_re = re.compile(r'^\d|\W') -def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True): +def getconfig(mycfg, tolerant=False, allow_sourcing=False, expand=True, + recursive=False): + if isinstance(expand, dict): # Some existing variable definitions have been # passed in, for use in substitutions. @@ -567,6 +572,46 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True): else: expand_map = {} mykeys = {} + + if recursive and os.path.isdir(mycfg): + # Use source commands so that syntax error messages + # can display real file names and line numbers. + recursive_files = [] + for parent, dirs, files in os.walk(mycfg): + try: + parent = _unicode_decode(parent, + encoding=_encodings['fs'], errors='strict') + except UnicodeDecodeError: + continue + for fname_enc in dirs[:]: + try: + fname = _unicode_decode(fname_enc, + encoding=_encodings['fs'], errors='strict') + except UnicodeDecodeError: + dirs.remove(fname_enc) + continue + if fname in VCS_DIRS or not _recursive_basename_filter(fname): + dirs.remove(fname_enc) + for fname in files: + try: + fname = _unicode_decode(fname, + encoding=_encodings['fs'], errors='strict') + except UnicodeDecodeError: + pass + else: + if _recursive_basename_filter(fname): + fname = os.path.join(parent, fname) + if os.path.isfile(fname): + recursive_files.append(fname) + recursive_files.sort() + if not expand: + expand_map = False + for fname in recursive_files: + mykeys.update(getconfig(fname, tolerant=tolerant, + allow_sourcing=allow_sourcing, expand=expand_map, + recursive=False) or {}) + return mykeys + f = None try: # NOTE: shlex doesn't support unicode objects with Python 2