Exemplo n.º 1
0
def entry_list_show(options):
    with Session() as session:
        try:
            entry_list = get_list_by_exact_name(options.list_name, session=session)
        except NoResultFound:
            console('Could not find entry list with name {}'.format(options.list_name))
            return

        try:
            entry = get_entry_by_id(entry_list.id, int(options.entry), session=session)
        except NoResultFound:
            console(
                'Could not find matching entry with ID {} in list `{}`'.format(int(options.entry), options.list_name))
            return
        except ValueError:
            entry = get_entry_by_title(entry_list.id, options.entry, session=session)
            if not entry:
                console(
                    'Could not find matching entry with title `{}` in list `{}`'.format(options.entry,
                                                                                        options.list_name))
                return
        header = ['Field name', 'Value']
        table_data = [header]
        for k, v in sorted(entry.entry.items()):
            table_data.append([k, str(v)])
    table = TerminalTable(options.table_type, table_data, wrap_columns=[1])
    table.table.justify_columns[0] = 'center'
    try:
        console(table.output)
    except TerminalTableError as e:
        console('ERROR: %s' % str(e))
Exemplo n.º 2
0
def entry_list_del(options):
    with Session() as session:
        try:
            entry_list = get_list_by_exact_name(options.list_name)
        except NoResultFound:
            console("Could not find entry list with name `{}`".format(options.list_name))
            return
        try:
            db_entry = get_entry_by_id(entry_list.id, int(options.entry), session=session)
        except NoResultFound:
            console(
                "Could not find matching entry with ID {} in list `{}`".format(int(options.entry), options.list_name)
            )
            return
        except ValueError:
            db_entry = get_entry_by_title(entry_list.id, options.entry, session=session)
            if not db_entry:
                console(
                    "Could not find matching entry with title `{}` in list `{}`".format(
                        options.entry, options.list_name
                    )
                )
                return
        console("Removing entry `%s` from list %s" % (db_entry.title, options.list_name))
        session.delete(db_entry)
Exemplo n.º 3
0
def entry_list_add(options):
    with Session() as session:
        try:
            entry_list = plugin_entry_list.get_list_by_exact_name(options.list_name, session=session)
        except NoResultFound:
            console('Could not find entry list with name `{}`, creating'.format(options.list_name))
            entry_list = plugin_entry_list.EntryListList(name=options.list_name)
            session.add(entry_list)
        session.merge(entry_list)
        session.commit()
        title = options.entry_title
        entry = {'title': options.entry_title, 'url': options.url}
        db_entry = plugin_entry_list.get_entry_by_title(list_id=entry_list.id, title=title, session=session)
        if db_entry:
            console("Entry with the title `{}` already exist with list `{}`. Will replace identifiers if given".format(
                title, entry_list.name))
            output = 'Successfully updated entry `{}` to entry list `{}` '.format(title, entry_list.name)
        else:
            console("Adding entry with title `{}` to list `{}`".format(title, entry_list.name))
            db_entry = plugin_entry_list.EntryListEntry(entry=entry, entry_list_id=entry_list.id)
            session.add(db_entry)
            output = 'Successfully added entry `{}` to entry list `{}` '.format(title, entry_list.name)
        if options.attributes:
            console('Adding attributes to entry `{}`'.format(title))
            for identifier in options.attributes:
                for k, v in identifier.items():
                    entry[k] = v
            db_entry.entry = entry
        console(output)
Exemplo n.º 4
0
def entry_list_show(options):
    with Session() as session:
        try:
            entry_list = get_list_by_exact_name(options.list_name,
                                                session=session)
        except NoResultFound:
            console('Could not find entry list with name {}'.format(
                options.list_name))
            return

        try:
            entry = get_entry_by_id(entry_list.id,
                                    int(options.entry),
                                    session=session)
        except NoResultFound:
            console(
                'Could not find matching entry with ID {} in list `{}`'.format(
                    int(options.entry), options.list_name))
            return
        except ValueError:
            entry = get_entry_by_title(entry_list.id,
                                       options.entry,
                                       session=session)
            if not entry:
                console(
                    'Could not find matching entry with title `{}` in list `{}`'
                    .format(options.entry, options.list_name))
                return

        console('Showing fields for entry ID {}'.format(options.list_name))
        console('-' * 79)
        for k, v in sorted(entry.entry.items()):
            console('{}: {}'.format(k.upper(), v))
Exemplo n.º 5
0
def entry_list_add(options):
    with Session() as session:
        try:
            entry_list = get_list_by_exact_name(options.list_name, session=session)
        except NoResultFound:
            console('Could not find entry list with name `{}`, creating'.format(options.list_name))
            entry_list = EntryListList(name=options.list_name)
            session.add(entry_list)
        session.merge(entry_list)
        session.commit()
        title = options.entry_title
        entry = {'title': options.entry_title, 'url': options.url}
        db_entry = get_entry_by_title(list_id=entry_list.id, title=title, session=session)
        if db_entry:
            console("Entry with the title `{}` already exist with list `{}`. Will replace identifiers if given".format(
                title, entry_list.name))
            output = 'Successfully updated entry `{}` to entry list `{}` '.format(title, entry_list.name)
        else:
            console("Adding entry with title `{}` to list `{}`".format(title, entry_list.name))
            db_entry = EntryListEntry(entry=entry, entry_list_id=entry_list.id)
            session.add(db_entry)
            output = 'Successfully added entry `{}` to entry list `{}` '.format(title, entry_list.name)
        if options.attributes:
            console('Adding attributes to entry `{}`'.format(title))
            for identifier in options.attributes:
                for k, v in identifier.items():
                    entry[k] = v
            db_entry.entry = entry
        console(output)
Exemplo n.º 6
0
def entry_list_show(options):
    with Session() as session:
        try:
            entry_list = get_list_by_exact_name(options.list_name, session=session)
        except NoResultFound:
            console('Could not find entry list with name {}'.format(options.list_name))
            return

        try:
            entry = get_entry_by_id(entry_list.id, int(options.entry), session=session)
        except NoResultFound:
            console(
                'Could not find matching entry with ID {} in list `{}`'.format(int(options.entry), options.list_name))
            return
        except ValueError:
            entry = get_entry_by_title(entry_list.id, options.entry, session=session)
            if not entry:
                console(
                    'Could not find matching entry with title `{}` in list `{}`'.format(options.entry,
                                                                                        options.list_name))
                return

        console('Showing fields for entry ID {}'.format(options.list_name))
        console('-' * 79)
        for k, v in sorted(entry.entry.items()):
            console('{}: {}'.format(k.upper(), v))
Exemplo n.º 7
0
def entry_list_show(options):
    with Session() as session:
        try:
            entry_list = plugin_entry_list.get_list_by_exact_name(options.list_name, session=session)
        except NoResultFound:
            console('Could not find entry list with name {}'.format(options.list_name))
            return

        try:
            entry = plugin_entry_list.get_entry_by_id(entry_list.id, int(options.entry), session=session)
        except NoResultFound:
            console(
                'Could not find matching entry with ID {} in list `{}`'.format(int(options.entry), options.list_name))
            return
        except ValueError:
            entry = plugin_entry_list.get_entry_by_title(entry_list.id, options.entry, session=session)
            if not entry:
                console(
                    'Could not find matching entry with title `{}` in list `{}`'.format(options.entry,
                                                                                        options.list_name))
                return
        header = ['Field name', 'Value']
        table_data = [header]
        for k, v in sorted(entry.entry.items()):
            table_data.append([k, str(v)])
    try:
        table = TerminalTable(options.table_type, table_data, wrap_columns=[1])
        table.table.justify_columns[0] = 'center'
        console(table.output)
    except TerminalTableError as e:
        console('ERROR: %s' % str(e))
Exemplo n.º 8
0
def entry_list_del(options):
    with Session() as session:
        try:
            entry_list = get_list_by_exact_name(options.list_name)
        except NoResultFound:
            console('Could not find entry list with name `{}`'.format(
                options.list_name))
            return
        try:
            db_entry = get_entry_by_id(entry_list.id,
                                       int(options.entry),
                                       session=session)
        except NoResultFound:
            console(
                'Could not find matching entry with ID {} in list `{}`'.format(
                    int(options.entry), options.list_name))
            return
        except ValueError:
            db_entry = get_entry_by_title(entry_list.id,
                                          options.entry,
                                          session=session)
            if not db_entry:
                console(
                    'Could not find matching entry with title `{}` in list `{}`'
                    .format(options.entry, options.list_name))
                return
        console('Removing entry `%s` from list %s' %
                (db_entry.title, options.list_name))
        session.delete(db_entry)
Exemplo n.º 9
0
 def post(self, session=None):
     """ Create a new entry list """
     data = request.json
     name = data.get('name')
     new_list = False
     try:
         el.get_list_by_exact_name(name=name, session=session)
     except NoResultFound:
         new_list = True
     if not new_list:
         raise Conflict('list with name \'%s\' already exists' % name)
     entry_list = el.EntryListList(name=name)
     session.add(entry_list)
     session.commit()
     resp = jsonify(entry_list.to_dict())
     resp.status_code = 201
     return resp
Exemplo n.º 10
0
 def post(self, session=None):
     """ Create a new entry list """
     data = request.json
     name = data.get('name')
     new_list = False
     try:
         el.get_list_by_exact_name(name=name, session=session)
     except NoResultFound:
         new_list = True
     if not new_list:
         raise Conflict('list with name \'%s\' already exists' % name)
     entry_list = el.EntryListList(name=name)
     session.add(entry_list)
     session.commit()
     resp = jsonify(entry_list.to_dict())
     resp.status_code = 201
     return resp
Exemplo n.º 11
0
def entry_list_purge(options):
    with Session() as session:
        try:
            entry_list = plugin_entry_list.get_list_by_exact_name(options.list_name)
        except NoResultFound:
            console('Could not find entry list with name `{}`'.format(options.list_name))
            return
        console('Deleting list %s' % options.list_name)
        session.delete(entry_list)
Exemplo n.º 12
0
def entry_list_purge(options):
    with Session() as session:
        try:
            entry_list = get_list_by_exact_name(options.list_name)
        except NoResultFound:
            console('Could not find entry list with name `{}`'.format(options.list_name))
            return
        console('Deleting list %s' % options.list_name)
        session.delete(entry_list)
Exemplo n.º 13
0
def entry_list_list(options):
    """List entry list"""
    with Session() as session:
        try:
            entry_list = get_list_by_exact_name(options.list_name, session=session)
        except NoResultFound:
            console('Could not find entry list with name {}'.format(options.list_name))
            return
        console('Entries for list `{}`:'.format(options.list_name))
        console('-' * 79)
        for entry in get_entries_by_list_id(entry_list.id, order_by='added', descending=True, session=session):
            console('{:2d}: {}, {} fields'.format(entry.id, entry.title, len(entry.entry)))
Exemplo n.º 14
0
 def post(self, session=None):
     """ Create a new entry list """
     data = request.json
     name = data.get('name')
     entry_list = el.get_list_by_exact_name(name=name, session=session)
     if entry_list:
         return {'status': 'error',
                 'message': "list with name '%s' already exists" % name}, 500
     entry_list = el.EntryListList(name=name)
     session.add(entry_list)
     session.commit()
     resp = jsonify(entry_list.to_dict())
     resp.status_code = 201
     return resp
Exemplo n.º 15
0
def entry_list_list(options):
    """List entry list"""
    with Session() as session:
        try:
            entry_list = get_list_by_exact_name(options.list_name, session=session)
        except NoResultFound:
            console('Could not find entry list with name {}'.format(options.list_name))
            return
        header = ['#', 'Title', '# of fields']
        table_data = [header]
        for entry in get_entries_by_list_id(entry_list.id, order_by='added', descending=True, session=session):
            table_data.append([entry.id, entry.title, len(entry.entry)])
    table = TerminalTable(options.table_type, table_data)
    try:
        console(table.output)
    except TerminalTableError as e:
        console('ERROR: %s' % str(e))
Exemplo n.º 16
0
def entry_list_list(options):
    """List entry list"""
    with Session() as session:
        try:
            entry_list = plugin_entry_list.get_list_by_exact_name(options.list_name, session=session)
        except NoResultFound:
            console('Could not find entry list with name {}'.format(options.list_name))
            return
        header = ['#', 'Title', '# of fields']
        table_data = [header]
        for entry in plugin_entry_list.get_entries_by_list_id(entry_list.id, order_by='added', descending=True,
                                                              session=session):
            table_data.append([entry.id, entry.title, len(entry.entry)])
    try:
        table = TerminalTable(options.table_type, table_data)
        console(table.output)
    except TerminalTableError as e:
        console('ERROR: %s' % str(e))
Exemplo n.º 17
0
def entry_list_list(options):
    """List entry list"""
    with Session() as session:
        try:
            entry_list = get_list_by_exact_name(options.list_name,
                                                session=session)
        except NoResultFound:
            console('Could not find entry list with name {}'.format(
                options.list_name))
            return
        console('Entries for list `{}`:'.format(options.list_name))
        console('-' * 79)
        for entry in get_entries_by_list_id(entry_list.id,
                                            order_by='added',
                                            descending=True,
                                            session=session):
            console('{:2d}: {}, {} fields'.format(entry.id, entry.title,
                                                  len(entry.entry)))