def action_purge(options): with Session() as session: regexp_list = get_list_by_exact_name(options.list_name) if not regexp_list: console('Could not find regexp list with name {}'.format(options.list_name)) return console('Deleting list %s' % options.list_name) session.delete(regexp_list)
def action_del(options): with Session() as session: regexp_list = get_list_by_exact_name(options.list_name) if not regexp_list: console('Could not find regexp list with name {}'.format(options.list_name)) return regexp = get_regexp(list_id=regexp_list.id, regexp=options.regexp, session=session) if regexp: console('Removing regexp {} from list {}'.format(options.regexp, options.list_name)) session.delete(regexp) else: console('Could not find regexp {} in list {}'.format(options.movie_title, options.list_name)) return
def action_add(options): with Session() as session: regexp_list = get_list_by_exact_name(options.list_name) if not regexp_list: console('Could not find regexp list with name {}, creating'.format(options.list_name)) regexp_list = create_list(options.list_name, session=session) regexp = get_regexp(list_id=regexp_list.id, regexp=options.regexp, session=session) if not regexp: console("Adding regexp {} to list {}".format(options.regexp, regexp_list.name)) add_to_list_by_name(regexp_list.name, options.regexp, session=session) console('Successfully added regexp {} to regexp list {} '.format(options.regexp, regexp_list.name)) else: console("Regexp {} already exists in list {}".format(options.regexp, regexp_list.name))
def action_list(options): """List regexp list""" with Session() as session: regexp_list = get_list_by_exact_name(options.list_name) if not regexp_list: console('Could not find regexp list with name {}'.format(options.list_name)) return header = ['Regexp'] table_data = [header] regexps = get_regexps_by_list_id(regexp_list.id, order_by='added', descending=True, session=session) for regexp in regexps: regexp_row = [regexp.regexp or ''] table_data.append(regexp_row) table = TerminalTable(options.table_type, table_data) try: console(table.output) except TerminalTableError as e: console('ERROR: %s' % str(e))