示例#1
0
    def run_listproperties(self, *args):
        """
        List all found global AiiDA properties.
        """
        import argparse

        from aiida.common.setup import (
            _property_table, exists_property, get_property)

        parser = argparse.ArgumentParser(
            prog=self.get_full_command_name(),
            description='List all custom properties stored in the user configuration file.')
        parser.add_argument('-a', '--all',
                            dest='all', action='store_true',
                            help="Show all properties, even if not explicitly defined, if they "
                                 "have a default value.")
        parser.set_defaults(all=False)
        parsed_args = parser.parse_args(args)

        show_all = parsed_args.all

        for prop in sorted(_property_table.keys()):
            try:
                # To enforce the generation of an exception, even if
                # there is a default value
                if show_all or exists_property(prop):
                    val = get_property(prop)
                    print "{} = {}".format(prop, val)
            except KeyError:
                pass
示例#2
0
    def run_describeproperties(self, *args):
        """
        List all valid properties that can be stored in the AiiDA config file.

        Only properties listed in the ``_property_table`` of
        ``aida.common.setup`` can be used.
        """
        from aiida.common.setup import _property_table, _NoDefaultValue

        if args:
            print >> sys.stderr, ("No parameters allowed for {}".format(
                self.get_full_command_name()))
            sys.exit(1)

        for prop in sorted(_property_table.keys()):
            if _property_table[prop][4] is None:
                valid_vals_str = ""
            else:
                valid_vals_str = " Valid values: {}.".format(",".join(
                    str(_) for _ in _property_table[prop][4]))
            if isinstance(_property_table[prop][3], _NoDefaultValue):
                def_val_string = ""
            else:
                def_val_string = " (default: {})".format(
                    _property_table[prop][3])
            print "* {} ({}): {}{}{}".format(prop, _property_table[prop][1],
                                             _property_table[prop][2],
                                             def_val_string, valid_vals_str)
示例#3
0
def devel_describeproperties():
    """
    List all valid properties that can be stored in the AiiDA config file.

    Only properties listed in the ``_property_table`` of ``aida.common.setup`` can be used.
    """
    from aiida.common.setup import _property_table, _NoDefaultValue

    for prop in sorted(_property_table.keys()):

        prop_name = _property_table[prop][1]
        prop_type = _property_table[prop][2]
        prop_default = _property_table[prop][3]
        prop_values = _property_table[prop][4]

        if prop_values is None:
            prop_values_str = ''
        else:
            prop_values_str = ' Valid values: {}.'.format(', '.join(
                str(_) for _ in prop_values))

        if isinstance(prop_default, _NoDefaultValue):
            prop_default_str = ''
        else:
            prop_default_str = ' (default: {})'.format(prop_default)

        echo.echo('* {} ({}): {}{}{}'.format(prop, prop_name, prop_type,
                                             prop_default_str,
                                             prop_values_str))
示例#4
0
    def complete_properties(self, subargs_idx, subargs):
        """
        I complete with subargs that were not used yet.
        """
        from aiida.common.setup import _property_table

        if subargs_idx == 0:
            return " ".join(_property_table.keys())
        else:
            return ""
示例#5
0
def devel_listproperties(all_entries):
    """List all the properties that are explicitly set for the current profile."""
    from aiida.common.setup import _property_table, exists_property, get_property

    for prop in sorted(_property_table.keys()):
        try:
            # To enforce the generation of an exception, even if there is a default value
            if all_entries or exists_property(prop):
                val = get_property(prop)
                echo.echo('{} = {}'.format(prop, val))
        except KeyError:
            pass
示例#6
0
 def tearDown(self):
     """Delete any properties that were set."""
     for prop in sorted(_property_table.keys()):
         if exists_property(prop):
             del_property(prop)