#!/usr/bin/python
# -*- coding: utf-8 -*-
#Importing modules
import sys
import getopt
from libnofi import *
editor = 'vi'
pager = 'more'
#Defining functions
def create(name):
note = Note(name)
if not note.exists():
text = raw_input()
Note.write(text)
tag()
else:
print ':: Note already exists'
def add(path):
name = os.path.splitext(os.path.split(path)[1])[0]
note = Note(name)
if not note.exists():
note.importFile(path)
else:
print ':: Note already exists'
def edit(name):
note = Note(name)
if note.exists():
os.system('%s %s' % (editor, note.getPath()))
else:
print ':: No such note'
def tag(name):
note = Note(name)
tags = asktags()
note.tag(tags)
def view(name):
note = Note(name)
if note.exists():
os.system('cat %s | %s' % (path, pager))
else:
print ':: No such note'
def info(name):
note = Note(name)
if note.exists():
print 'Name: ', name
print 'Path: ', note.getPath()
print 'Date: ', note.getDate()
print 'Tags: ', ', '.join(note.getTags())
else:
print ':: No such note'
def remove(name):
note = Note(name)
yes = ('Y', 'y')
no = ('N', 'n')
if note.exists():
answer = raw_input(':: Do you REALLY want to remove this note? [Y/n]\n')
while answer not in yes and answer not in no:
answer = raw_input()
if answer in yes:
note.remove()
elif answer in no:
print ':: Note was not removed'
else:
print ':: No such note'
def summary():
print 'Notes: %i' % (Storage().getNotesNumber()), ', '.join(Storage.getNotes())
def asktags():
tag = raw_input(':: Enter tags\n')
taglist = []
while tag != '':
taglist.append(tag)
tag = raw_input()
return taglist
def askqueries():
query = raw_input()
queries = []
while query != '':
queries.append(query)
query = raw_input()
return queries
def find():
queries = askqueries()
print 'Results: ', ', '.join(Search(queries).getNotes())
def main():
help = 'USAGE: nofi [OPTION] [ARGUMENT]\n-n, --new [NAME]\n create new note\n-i, --import [PATH]\n add text file to db\n-e, --edit [NAME]\n edit note\n-v, --view [NAME]\n view note\n-p, --prop [NAME]\n view note`s properties (e.g.: name, path, date, tags)\n-r, --remove [NAME]\n remove note\n-f, --find\n search notes by date or/and tag, text\n-s, --summary\n view summary\n-h, --help\n view this help message\n-a, --about\n about this software'
about = ':: NoteFinder CLI 2.0 on %s\nEasy-to-use console notes manager\nCopyright (c) 2008 GFORGX <gforgx@gmail.com>' % (os.uname()[0])
try:
opts, args = getopt.getopt(sys.argv[1:], "ae:fhi:n:p:r:sv:", ["about","edit=","find","help","import=","new=","prop=","remove=","summary","view="])
except getopt.GetoptError:
print help
sys.exit('\n:: Incorrect option or argument')
for o, a in opts:
if o in ('-n', '--new'):
name = a
create(name)
elif o in ('-i', '--import'):
note = a
add(note)
elif o in ('-e, --edit'):
note_path=a
edit(note_path)
elif o in ('-s', '--summary'):
summary()
elif o in ('-v', '--view'):
notename = a
view(notename)
elif o in ('-p', '--prop'):
name = a
info(name)
elif o in ('-r', '--remove'):
name=a
remove(name)
elif o in ('-f', '--find'):
find()
elif o in ('-h', '--help'):
print help
elif o in ('-a', '--about'):
print about
#Executing program
if __name__ == '__main__':
main()