forked from akkana/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfotogr
More file actions
executable file
·88 lines (71 loc) · 2.9 KB
/
fotogr
File metadata and controls
executable file
·88 lines (71 loc) · 2.9 KB
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
#!/usr/bin/env python
# Photo Search:
# Search under the current dir, or the first argument given,
# for grep matches within files named "Keywords".
# Then translate that to a list of full pathnames.
# Copyright 2007,2009 by Akkana Peck: share and enjoy under the GPLv2 or later.
# Wish list: Boolean logic. Currently this can search only for one
# term/phrase at a time.
import sys, os, string
def system_out (cmdstr) :
retlist = []
fp = os.popen(cmdstr)
while 1:
s = fp.readline()
if not s : break
retlist.append(s)
fp.close()
return retlist
def search_for_keywords(opts, pat, grepdirs) :
matchfiles = []
for grepdir in grepdirs :
matches = system_out("find " + grepdir + \
" \\( -name 'Keywords' -or -name 'Tags' \\) -print0 | xargs -0 grep -i '" \
+ pat + "' /dev/null")
# matches is an array of lines that are either empty, or look like this:
# ./missionpeak/Tags:dave: pict1166.jpg pict1167.jpg pict1168.jpg
for line in (matches) :
if opts.separate :
if line[0:2] == "./" :
print line[2:]
else :
print line
continue
# print "Have a match: -", line, "-"
pieces = line.split(':')
#print "dir is", pieces[0], "middle", pieces[1], "rest", pieces[2]
matchsplit = pieces[2].split()
#print "matchsplit", matchsplit
subdir = os.path.normpath(os.path.dirname(pieces[0]))
# Don't add "./" if . is the current path
if subdir == "." :
subdir = None
#print "subdir is", subdir
for fil in matchsplit :
if subdir :
fnam = os.path.join(subdir, fil)
else :
fnam = fil
# Only print files that actually exist and are readable:
if os.access(fnam, os.R_OK) :
if fnam not in matchfiles :
matchfiles.append(fnam)
#print fnam,
for f in matchfiles :
print f,
if __name__ == "__main__" :
from optparse import OptionParser
usage = "Usage: %prog [options] gpx_file(s)"
version = "%prog 0.2: search for photos with keywords.\n\
Copyright 2009 by Akkana Peck; share and enjoy under the GPL v2 or later."
parser = OptionParser(usage=usage, version=version)
parser.add_option("-s", "--separate",
action="store_true", dest="separate",
help="print separate lines from different Keywords files")
(options, args) = parser.parse_args()
if len(args) == 0 :
parser.print_help()
elif len(args) == 1 :
search_for_keywords(options, args[0], [ "." ])
else :
search_for_keywords(options, args[0], args[1:])