예제 #1
0
def _rehash_cmd(all, class_name, pks):
    try_load_dbenv()
    from aiida.orm.querybuilder import QueryBuilder

    # Get the Node class to match
    try:
        node_class = load_class(class_name)
    except ClassNotFoundException:
        click.echo("Could not load class '{}'.\nAborted!".format(class_name))
        sys.exit(1)

    # Add the filters for the class and PKs.
    qb = QueryBuilder()
    qb.append(node_class, tag='node')
    if pks:
        qb.add_filter('node', {'id': {'in': pks}})
    else:
        if not all:
            click.echo(
                "Nothing specified, nothing re-hashed.\nExplicitly specify the PK of the nodes, or use '--all'."
            )
            return

    if not qb.count():
        click.echo('No matching nodes found.')
        return
    for i, (node, ) in enumerate(qb.iterall()):
        if i % 100 == 0:
            click.echo('.', nl=False)
        node.rehash()
    click.echo('\nAll done! {} node(s) re-hashed.'.format(i + 1))
예제 #2
0
 def load_workchain(self):
     """Loads the workchain and sets up additional attributes."""
     # pylint: disable=attribute-defined-outside-init
     self.workchain_name = self.arguments[0]
     self.module_name, self.class_name = self.workchain_name.rsplit('.', 1)
     self.workchain = load_class(self.workchain_name)
     self.workchain_spec = self.workchain.spec()
예제 #3
0
def _get_config(config_file):
    try:
        with open(config_file, 'r') as f:
            config = yaml.load(f)[get_current_profile()]
    # no config file, or no config for this profile
    except (OSError, IOError, KeyError):
        return DEFAULT_CONFIG

    # validate configuration
    for key in config:
        if key not in DEFAULT_CONFIG:
            raise ValueError(
                "Configuration error: Invalid key '{}' in cache_config.yml".format(key)
            )

    # add defaults where config is missing
    for key, default_config in DEFAULT_CONFIG.items():
        config[key] = config.get(key, default_config)

    # load classes
    try:
        for key in [config_keys.enabled, config_keys.disabled]:
            config[key] = [load_class(c) for c in config[key]]
    except (ImportError, ClassNotFoundException) as err:
        raise_from(
            ConfigurationError("Unknown class given in 'cache_config.yml': '{}'".format(err)),
            err
        )
    return config
예제 #4
0
파일: rmq.py 프로젝트: DropD/plumpy
    def _on_launch(self, ch, method, properties, body):
        self._num_processes += 1

        task = self._decode(body)
        ProcClass = load_class(task['proc_class'])

        p = ProcClass.new(inputs=task['inputs'])
        p.add_process_listener(self)
        self._status_publisher.add_process(p)

        self._running_processes[p.pid] = \
            _RunningTaskInfo(p.pid, ch, method.delivery_tag)
        self._manager.start(p)
예제 #5
0
    def _on_launch(self, ch, method, properties, body):
        """
        Consumer function that processes the launch message.

        :param ch: The channel
        :param method: The method
        :param properties: The message properties
        :param body: The message body
        """
        self._num_processes += 1

        task = self._decode(body)
        proc_class = load_class(task['proc_class'])

        proc = proc_class.new(inputs=task['inputs'])
        proc.add_process_listener(self)

        self._running_processes[proc.pid] = _RunningTaskInfo(
            proc.pid, ch, method.delivery_tag)
        self._controller.insert(proc)
        self._controller.play(proc.pid)
예제 #6
0
def setup_pseudo_family(command_name, folder, group_name, group_description):
    pseudo_cmd = load_class(command_name)()
    with open(os.devnull, 'w') as devnull, redirect_stdout(devnull):
        pseudo_cmd.uploadfamily(folder, group_name, group_description)