def use_create_table(items,
                     fields,
                     field_names,
                     gen_tags,
                     tag_str,
                     item_data=None,
                     add_item_to_item_data=False,
                     add_exit=False,
                     prompt=None,
                     style=None,
                     default_choice=None,
                     default_action=TABLE_RETURN_ROW):

    # prompt = None
    tbl = create_table(items,
                       fields,
                       field_names=field_names,
                       gen_tags=gen_tags,
                       tag_str=tag_str,
                       item_data=item_data,
                       add_item_to_item_data=add_item_to_item_data,
                       add_exit=add_exit,
                       style=style,
                       default_choice=default_choice,
                       default_action=default_action,
                       prompt=prompt)
    print()
    recipe_ti = tbl.get_table_choice(commands=None)
    print(recipe_ti)
    return recipe_ti
Beispiel #2
0
def add_event_action(row, action_item):
    events = action_dict['events']
    event_types = action_dict['event_types']
    cmds = action_dict['commands']
    desc = ci.get_string(prompt="Event description? ", commands=cmds)
    tbl = ci.create_table(event_types, ["name", "desc"], ["Name", "Desc"],
                          add_item_to_item_data=True)
    event_type = tbl.get_table_choice(prompt='Type? ', commands=cmds)
    date = ci.get_date(prompt='Date? ', default='today', commands=cmds)
    type_id = event_type.item_data['item'].id
    events.append(Event(len(events) + 1, date, desc, type_id))
def get_endpoint_groups_action(row, action_dict):
    # list endpoints as a table
    fields = 'group groupTitle'.split()
    field_names = [f.capitalize() for f in fields]
    tbl = ci.create_table(items=action_dict['endpoints'],
                          fields=fields,
                          field_names=field_names,
                          style=action_dict['style'],
                          gen_tags=True,
                          default_action=show_group_endpoints_action,
                          add_item_to_item_data=True,
                          add_exit=True,
                          prompt='Chooose an endpoint')
    tbl.run()
Beispiel #4
0
def rewrite_parts_and_show_post_table(c, did, wvm, eid, fields,
                                      filtered_parts):
    if ci.get_yes_no(
            prompt=
            'Do you want to re-write the part numbers with the part names',
            default='no') == 'yes':
        rewrite_part_numbers(c, did, filtered_parts)
        # rewrite_top_level_part_numbers(c, did, top_level_parts)

        # show results
        print('\nParts after setting part numbers:')
        filtered_part_set = {part['name'] for part in filtered_parts}

        bom = c.get_assembly_bom(did, wvm, eid)
        bom_json = json.loads(bom.text)
        changed_parts = [
            part for part in bom_json['bomTable']['items']
            if part['name'] in filtered_part_set
        ]

        # for part in top_level_parts:
        #     changed_parts.append(part)

        for part in changed_parts:
            part['partId'] = part['itemSource']['partId']
            part['elementId'] = part['itemSource']['elementId']

        style = ci.TableStyle(show_border=True,
                              hrules=ci.RULE_NONE,
                              rows_per_page=None)
        tbl = ci.create_table(changed_parts,
                              fields=fields,
                              field_names=fields,
                              gen_tags=None,
                              item_data=None,
                              add_item_to_item_data=True,
                              title=None,
                              prompt=None,
                              default_choice=None,
                              default_str=None,
                              default_action='table_item',
                              style=style)
        tbl.show_table()
        sys.exit(0)
    else:
        print('Exiting without re-writing part numbers\n')
        sys.exit(0)
def show_group_endpoints_action(row, action_dict):
    print(f'Received row for endpoint: {row.item_data["item"]["groupTitle"]}')

    style = ci.TableStyle(rows_per_page=99)
    items = row.item_data['item']['endpoints']
    fields = 'title name type url'.split()
    field_names = [f.capitalize() for f in fields]
    tbl = ci.create_table(items=items,
                          fields=fields,
                          field_names=field_names,
                          style=style,
                          gen_tags=True,
                          default_action=show_individual_endpoint_action,
                          add_item_to_item_data=True,
                          add_exit=ci.TABLE_ADD_RETURN,
                          prompt='Chooose an endpoint')
    tbl.run()
    def test_get_table_choice(self):
        input_str = '1'

        items = {
            1: {
                "episode": 1,
                "name": "Whither Canada?",
                "date": "5 October, 1969",
                "season": 1
            },
            2: {
                "episode": 4,
                "name": "Owl Stretching Time",
                "date": "26 October, 1969",
                "season": 1
            },
            3: {
                "episode": 15,
                "name": "The Spanish Inquisition",
                "date": "22 September, 1970",
                "season": 2
            },
            4: {
                "episode": 35,
                "name": "The Nude Organist",
                "date": "14 December, 1972",
                "season": 2
            }
        }

        fields = 'episode name date'.split()
        field_names = 'Episode Name Date'.split()
        tbl = create_table(items,
                           fields,
                           field_names,
                           add_item_to_item_data=True,
                           title='And Now For Something Completely different')

        with redirect_stdin(StringIO(input_str)):
            choice = tbl.get_table_choice()
            item = choice.item_data["item"]
            print('{}: {}'.format(item['name'], item['season']))
        assert (item['name'] == 'Whither Canada?')
Beispiel #7
0
def list_event_action(row, action_item):
    events = action_dict['events']
    event_types = action_dict['event_types']

    if len(events) == 0:
        print('\nno events\n')
        return

    et_dict = {item.id: item.name for item in event_types}
    items = []
    for e in events:
        date = e.date.strftime('%x')
        etype = et_dict[e.type]
        items.append({'id': e.id, 'date': date, 'desc': e.desc, 'type': etype})

    fields = ['date', 'desc', 'type']
    field_names = ['Date', 'Desc', 'Type']
    tbl = ci.create_table(items, fields, field_names, title='Events')
    print('\n')
    tbl.show_table()
    print('\n')
Beispiel #8
0
def show_pre_table(fields, parts_iterable, top_level: bool):
    style = ci.TableStyle(show_border=True,
                          hrules=ci.RULE_NONE,
                          rows_per_page=None)
    tbl = ci.create_table(parts_iterable,
                          fields=fields,
                          field_names=fields,
                          gen_tags=None,
                          item_data=None,
                          add_item_to_item_data=True,
                          title=None,
                          prompt=None,
                          default_choice=None,
                          default_str=None,
                          default_action='table_item',
                          style=style)

    if top_level is True:
        print('\nTop level parts identified to set:')
    else:
        print('\nParts identified to set:')
    tbl.show_table()
def show_individual_endpoint_action(row, action_dict):
    """
    row.item_data['item'] is list of: type, url, title, name, description, group, version, permission (list), success (dict),
        groupTitle, header (dict), parameter (dict)
    """
    ri = row.item_data["item"]
    deprecated, replaced_by = is_deprecated(ri)

    print(f'\nname: {ri["name"]}\ttitle: {ri["title"]}')
    print(f'description: {ri["description"]}')
    print(f'url: {ri["url"]}')
    print(f'type: {ri["type"]}\tversion: {ri["version"]}')
    if deprecated:
        replaced_by_str = 'True' + ' - replaced by: ' + replaced_by
        print(f'deprecated: {replaced_by_str}')

    permissions = ', '.join([i['name'] for i in ri['permission']])
    print(f'permissions: {permissions}')

    if 'success' in ri:
        # Response is a dict with multiple items. Each looks like Response
        print('\nSuccess Entries:\n')
        for field in ri['success']['fields'].items():
            fields = 'field type optional description'.split()
            field_names = [f.capitalize() for f in fields]
            tbl = ci.create_table(items=field[1],
                                  fields=fields,
                                  field_names=field_names,
                                  gen_tags=False,
                                  add_exit=False,
                                  title=f'{field[0]}:')
            tbl.show_table()

    if 'header' in ri:
        header = ri['header']['fields']['Header']
        fields = 'field type optional defaultValue description'.split()
        field_names = [f.capitalize() for f in fields]
        tbl = ci.create_table(items=header,
                              fields=fields,
                              field_names=field_names,
                              gen_tags=False,
                              add_exit=False,
                              title='\nHeader:')
        tbl.show_table()

    if 'parameter' in ri:
        # add body - list of: type optional field description
        if 'Body' in ri['parameter']['fields']:
            body = ri['parameter']['fields']['Body']
            fields = 'field type optional description'.split()
            field_names = [f.capitalize() for f in fields]
            tbl = ci.create_table(items=body,
                                  fields=fields,
                                  field_names=field_names,
                                  gen_tags=False,
                                  add_exit=False,
                                  title='PathParam:')
            tbl.show_table()

        if 'PathParam' in ri['parameter']['fields']:
            path_param = ri['parameter']['fields']['PathParam']
            fields = 'field type optional description'.split()
            field_names = [f.capitalize() for f in fields]
            tbl = ci.create_table(items=path_param,
                                  fields=fields,
                                  field_names=field_names,
                                  gen_tags=False,
                                  add_exit=False,
                                  title='PathParam:')
            tbl.show_table()

        if 'QueryParam' in ri['parameter']['fields']:
            query_param = ri['parameter']['fields']['QueryParam']
            fields = 'field type optional defaultValue description'.split()
            field_names = [f.capitalize() for f in fields]
            tbl = ci.create_table(items=query_param,
                                  fields=fields,
                                  field_names=field_names,
                                  gen_tags=False,
                                  add_exit=False,
                                  title='QueryParam:')
            tbl.show_table()

        if 'error' in ri:
            # 'error' - dict with 'fields' each with group, optional, field, desciption
            errors = ri['error']['fields']
            for error in errors.items():
                fields = 'field optional description'.split()
                field_names = [f.capitalize() for f in fields]
                tbl = ci.create_table(items=error[1],
                                      fields=fields,
                                      field_names=field_names,
                                      gen_tags=False,
                                      add_exit=False,
                                      title=error[0])
                tbl.show_table()

    print('\n\n\n')