Ejemplo n.º 1
0
def generate(args):
    """Produce a list of file dependencies from a manfiest and a proto
        area."""
    try:
        opts, pargs = getopt.getopt(args, "d:D:Ik:Mm?", ["help"])
    except getopt.GetoptError as e:
        usage(_("illegal global option -- {0}").format(e.opt))

    remove_internal_deps = True
    echo_manf = False
    show_missing = False
    show_usage = False
    isa_paths = []
    run_paths = []
    platform_paths = []
    dyn_tok_conv = {}
    proto_dirs = []

    for opt, arg in opts:
        if opt == "-d":
            if not os.path.isdir(arg):
                usage(_("The proto directory {0} could not be "
                        "found.".format(arg)),
                      retcode=2)
            proto_dirs.append(os.path.abspath(arg))
        elif opt == "-D":
            try:
                dyn_tok_name, dyn_tok_val = arg.split("=", 1)
            except:
                usage(_("-D arguments must be of the form " "'name=value'."))
            if not dyn_tok_name[0] == "$":
                dyn_tok_name = "$" + dyn_tok_name
            dyn_tok_conv.setdefault(dyn_tok_name, []).append(dyn_tok_val)
        elif opt == "-I":
            remove_internal_deps = False
        elif opt == "-k":
            run_paths.append(arg)
        elif opt == "-m":
            echo_manf = True
        elif opt == "-M":
            show_missing = True
        elif opt in ("--help", "-?"):
            show_usage = True
    if show_usage:
        usage(retcode=0)
    if len(pargs) > 2 or len(pargs) < 1:
        usage(_("Generate only accepts one or two arguments."))

    if "$ORIGIN" in dyn_tok_conv:
        usage(
            _("ORIGIN may not be specified using -D. It will be "
              "inferred from the\ninstall paths of the files."))

    retcode = 0

    manf = pargs[0]

    if not os.path.isfile(manf):
        usage(_("The manifest file {0} could not be found.").format(manf),
              retcode=2)

    if len(pargs) > 1:
        if not os.path.isdir(pargs[1]):
            usage(_("The proto directory {0} could not be found.").format(
                pargs[1]),
                  retcode=2)
        proto_dirs.insert(0, os.path.abspath(pargs[1]))
    if not proto_dirs:
        usage(_("At least one proto directory must be provided."), retcode=2)

    try:
        ds, es, ms, pkg_attrs = dependencies.list_implicit_deps(
            manf, proto_dirs, dyn_tok_conv, run_paths, remove_internal_deps)
    except (actions.MalformedActionError, actions.UnknownActionError) as e:
        error(
            _("Could not parse manifest {manifest} because of the "
              "following line:\n{line}").format(manifest=manf,
                                                line=e.actionstr))
        return 1
    except api_errors.ApiException as e:
        error(e)
        return 1

    if echo_manf:
        fh = open(manf, "rb")
        for l in fh:
            msg(l.rstrip())
        fh.close()

    for d in sorted(ds):
        msg(d)

    for key, value in pkg_attrs.iteritems():
        msg(actions.attribute.AttributeAction(**{key: value}))

    if show_missing:
        for m in ms:
            emsg(m)

    for e in es:
        emsg(e)
        retcode = 1
    return retcode
Ejemplo n.º 2
0
        if not os.path.isfile(manf):
                usage(_("The manifest file %s could not be found.") % manf,
                    retcode=2)

        if len(pargs) > 1:
                if not os.path.isdir(pargs[1]):
                        usage(_("The proto directory %s could not be found.") %
                            pargs[1], retcode=2)
                proto_dirs.insert(0, os.path.abspath(pargs[1]))
        if not proto_dirs:
                usage(_("At least one proto directory must be provided."),
                    retcode=2)

        try:
                ds, es, ms, pkg_attrs = dependencies.list_implicit_deps(manf,
                    proto_dirs, dyn_tok_conv, run_paths, remove_internal_deps)
        except (actions.MalformedActionError, actions.UnknownActionError), e:
                error(_("Could not parse manifest %(manifest)s because of the "
                    "following line:\n%(line)s") % { 'manifest': manf ,
                    'line': e.actionstr})
                return 1
        except api_errors.ApiException, e:
                error(e)
                return 1

        if echo_manf:
                fh = open(manf, "rb")
                for l in fh:
                        msg(l.rstrip())
                fh.close()