Ejemplo n.º 1
0
def tag_options(ctx, args, incomplete):
    tag_list = []
    db = tagdb.db(notes_dir)
    all_tags = db.get_all_tags()
    for tag in all_tags:
        tag_list.append(tag['name'])
    return [k for k in tag_list if incomplete in k]
Ejemplo n.º 2
0
def search(tags, output, form):
    """ Searches database for given tags """
    notes_dir = base_dir + form + '/'
    db = tagdb.db(notes_dir)
    items = db.get_items_with_tags(tags)
    if not items:
        click.echo('[-] No matching items.')
        exit()
    if output:
        outdir = output + '/noted_out-' + '+'.join(tags)
        if os.path.exists(outdir):
            print('[-] Outdir already exists. Delete', outdir, 'and try again. Exiting.')
            exit()
        print('[+] Found', len(items), 'matches. Creating output directory.')
        os.makedirs(outdir)
        for item in items:
            filename = item['file'].split('/')[-1]
            outfile = outdir + '/' + filename
            print('[+] Creating symlink for', filename)
            os.symlink(item['file'], outfile)
        print('[+] Search complete.')
        exit()
    all_items = [['title', 'category', 'file']]
    for item in items:
        details_list = []
        for key, info in item.items():
            details_list.append(info)
        all_items.append(details_list)                
    print(AsciiTable(all_items).table)
Ejemplo n.º 3
0
def view_tags():
    """ View all tags currently in the database. """
    db = tagdb.db(notes_dir)
    all_tags = [ x['name'] for x in db.get_all_tags() ]
    alphabet_sorted_tags = sorted(all_tags)
    # Breaking this down: itertools.groupby()
    tags_in_lists = [alphabet_sorted_tags[i:i+3] for i in range(0, len(alphabet_sorted_tags), 3)]
    table = AsciiTable(tags_in_lists)
    table.inner_heading_row_border = False
    print(table.table)
Ejemplo n.º 4
0
def add_bugreport(category, title, tags, resources):
    """ Add a new Bug Report"""
    note_type = 'BugReports'
    notes_dir = base_dir + note_type + '/'
    resources_prepended = ['* {0}'.format(x) for x in resources]
    formatted_resources = '\n'.join(resources_prepended)
    passthrough_dict = {'category': category, 'title': title, 'tags': tags, 'resources': formatted_resources, 'details': ''}
    db = tagdb.db(notes_dir)
    add_item_to_db = new_item.new_item(passthrough_dict, notes_dir)
    item_to_add = add_item_to_db.get_user_input()
    db.add_item(item_to_add)
Ejemplo n.º 5
0
def view_all_items():
    """ View all items currently in the database. """
    header = ['ID', 'Title']
    db = tagdb.db(notes_dir)
    item_list = [header]
    for item_details in db.get_item_titles():
        single_item_list = []
        for key, item in item_details.items():
            single_item_list.append(item)
        item_list.append(single_item_list)
    table = AsciiTable(item_list)
    print(table.table)
Ejemplo n.º 6
0
def parse_dir(directory):
    """ Import directory of files into database. WARNING - If the files do not correspond to the template, this will break. """
    db = tagdb.db(notes_dir)
    print('[+] Getting all files. If using a network share this could take a while.')
    files = glob.glob(directory + '/**/*.md', recursive=True)
    for file in files:
        if not db.does_file_exist(file):
            print('[+] Parsing', file, 'to database')
            add_new_item = new_item.new_item(None, notes_dir)
            parsed_template_dict = add_new_item.parse_template(file)
            db.add_item(parsed_template_dict)
        else:
            print('[+]', file, 'already exists in database.')
Ejemplo n.º 7
0
def view_item(id):
    """ View item with a given ID. """
    db = tagdb.db(notes_dir)
    print(db.get_item_titles())
    return db.get_item_titles()
Ejemplo n.º 8
0
def view_items(ids):
    """ View a collection of items by their IDs. """
    id_list = ids.split(',')
    db = tagdb.db(notes_dir)
    print(db.get_item_titles())