예제 #1
0
def load_experiment_parser(opts):
    """ Parse namespace 'opts' object and execute requested 'load' command """

    user, passwd = auth.get_user_credentials(opts.username, opts.password)
    api = rest.Api(user, passwd)
    files = helpers.flatten_list_list(opts.files)
    return experiment.load_experiment(api, opts.path_file, files)
예제 #2
0
def expand_short_nodes_list(nodes_str):
    """ Expand short nodes_list '1-5+6+8-12' to a regular nodes list

    >>> expand_short_nodes_list('1-4+6+7-8')
    [1, 2, 3, 4, 6, 7, 8]

    >>> expand_short_nodes_list('1-4-5')
    Traceback (most recent call last):
    ValueError: Invalid nodes list: 1-4-5 ([0-9+-])

    >>> expand_short_nodes_list('3-3')
    Traceback (most recent call last):
    ValueError: Invalid nodes list: 3-3 ([0-9+-])

    >>> expand_short_nodes_list('3-2')
    Traceback (most recent call last):
    ValueError: Invalid nodes list: 3-2 ([0-9+-])

    >>> expand_short_nodes_list('a-b')
    Traceback (most recent call last):
    ValueError: Invalid nodes list: a-b ([0-9+-])
    """

    try:
        # '1-4+6+8-8'
        nodes_ll = [
            _expand_minus_str(minus_nodes_str)
            for minus_nodes_str in nodes_str.split('+')
        ]
        # [[1, 2, 3], [6], [12]]
        return helpers.flatten_list_list(nodes_ll)
    except ValueError:
        # invalid: 6-3 or 6-7-8 or non int values
        raise ValueError('Invalid nodes list: %s ([0-9+-])' % nodes_str)
예제 #3
0
def load_experiment_parser(opts):
    """ Parse namespace 'opts' object and execute requested 'load' command """

    user, passwd = auth.get_user_credentials(opts.username, opts.password)
    api = rest.Api(user, passwd)
    files = helpers.flatten_list_list(opts.files)
    return experiment.load_experiment(api, opts.path_file, files)
예제 #4
0
파일: common.py 프로젝트: iot-lab/cli-tools
def expand_short_nodes_list(nodes_str):
    """ Expand short nodes_list '1-5+6+8-12' to a regular nodes list

    >>> expand_short_nodes_list('1-4+6+7-8')
    [1, 2, 3, 4, 6, 7, 8]

    >>> expand_short_nodes_list('1-4-5')
    Traceback (most recent call last):
    ValueError: Invalid nodes list: 1-4-5 ([0-9+-])

    >>> expand_short_nodes_list('3-3')
    Traceback (most recent call last):
    ValueError: Invalid nodes list: 3-3 ([0-9+-])

    >>> expand_short_nodes_list('3-2')
    Traceback (most recent call last):
    ValueError: Invalid nodes list: 3-2 ([0-9+-])

    >>> expand_short_nodes_list('a-b')
    Traceback (most recent call last):
    ValueError: Invalid nodes list: a-b ([0-9+-])
    """

    try:
        # '1-4+6+8-8'
        nodes_ll = [_expand_minus_str(minus_nodes_str) for minus_nodes_str in
                    nodes_str.split('+')]
        # [[1, 2, 3], [6], [12]]
        return helpers.flatten_list_list(nodes_ll)
    except ValueError:
        # invalid: 6-3 or 6-7-8 or non int values
        raise ValueError('Invalid nodes list: %s ([0-9+-])' % nodes_str)
예제 #5
0
def list_nodes(api, exp_id, nodes_ll=None, excl_nodes_ll=None):
    """ Return the list of nodes where the command will apply """

    if nodes_ll is not None:
        # flatten lists into one
        nodes = helpers.flatten_list_list(nodes_ll)

    elif excl_nodes_ll is not None:
        # flatten lists into one
        excl_nodes = set(helpers.flatten_list_list(excl_nodes_ll))

        # remove exclude nodes from experiment nodes
        exp_nodes = set(_get_experiment_nodes_list(api, exp_id))
        nodes = list(exp_nodes - excl_nodes)
    else:
        nodes = []  # all the nodes

    return sorted(nodes, key=helpers.node_url_sort_key)
예제 #6
0
파일: common.py 프로젝트: iot-lab/cli-tools
def list_nodes(api, exp_id, nodes_ll=None, excl_nodes_ll=None):
    """ Return the list of nodes where the command will apply """

    if nodes_ll is not None:
        # flatten lists into one
        nodes = helpers.flatten_list_list(nodes_ll)

    elif excl_nodes_ll is not None:
        # flatten lists into one
        excl_nodes = set(helpers.flatten_list_list(excl_nodes_ll))

        # remove exclude nodes from experiment nodes
        exp_nodes = set(_get_experiment_nodes_list(api, exp_id))
        nodes = list(exp_nodes - excl_nodes)
    else:
        nodes = []  # all the nodes

    return sorted(nodes, key=helpers.node_url_sort_key)
예제 #7
0
def _check_sites_uniq(*site_associations):
    """Check that sites are uniq

    >>> _check_sites_uniq(site_association('grenoble', script='script'),
    ...                   site_association('lille', script='script'))
    >>> _check_sites_uniq(site_association('grenoble', script='script'),
    ...                   site_association('grenoble', script='script2'))
    Traceback (most recent call last):
    ...
    ValueError: Sites may only be given once: ['grenoble']
    """
    sites = [assocs.sites for assocs in site_associations]
    sites = helpers.flatten_list_list(sites)
    duplicates = [s for s, c in collections.Counter(sites).items() if c > 1]

    if duplicates:
        raise ValueError('Sites may only be given once: %s' % duplicates)
예제 #8
0
def _check_sites_uniq(*site_associations):
    """Check that sites are uniq

    >>> _check_sites_uniq(site_association('grenoble', script='script'),
    ...                   site_association('lille', script='script'))
    >>> _check_sites_uniq(site_association('grenoble', script='script'),
    ...                   site_association('grenoble', script='script2'))
    Traceback (most recent call last):
    ...
    ValueError: Sites may only be given once: ['grenoble']
    """
    sites = [assocs.sites for assocs in site_associations]
    sites = helpers.flatten_list_list(sites)
    duplicates = [s for s, c in collections.Counter(sites).items() if c > 1]

    if duplicates:
        raise ValueError('Sites may only be given once: %s' % duplicates)