usr bin python coding utf-8 Importing modules import sys import getopt

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/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()