Exemplo n.º 1
0
def list_file_templates(manager, options):
    header = ['Name', 'Use with', 'Full Path', 'Contents']
    table_data = [header]
    console('Fetching all file templates, stand by...')
    for template_name in list_templates(extensions=['template']):
        if options.name and not options.name in template_name:
            continue
        template = get_template(template_name)
        if 'entries' in template_name:
            plugin = 'notify_entries'
        elif 'task' in template_name:
            plugin = 'notify_task'
        else:
            plugin = '-'
        name = template_name.replace('.template', '').split('/')
        if len(name) == 2:
            name = name[1]
        with open(template.filename) as contents:
            table_data.append(
                [name, plugin, template.filename,
                 contents.read()])

    try:
        table = TerminalTable(options.table_type,
                              table_data,
                              wrap_columns=[2, 3],
                              drop_columns=[2, 3])
    except TerminalTableError as e:
        console('ERROR: %s' % str(e))
    else:
        console(table.output)
Exemplo n.º 2
0
def list_file_templates(manager, options):
    header = ['Name', 'Use with', 'Full Path', 'Contents']
    table_data = [header]
    console('Fetching all file templates, stand by...')
    for template_name in list_templates(extensions=['template']):
        if options.name and not options.name in template_name:
            continue
        template = get_template(template_name)
        if 'entries' in template_name:
            plugin = 'notify_entries'
        elif 'task' in template_name:
            plugin = 'notify_task'
        else:
            plugin = '-'
        name = template_name.replace('.template', '').split('/')
        if len(name) == 2:
            name = name[1]
        with io.open(template.filename) as contents:
            table_data.append([name, plugin, template.filename, contents.read()])

    try:
        table = TerminalTable(options.table_type, table_data, wrap_columns=[2, 3], drop_columns=[2, 3])
    except TerminalTableError as e:
        console('ERROR: %s' % str(e))
    else:
        console(table.output)
Exemplo n.º 3
0
def list_file_templates(manager, options):
    header = [
        'Name',
        'Use with',
        TerminalTable.Column('Full Path', overflow='fold'),
        TerminalTable.Column('Contents', overflow='ignore'),
    ]
    table = TerminalTable(*header,
                          table_type=options.table_type,
                          show_lines=True)
    console('Fetching all file templates, stand by...')
    for template_name in list_templates(extensions=['template']):
        if options.name and not options.name in template_name:
            continue
        template = get_template(template_name)
        if 'entries' in template_name:
            plugin = 'notify_entries'
        elif 'task' in template_name:
            plugin = 'notify_task'
        else:
            plugin = '-'
        name = template_name.replace('.template', '').split('/')[-1]
        with open(template.filename) as contents:
            table.add_row(name, plugin, template.filename,
                          contents.read().strip())

    console(table)