Exemplo n.º 1
0
def load_make_conf(vars_dict, path, allow_sourcing=False, required=True,
                   incrementals=False):
    """parse make.conf files

    Args:
        vars_dict (dict): dictionary to add parsed variables to
        path (str): path to the make.conf which can be a regular file or
            directory, if a directory is passed all the non-hidden files within
            that directory are parsed in alphabetical order.
    """
    sourcing_command = None
    if allow_sourcing:
        sourcing_command = 'source'

    for fp in sorted_scan(os.path.realpath(path), follow_symlinks=True, nonexistent=True):
        try:
            new_vars = read_bash_dict(
                fp, vars_dict=vars_dict, sourcing_command=sourcing_command)
        except EnvironmentError as e:
            if e.errno == errno.EACCES:
                raise_from(errors.PermissionDeniedError(fp, write=False))
            if e.errno != errno.ENOENT or required:
                raise_from(errors.ParsingError("parsing %r" % (fp,), exception=e))
            return

        if incrementals:
            for key in econst.incrementals:
                if key in vars_dict and key in new_vars:
                    new_vars[key] = "%s %s" % (vars_dict[key], new_vars[key])
        # quirk of read_bash_dict; it returns only what was mutated.
        vars_dict.update(new_vars)
Exemplo n.º 2
0
def load_make_conf(vars_dict, path, allow_sourcing=False, required=True,
                   incrementals=False):
    """parse make.conf files

    Args:
        vars_dict (dict): dictionary to add parsed variables to
        path (str): path to the make.conf which can be a regular file or
            directory, if a directory is passed all the non-hidden files within
            that directory are parsed in alphabetical order.
    """
    sourcing_command = None
    if allow_sourcing:
        sourcing_command = 'source'

    for fp in sorted_scan(os.path.realpath(path), follow_symlinks=True, nonexistent=True):
        try:
            new_vars = read_bash_dict(
                fp, vars_dict=vars_dict, sourcing_command=sourcing_command)
        except EnvironmentError as e:
            if e.errno == errno.EACCES:
                raise_from(errors.PermissionDeniedError(fp, write=False))
            if e.errno != errno.ENOENT or required:
                raise_from(errors.ParsingError("parsing %r" % (fp,), exception=e))
            return

        if incrementals:
            for key in econst.incrementals:
                if key in vars_dict and key in new_vars:
                    new_vars[key] = "%s %s" % (vars_dict[key], new_vars[key])
        # quirk of read_bash_dict; it returns only what was mutated.
        vars_dict.update(new_vars)
Exemplo n.º 3
0
    def default_env(self, data):
        rendered = _make_incrementals_dict()
        for parent in self.parents:
            rendered.update(parent.default_env.items())

        if data is not None:
            data = read_bash_dict(data[0], vars_dict=rendered)
            rendered.update(data.items())
        return ImmutableDict(rendered)
Exemplo n.º 4
0
    def default_env(self, data):
        rendered = _make_incrementals_dict()
        for parent in self.parents:
            rendered.update(parent.default_env.items())

        if data is not None:
            data = read_bash_dict(data, vars_dict=rendered)
            rendered.update(data.items())
        return ImmutableDict(rendered)
Exemplo n.º 5
0
def read_makeconf(mymakeconffile):
    if os.path.exists(mymakeconffile):
        try:
            return read_bash_dict(mymakeconffile, sourcing_command="source")
        except Exception as e:
            raise CatalystError("Could not parse make.conf file " +
                                mymakeconffile,
                                print_traceback=True) from e
    else:
        makeconf = {}
        return makeconf
Exemplo n.º 6
0
def collapse_envd(base):
    collapsed_d = {}
    try:
        env_d_files = sorted(listdir_files(base))
    except FileNotFoundError:
        pass
    else:
        for x in env_d_files:
            if x.endswith(".bak") or x.endswith("~") or x.startswith("._cfg") \
                    or len(x) <= 2 or not x[0:2].isdigit():
                continue
            d = read_bash_dict(pjoin(base, x))
            # inefficient, but works.
            for k, v in d.items():
                collapsed_d.setdefault(k, []).append(v)
            del d

    loc_incrementals = set(incrementals)
    loc_colon_parsed = set(colon_parsed)

    # split out env.d defined incrementals..
    # update incrementals *and* colon parsed for colon_separated;
    # incrementals on its own is space separated.

    for x in collapsed_d.pop("COLON_SEPARATED", []):
        v = x.split()
        if v:
            loc_colon_parsed.update(v)

    loc_incrementals.update(loc_colon_parsed)

    # now space.
    for x in collapsed_d.pop("SPACE_SEPARATED", []):
        v = x.split()
        if v:
            loc_incrementals.update(v)

    # now reinterpret.
    for k, v in collapsed_d.items():
        if k not in loc_incrementals:
            collapsed_d[k] = v[-1]
            continue
        if k in loc_colon_parsed:
            collapsed_d[k] = [
                _f for _f in iflatten_instance(x.split(':') for x in v) if _f
            ]
        else:
            collapsed_d[k] = [
                _f for _f in iflatten_instance(x.split() for x in v) if _f
            ]

    return collapsed_d, loc_incrementals, loc_colon_parsed
Exemplo n.º 7
0
def collapse_envd(base):
    collapsed_d = {}
    try:
        env_d_files = sorted(listdir_files(base))
    except OSError as oe:
        if oe.errno != errno.ENOENT:
            raise
    else:
        for x in env_d_files:
            if x.endswith(".bak") or x.endswith("~") or x.startswith("._cfg") \
                    or len(x) <= 2 or not x[0:2].isdigit():
                continue
            d = read_bash_dict(pjoin(base, x))
            # inefficient, but works.
            for k, v in d.iteritems():
                collapsed_d.setdefault(k, []).append(v)
            del d

    loc_incrementals = set(incrementals)
    loc_colon_parsed = set(colon_parsed)

    # split out env.d defined incrementals..
    # update incrementals *and* colon parsed for colon_separated;
    # incrementals on its own is space separated.

    for x in collapsed_d.pop("COLON_SEPARATED", []):
        v = x.split()
        if v:
            loc_colon_parsed.update(v)

    loc_incrementals.update(loc_colon_parsed)

    # now space.
    for x in collapsed_d.pop("SPACE_SEPARATED", []):
        v = x.split()
        if v:
            loc_incrementals.update(v)

    # now reinterpret.
    for k, v in collapsed_d.iteritems():
        if k not in loc_incrementals:
            collapsed_d[k] = v[-1]
            continue
        if k in loc_colon_parsed:
            collapsed_d[k] = filter(None, iflatten_instance(
                x.split(':') for x in v))
        else:
            collapsed_d[k] = filter(None, iflatten_instance(
                x.split() for x in v))

    return collapsed_d, loc_incrementals, loc_colon_parsed
Exemplo n.º 8
0
    def load_make_conf(vars_dict,
                       path,
                       allow_sourcing=False,
                       required=True,
                       allow_recurse=True,
                       incrementals=False):
        """parse make.conf files

        Args:
            vars_dict (dict): dictionary to add parsed variables to
            path (str): path to the make.conf which can be a regular file or
                directory, if a directory is passed all the non-hidden files within
                that directory are parsed in alphabetical order.
        """
        sourcing_command = 'source' if allow_sourcing else None

        if allow_recurse:
            files = sorted_scan(os.path.realpath(path),
                                follow_symlinks=True,
                                nonexistent=True,
                                hidden=False,
                                backup=False)
        else:
            files = (path, )

        for fp in files:
            try:
                new_vars = read_bash_dict(fp,
                                          vars_dict=vars_dict,
                                          sourcing_command=sourcing_command)
            except PermissionError as e:
                raise base_errors.PermissionDenied(fp, write=False) from e
            except EnvironmentError as e:
                if e.errno != errno.ENOENT or required:
                    raise config_errors.ParsingError(f"parsing {fp!r}",
                                                     exception=e) from e
                return

            if incrementals:
                for key in econst.incrementals:
                    if key in vars_dict and key in new_vars:
                        new_vars[key] = f"{vars_dict[key]} {new_vars[key]}"
            # quirk of read_bash_dict; it returns only what was mutated.
            vars_dict.update(new_vars)
Exemplo n.º 9
0
    def load_make_conf(vars_dict, path, allow_sourcing=False, required=True,
                       allow_recurse=True, incrementals=False):
        """parse make.conf files

        Args:
            vars_dict (dict): dictionary to add parsed variables to
            path (str): path to the make.conf which can be a regular file or
                directory, if a directory is passed all the non-hidden files within
                that directory are parsed in alphabetical order.
        """
        sourcing_command = 'source' if allow_sourcing else None

        if allow_recurse:
            files = sorted_scan(
                os.path.realpath(path), follow_symlinks=True, nonexistent=True,
                hidden=False, backup=False)
        else:
            files = (path,)

        for fp in files:
            try:
                new_vars = read_bash_dict(
                    fp, vars_dict=vars_dict, sourcing_command=sourcing_command)
            except PermissionError as e:
                raise base_errors.PermissionDenied(fp, write=False) from e
            except EnvironmentError as e:
                if e.errno != errno.ENOENT or required:
                    raise errors.ParsingError(f"parsing {fp!r}", exception=e) from e
                return

            if incrementals:
                for key in econst.incrementals:
                    if key in vars_dict and key in new_vars:
                        new_vars[key] = f"{vars_dict[key]} {new_vars[key]}"
            # quirk of read_bash_dict; it returns only what was mutated.
            vars_dict.update(new_vars)
Exemplo n.º 10
0
 def make_defaults(self, data):
     d = {}
     if data is not None:
         d.update(read_bash_dict(data[0]))
     return ImmutableDict(d)
Exemplo n.º 11
0
default_ldpath = ('/lib', '/lib64', '/lib32',
    '/usr/lib', '/usr/lib64', '/usr/lib32')

def collapse_envd(base):
    collapsed_d = {}
    try:
        env_d_files = sorted(listdir_files(base))
    except OSError, oe:
        if oe.errno != errno.ENOENT:
            raise
    else:
        for x in env_d_files:
            if x.endswith(".bak") or x.endswith("~") or x.startswith("._cfg") \
                or len(x) <= 2 or not x[0:2].isdigit():
                continue
            d = read_bash_dict(pjoin(base, x))
            # inefficient, but works.
            for k, v in d.iteritems():
                collapsed_d.setdefault(k, []).append(v)
            del d

    loc_incrementals = set(incrementals)
    loc_colon_parsed = set(colon_parsed)

    # split out env.d defined incrementals..
    # update incrementals *and* colon parsed for colon_seperated;
    # incrementals on it's own is space seperated.

    for x in collapsed_d.pop("COLON_SEPARATED", []):
        v = x.split()
        if v:
Exemplo n.º 12
0
 def invoke_and_close(self, handle, *args, **kwds):
     try:
         return read_bash_dict(handle, *args, **kwds)
     finally:
         if hasattr(handle, 'close'):
             handle.close()
Exemplo n.º 13
0
 def invoke_and_close(self, handle, *args, **kwds):
     try:
         return read_bash_dict(handle, *args, **kwds)
     finally:
         if hasattr(handle, "close"):
             handle.close()