Skip to content

Commit

Permalink
search-notes.py: Support -v, --verbose option
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Nov 24, 2011
1 parent 6f925ab commit f3bdec9
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions misc/notes/search-notes.py
Expand Up @@ -44,8 +44,8 @@ def __init__(self):
def parse_args(self):
''' Parse the command line arguments. '''
try:
opts, keywords = getopt.getopt(sys.argv[1:], 'l:d:n:e:h',
['list=', 'database=', 'notes=', 'encoding=', 'help'])
opts, keywords = getopt.getopt(sys.argv[1:], 'l:d:n:e:vh',
['list=', 'database=', 'notes=', 'encoding=', 'verbose', 'help'])
except getopt.GetoptError, error:
print str(error)
self.usage()
Expand All @@ -55,6 +55,7 @@ def parse_args(self):
self.user_directory = '~/.vim/misc/notes/user/'
self.character_encoding = 'UTF-8'
self.keyword_filter = None
self.verbose = False
# Map command line options to variables.
for opt, arg in opts:
if opt in ('-l', '--list'):
Expand All @@ -65,6 +66,8 @@ def parse_args(self):
self.user_directory = arg
elif opt in ('-e', '--encoding'):
self.character_encoding = arg
elif opt in ('-v', '--verbose'):
self.verbose = True
elif opt in ('-h', '--help'):
self.usage()
sys.exit(0)
Expand Down Expand Up @@ -127,7 +130,8 @@ def update_index(self):

def add_note(self, filename, last_modified):
''' Add a note to the index (assumes the note is not already indexed). '''
sys.stderr.write("Scanning %s ..\n" % filename)
if self.verbose:
sys.stderr.write("Indexing %s ..\n" % filename)
self.index['files'][filename] = last_modified
with open(filename) as handle:
for kw in self.tokenize(handle.read()):
Expand All @@ -139,6 +143,8 @@ def add_note(self, filename, last_modified):

def delete_note(self, filename):
''' Remove a note from the index. '''
if self.verbose:
sys.stderr.write("Forgetting %s ..\n" % filename)
del self.index['files'][filename]
for kw in self.index['keywords']:
filter(lambda x: x != filename, self.index['keywords'][kw])
Expand Down Expand Up @@ -203,6 +209,7 @@ def usage(self):
-d, --database=FILE set path to keywords index file
-n, --notes=DIR set directory with user notes
-e, --encoding=NAME set character encoding of notes
-v, --verbose make more noise
-h, --help show this message and exit
For more information see http://peterodding.com/code/vim/notes/
Expand Down

0 comments on commit f3bdec9

Please sign in to comment.