Exemplo n.º 1
0
def _save_graph(graph_str, filepath, prune_to):
    # rez cli tools do a killpg() on sig handling, this inadvertantly causes
    # the main GUI to terminate when Writer.process is terminated! Setting this
    # variable suppresses the killpg() and stops that from happening.
    os.environ["_REZ_NO_KILLPG"] = "1"
    os.environ["_REZ_QUIET_ON_SIG"] = "1"
    if prune_to:
        graph_str = prune_graph(graph_str, prune_to)
    save_graph(graph_str, filepath)
Exemplo n.º 2
0
def _save_graph(graph_str, filepath, prune_to):
    # rez cli tools do a killpg() on sig handling, this inadvertantly causes
    # the main GUI to terminate when Writer.process is terminated! Setting this
    # variable suppresses the killpg() and stops that from happening.
    os.environ["_REZ_NO_KILLPG"] = "1"
    os.environ["_REZ_QUIET_ON_SIG"] = "1"
    if prune_to:
        graph_str = prune_graph(graph_str, prune_to)
    save_graph(graph_str, filepath)
Exemplo n.º 3
0
    def write_graph(self):
        if self.prune_to:
            graph_str = prune_graph(self.graph_str, self.prune_to)
        else:
            graph_str = self.graph_str

        error_msg = ''
        try:
            save_graph(graph_str, self.filepath)
        except Exception as e:
            error_msg = str(e)

        self.graph_written.emit(self.filepath, error_msg)
Exemplo n.º 4
0
    def write_graph(self):
        if self.prune_to:
            graph_str = prune_graph(self.graph_str, self.prune_to)
        else:
            graph_str = self.graph_str

        error_msg = ''
        try:
            save_graph(graph_str, self.filepath)
        except Exception as e:
            error_msg = str(e)

        self.graph_written.emit(self.filepath, error_msg)
Exemplo n.º 5
0
def command(opts, parser, extra_arg_groups=None):
    from rez.status import status
    from rez.utils.formatting import columnise, PackageRequest
    from rez.resolved_context import ResolvedContext
    from rez.utils.graph_utils import save_graph, view_graph, prune_graph
    from pprint import pformat

    rxt_file = opts.RXT if opts.RXT else status.context_file
    if not rxt_file:
        print >> sys.stderr, "not in a resolved environment context."
        sys.exit(1)

    if rxt_file == '-':  # read from stdin
        rc = ResolvedContext.read_from_buffer(sys.stdin, 'STDIN')
    else:
        rc = ResolvedContext.load(rxt_file)

    def _graph():
        if rc.has_graph:
            return rc.graph(as_dot=True)
        else:
            print >> sys.stderr, "The context does not contain a graph."
            sys.exit(1)

    parent_env = {} if opts.no_env else None

    if not opts.interpret:
        if opts.print_request:
            print " ".join(str(x) for x in rc.requested_packages(False))
        elif opts.print_resolve:
            print ' '.join(x.qualified_package_name
                           for x in rc.resolved_packages)
        elif opts.tools:
            rc.print_tools()
        elif opts.diff:
            rc_other = ResolvedContext.load(opts.diff)
            rc.print_resolve_diff(rc_other, True)
        elif opts.fetch:
            rc_new = ResolvedContext(rc.requested_packages(),
                                     package_paths=rc.package_paths,
                                     verbosity=opts.verbose)
            rc.print_resolve_diff(rc_new, heading=("current", "updated"))
        elif opts.which:
            cmd = opts.which
            path = rc.which(cmd, parent_environ=parent_env)
            if path:
                print path
            else:
                print >> sys.stderr, "'%s' not found in the context" % cmd
        elif opts.print_graph:
            gstr = _graph()
            print gstr
        elif opts.graph or opts.write_graph:
            gstr = _graph()
            if opts.prune_pkg:
                req = PackageRequest(opts.prune_pkg)
                gstr = prune_graph(gstr, req.name)
            func = view_graph if opts.graph else save_graph
            func(gstr, dest_file=opts.write_graph)
        else:
            rc.print_info(verbosity=opts.verbose,
                          source_order=opts.source_order,
                          show_resolved_uris=opts.show_uris)
        return

    if opts.format in ("dict", "table", "json"):
        env = rc.get_environ(parent_environ=parent_env)

        if opts.format == 'table':
            rows = [x for x in sorted(env.iteritems())]
            print '\n'.join(columnise(rows))
        elif opts.format == 'dict':
            print pformat(env)
        else:  # json
            print json.dumps(env, sort_keys=True, indent=4)
    else:
        code = rc.get_shell_code(shell=opts.format,
                                 parent_environ=parent_env,
                                 style=OutputStyle[opts.style])
        print code
Exemplo n.º 6
0
Arquivo: context.py Projeto: rvsiy/rez
def command(opts, parser, extra_arg_groups=None):
    from rez.status import status
    from rez.utils.formatting import columnise, PackageRequest
    from rez.resolved_context import ResolvedContext
    from rez.utils.graph_utils import save_graph, view_graph, prune_graph
    from pprint import pformat

    rxt_file = opts.RXT if opts.RXT else status.context_file
    if not rxt_file:
        print >> sys.stderr, "not in a resolved environment context."
        sys.exit(1)

    if rxt_file == '-':  # read from stdin
        rc = ResolvedContext.read_from_buffer(sys.stdin, 'STDIN')
    else:
        rc = ResolvedContext.load(rxt_file)

    def _graph():
        if rc.has_graph:
            return rc.graph(as_dot=True)
        else:
            print >> sys.stderr, "The context does not contain a graph."
            sys.exit(1)

    parent_env = {} if opts.no_env else None

    if not opts.interpret:
        if opts.print_request:
            print " ".join(str(x) for x in rc.requested_packages(False))
        elif opts.print_resolve:
            print ' '.join(x.qualified_package_name for x in rc.resolved_packages)
        elif opts.tools:
            rc.print_tools()
        elif opts.diff:
            rc_other = ResolvedContext.load(opts.diff)
            rc.print_resolve_diff(rc_other, True)
        elif opts.fetch:
            rc_new = ResolvedContext(rc.requested_packages(),
                                     package_paths=rc.package_paths,
                                     verbosity=opts.verbose)
            rc.print_resolve_diff(rc_new, heading=("current", "updated"))
        elif opts.which:
            cmd = opts.which
            path = rc.which(cmd, parent_environ=parent_env)
            if path:
                print path
            else:
                print >> sys.stderr, "'%s' not found in the context" % cmd
        elif opts.print_graph:
            gstr = _graph()
            print gstr
        elif opts.graph or opts.write_graph:
            gstr = _graph()
            if opts.prune_pkg:
                req = PackageRequest(opts.prune_pkg)
                gstr = prune_graph(gstr, req.name)
            func = view_graph if opts.graph else save_graph
            func(gstr, dest_file=opts.write_graph)
        else:
            rc.print_info(verbosity=opts.verbose,
                          source_order=opts.source_order,
                          show_resolved_uris=opts.show_uris)
        return

    if opts.format == 'table':
        env = rc.get_environ(parent_environ=parent_env)
        rows = [x for x in sorted(env.iteritems())]
        print '\n'.join(columnise(rows))
    elif opts.format == 'dict':
        env = rc.get_environ(parent_environ=parent_env)
        print pformat(env)
    else:
        code = rc.get_shell_code(shell=opts.format,
                                 parent_environ=parent_env,
                                 style=OutputStyle[opts.style])
        print code