Exemple #1
0
def print_node_info(node, print_groups=False):
    from aiida.cmdline.common import print_node_info

###TODO
#Add a check here on the node type, otherwise it might try to access attributes such as code which are not necessarily there
#####
    print_node_info(node)

    if print_groups:
        from aiida.orm.querybuilder import QueryBuilder
        from aiida.orm.group import Group
        from aiida.orm.node import Node

        qb = QueryBuilder()
        qb.append(Node, tag='node', filters={'id': {'==': node.pk}})
        qb.append(Group, tag='groups', group_of='node',
                  project=['id', 'name'])

        click.echo("#### GROUPS:")

        if qb.count() == 0:
            click.echo("No groups found containing node {}".format(node.pk))
        else:
            res = qb.iterdict()
            for gr in res:
                gr_specs = "{} {}".format(gr['groups']['name'],
                                          gr['groups']['id'])
                click.echo(gr_specs)
Exemple #2
0
def show(identifiers, uuid, print_groups):
    from aiida.common.exceptions import NotExistent
    from aiida.common.exceptions import MultipleObjectsError

    if not is_dbenv_loaded():
        load_dbenv()

    for id in identifiers:
        try:
            if uuid:
                try:
                    n = load_node(uuid=id)
                except MultipleObjectsError:
                    click.echo("More than one node found. Please provide "
                               "longer starting pattern for uuid.", err=True)
                    return
            else:
                try:
                    ids = int(id)
                except ValueError:
                    click.echo("The pk/id can not be a string. Please provide "
                               "an integer.", err=True)
                    return
                n = load_node(pk=int(ids))
            print_node_info(n, print_groups=print_groups)
        except NotExistent as e:
            click.echo(e.message, err=True)
            sys.exit(1)

        if len(identifiers) > 1:
            click.echo("")
Exemple #3
0
    def calculation_show(self, *args):
        from aiida.common.exceptions import NotExistent
        from aiida.cmdline.common import print_node_info

        if not is_dbenv_loaded():
            load_dbenv()

        table_headers = ['Link label', 'PK', 'Type']
        for calc_pk in args:
            try:
                calc = load_node(int(calc_pk))
            except ValueError:
                print "*** {}: Not a valid PK".format(calc_pk)
                continue
            except NotExistent:
                print "*** {}: Not a valid calculation".format(calc_pk)
                continue

            print_node_info(calc)