Пример #1
0
def get_column_names_search(doc, table_name, pattern, regex=False):
    """Deletes page in document with pattern in name
    args:
    doc (Spotfire document instance): document to read from
    pattern (string): pattern to find in page_name
    """
    column_names = get_column_names(doc, table_name)
    search_column_names = []
    LOGGER.debug('Searching for pattern %s', pattern)
    for column_name in column_names:
        LOGGER.debug(column_name)
        found = False
        if regex:
            match =re.match(r'{}'.format(pattern), column_name)

            if match:
                found = True
        else:
            if pattern in column_name:
                found = True

        if found:
            LOGGER.debug('This is a match %s', column_name)
            search_column_names.append(column_name)
    LOGGER.debug('Columns matching  pattern %s: %s',
                 pattern, list_string(search_column_names))
    return search_column_names
Пример #2
0
def announce_no_data(name, valid_names, data_type):
    """Announcing that no data is found in a message box

       args:
           name     : str
           valid_data: list
           data_type :  str, name of data type not found

       raises: AttributeError if data_type is not in valid_types
    """

    valid_types = sorted(item_dict())
    LOGGER.debug(valid_types)
    if data_type not in valid_types:

        raise AttributeError('No such data type in spotfire project')

    else:
        heading = 'Data does not exist!'
        message = ('{} with name {} does not exist,\n please choose among' +
                   ' the following {}').format(data_type, name,
                                               list_string(valid_names))

        ok_message(message, heading)
        LOGGER.debug('Written message')
Пример #3
0
def no_deletion(del_list, item_type, extra_text=''):
    """ Confirms no deletion of items
    args:
    del_list (list): list of items to delete
    item_type (str): type to delete
    extra_text (str): extra text to add
    """
    heading = 'No deletion'
    message = ('You decided not to delete {} {}' + 'from {}').format(
        list_string(del_list), item_type, extra_text)
    ok_message(message, heading)
Пример #4
0
def find_item(item_type):
    """returns string to confirm items"""
    items = item_dict()
    LOGGER.debug(items)
    LOGGER.debug('Extracting with |%s|', item_type)
    item_types = None
    try:
        item_types = items[item_type]
    except KeyError:
        LOGGER.warning('This was not right')
        raise KeyError('%s is not in {}'.format(item_type, list_string(items)))
    return item_types
Пример #5
0
def rename_columns(doc, table_name, orig_names, new_names):
    """Renames selected columns in data table
    args:
    doc (Spotfire document instance): document to read from
    """
    LOGGER.debug('--------------')
    LOGGER.debug(orig_names)
    LOGGER.debug(new_names)
    if orig_names and new_names:
        heading = 'Renaming columns in table {}!'.format(table_name)
        message = ('Do you want to rename' +
                   ' {} to {}?').format(list_string(orig_names),
                                        list_string(new_names))
        confirmation = yes_no_message(message, heading)
        if confirmation:
            table = get_table(doc, table_name)
            switch_dict = dict(zip(orig_names, new_names))

            LOGGER.debug(switch_dict)

            for col in table.Columns:
                col_name = col.Name
                # This does not work in spotfire 10..
                #LOGGER.debug('%s: %s', col_name, switch_dict[col_name])

                if col_name in orig_names:
                    try:
                        new_name = switch_dict[col_name]
                        col.Name = new_name
                        LOGGER.debug('Moving %s to %s', col, new_name)
                    except KeyError:
                        LOGGER.warning('%s not in list', col)
                else:
                    LOGGER.debug('Skipping %s', col_name)
            LOGGER.debug('Done with swithing')
      else:
        heading = 'Nothing to replace!!'
        message = 'Couldnt find anything to replace in rename columns'
        ok_message(message, heading)
Пример #6
0
def deletion_message(del_list, item_type, extra_text=''):
    """Asks for permision to delete elements
    args:
    del_list (list): list of items to delete
    item_type (str): type to delete
    extra_text (str): extra text to add
    """
    LOGGER.debug('Deletion of type %s', item_type)
    del_type = find_item(item_type)
    LOGGER.debug('Passing on %s', del_type)
    heading = 'Deletion of {}'.format(del_type)
    message = ('You are about to delete the following items \n{}\n' +
               ' {} do you want to proceed?').format(list_string(del_list),
                                                     extra_text)

    confirmation = yes_no_message(message, heading)
    LOGGER.debug('Received answer')
    LOGGER.debug(confirmation)
    return confirmation
Пример #7
0
def delete_pages_search(doc, pattern, regex=False):
    """Deletes page in document with pattern in name
    args:
    doc (Spotfire document instance): document to read from
    pattern (string): pattern to find in page_name
    """
    page_names = get_page_names(doc)
    del_page_names = []
    for page_name in page_names:
        found = False
        if regex:
            match = re.match(r'{}'.format(pattern), page_name)
            if match:
                found = True
        else:
            if pattern in page_name:
                found = True

        if found:
            del_page_names.append(page_name)
    LOGGER.debug('Pages matching  pattern %s: %s', pattern,
                 list_string(del_page_names))

    delete_pages(doc, del_page_names)