Esempio n. 1
0
def computer_config_show(computer, user, defaults, as_option_string):
    """Show the current configuration for a computer."""
    import tabulate
    from aiida.common.escaping import escape_for_bash

    transport_cls = computer.get_transport_class()
    option_list = [
        param for param in transport_cli.create_configure_cmd(
            computer.get_transport_type()).params
        if isinstance(param, click.core.Option)
    ]
    option_list = [
        option for option in option_list
        if option.name in transport_cls.get_valid_auth_params()
    ]

    if defaults:
        config = {
            option.name:
            transport_cli.transport_option_default(option.name, computer)
            for option in option_list
        }
    else:
        config = computer.get_configuration(user)

    option_items = []
    if as_option_string:
        for option in option_list:
            t_opt = transport_cls.auth_options[option.name]
            if config.get(option.name) or config.get(option.name) is False:
                if t_opt.get('switch'):
                    option_value = option.opts[-1] if config.get(
                        option.name) else '--no-{}'.format(
                            option.name.replace('_', '-'))
                elif t_opt.get('is_flag'):
                    is_default = config.get(
                        option.name) == transport_cli.transport_option_default(
                            option.name, computer)
                    option_value = option.opts[-1] if is_default else ''
                else:
                    option_value = '{}={}'.format(
                        option.opts[-1], option.type(config[option.name]))
                option_items.append(option_value)
        opt_string = ' '.join(option_items)
        echo.echo(escape_for_bash(opt_string))
    else:
        table = []
        for name in transport_cls.get_valid_auth_params():
            if name in config:
                table.append(('* ' + name, config[name]))
            else:
                table.append(('* ' + name, '-'))
        echo.echo(tabulate.tabulate(table, tablefmt='plain'))
Esempio n. 2
0
            # find all files matching pattern
            for this_file in self.glob(remotesource):
                # create the name of the link: take the last part of the path
                this_remote_dest = os.path.split(this_file)[-1]

                os.symlink(
                    os.path.join(this_file),
                    os.path.join(self.curdir, remotedestination,
                                 this_remote_dest))
        else:
            try:
                os.symlink(remotesource,
                           os.path.join(self.curdir, remotedestination))
            except OSError:
                raise OSError('!!: {}, {}, {}'.format(remotesource,
                                                      self.curdir,
                                                      remotedestination))

    def path_exists(self, path):
        """
        Check if path exists
        """
        return os.path.exists(os.path.join(self.curdir, path))

    @classmethod
    def _get_safe_interval_suggestion_string(cls, computer):
        return cls._DEFAULT_SAFE_OPEN_INTERVAL


CONFIGURE_LOCAL_CMD = transport_cli.create_configure_cmd('local')
Esempio n. 3
0
    if as_option_string:
        for option in option_list:
            t_opt = transport_cls.auth_options[option.name]
            if config.get(option.name) or config.get(option.name) is False:
                if t_opt.get('switch'):
                    option_value = option.opts[-1] if config.get(
                        option.name
                    ) else f"--no-{option.name.replace('_', '-')}"
                elif t_opt.get('is_flag'):
                    is_default = config.get(
                        option.name) == transport_cli.transport_option_default(
                            option.name, computer)
                    option_value = option.opts[-1] if is_default else ''
                else:
                    option_value = f'{option.opts[-1]}={option.type(config[option.name])}'
                option_items.append(option_value)
        opt_string = ' '.join(option_items)
        echo.echo(escape_for_bash(opt_string))
    else:
        table = []
        for name in transport_cls.get_valid_auth_params():
            if name in config:
                table.append((f'* {name}', config[name]))
            else:
                table.append((f'* {name}', '-'))
        echo.echo(tabulate.tabulate(table, tablefmt='plain'))


for ep in get_entry_points('aiida.transports'):
    computer_configure.add_command(transport_cli.create_configure_cmd(ep.name))