update for python 3

This commit is contained in:
Jonathan Reeve
2015-02-15 14:53:02 -05:00
parent 29a470f97d
commit a53bb81b4c

View File

@@ -51,18 +51,18 @@ __history__ = """
""" """
def usage(): def usage():
print "USAGE: %s [todo.txt] [done.txt]" % (sys.argv[0], ) print("USAGE: %s [todo.txt] [done.txt]" % (sys.argv[0], ))
def printTaskGroups(title, taskDict, priorityList, percentages): def printTaskGroups(title, taskDict, priorityList, percentages):
print "" print("")
print "%s"% (title,) print("%s"% (title,))
separator("-") separator("-")
if not taskDict: if not taskDict:
print "No items to list." print("No items to list.")
else: else:
# sort the dictionary by value # sort the dictionary by value
# http://python.fyxm.net/peps/pep-0265.html # http://python.fyxm.net/peps/pep-0265.html
items = [(v, k) for k, v in taskDict.items()] items = [(v, k) for k, v in list(taskDict.items())]
items.sort() items.sort()
items.reverse() # so largest is first items.reverse() # so largest is first
items = [(k, v) for v, k in items] items = [(k, v) for v, k in items]
@@ -84,7 +84,7 @@ def printTaskGroups(title, taskDict, priorityList, percentages):
def printTaskGroup(p, pctage, star): def printTaskGroup(p, pctage, star):
if pctage > -1: if pctage > -1:
progressBar = "" progressBar = ""
numStars = (pctage/10) numStars = int(pctage//10)
progressBar = "=" * numStars progressBar = "=" * numStars
numSpaces = 10 - numStars numSpaces = 10 - numStars
for n in range(numSpaces): for n in range(numSpaces):
@@ -94,14 +94,14 @@ def printTaskGroup(p, pctage, star):
displayTotal = " %d%%"% (pctage, ); displayTotal = " %d%%"% (pctage, );
else: else:
displayTotal = " %d%%"% (pctage, ); displayTotal = " %d%%"% (pctage, );
print "%s %s [%s] %s (%d todo's)"% (star, displayTotal, progressBar, p[0], p[1],) print("%s %s [%s] %s (%d todo's)"% (star, displayTotal, progressBar, p[0], p[1],))
else: else:
print "%s %s (%d todo's)"% (star, p[0], p[1], ) print("%s %s (%d todo's)"% (star, p[0], p[1], ))
def separator(c): def separator(c):
sep = "" sep = ""
sep = c * 42 sep = c * 42
print sep print(sep)
def main(argv): def main(argv):
@@ -139,7 +139,7 @@ def main(argv):
contextPriority.append(word) contextPriority.append(word)
f.close() f.close()
except IOError: except IOError:
print "ERROR: The file named %s could not be read."% (argv[0], ) print("ERROR: The file named %s could not be read."% (argv[0], ))
usage() usage()
sys.exit(2) sys.exit(2)
@@ -157,7 +157,7 @@ def main(argv):
completedTasks[word] = completedTasks.setdefault(word, 0) + 1 completedTasks[word] = completedTasks.setdefault(word, 0) + 1
f.close() f.close()
except IOError: except IOError:
print "ERROR: The file named %s could not be read."% (argv[1], ) print("ERROR: The file named %s could not be read."% (argv[1], ))
usage() usage()
sys.exit(2) sys.exit(2)
@@ -180,18 +180,18 @@ def main(argv):
# print out useful info # print out useful info
#print "TODO.TXT Bird's Eye View Report %s"% ( datetime.date.today().isoformat(), ) #print "TODO.TXT Bird's Eye View Report %s"% ( datetime.date.today().isoformat(), )
print "" print("")
print "TODO.TXT Bird's Eye View Report" print("TODO.TXT Bird's Eye View Report")
separator("=") separator("=")
printTaskGroups("Projects with Open TODO's", projects, projectPriority, projectPercentages) printTaskGroups("Projects with Open TODO's", projects, projectPriority, projectPercentages)
printTaskGroups("Contexts with Open TODO's", contexts, contextPriority, projectPercentages) printTaskGroups("Contexts with Open TODO's", contexts, contextPriority, projectPercentages)
printTaskGroups("Completed Projects (No open TODO's)", projectsWithNoIncompletes, projectPriority, projectPercentages) printTaskGroups("Completed Projects (No open TODO's)", projectsWithNoIncompletes, projectPriority, projectPercentages)
print "" print("")
print "* Projects and contexts with an asterisk next to them denote prioritized tasks." print("* Projects and contexts with an asterisk next to them denote prioritized tasks.")
print "Project with prioritized tasks are listed first, then sorted by number of open todo's." print("Project with prioritized tasks are listed first, then sorted by number of open todo's.")
print "" print("")