#!/usr/bin/env python
+from __future__ import print_function
+
# Dan White <dan@whiteaudio.com>
"""Recurse from current or given directory and display all folders with
tags."""
import datetime
+import io
import optparse
import os
-import sys
import re
+import sys
-try:
- import cStringIO as StringIO
-except ImportError:
- import StringIO
try:
import optcomplete
def findTag(tag, baseDir):
- s = StringIO.StringIO()
+ s = io.StringIO()
for (path, dirs, files) in os.walk(baseDir):
dirs[:] = [d for d in dirs if not RE_DO_NOT_FOLLOW_DIR.match(d)]
tags = [t.replace(TAG_PREFIX, '') for t in files if t.startswith(TAG_PREFIX)]
if tag in tags:
- print>>s, path
+ print(path, file=s)
return s.getvalue().rstrip()
fname = baseDir + '/' + TAG_PREFIX + tag
#if os.path.exists(fname):
fd = open(fname, 'a')
- print >>fd, datetime.datetime.now().strftime('%F %T')
+ print(datetime.datetime.now().strftime('%F %T'), file=fd)
#try:
#open(baseDir + '/' + TAG_PREFIX + tag, 'r')
#print "ee's already got one (%s)" % tag
try:
os.remove(baseDir + '/' + TAG_PREFIX + tag)
except OSError:
- print 'tag already not present (%s)' % tag
+ print('tag already not present (%s)' % tag)
alltags[t].append(path)
else:
alltags[t] = [path]
- print '%s:' % herePath(path, walkDir)
- print '\n'.join(tags)
- print
+ print('%s:' % herePath(path, walkDir))
+ print('\n'.join(tags))
+ print()
#usedtags = alltags.keys()
#usedtags.sort()
#print
#print '%s:' % t
#print '\n'.join(alltags[t])
else:
- print '\n'.join(listTags(walkDir))
+ print('\n'.join(listTags(walkDir)))
elif opt.search:
for t in opt.search.split(',') + taglist:
- print findTag(t, walkDir)
+ print(findTag(t, walkDir))
elif opt.add:
for t in opt.add.split(',') + taglist:
- print 'adding', t
+ print('adding', t)
addTag(t, walkDir)
elif opt.delete:
for t in opt.delete.split(','):