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 | #!/usr/bin/python
# gimmick.py -- tracks bugs and features
import sys, os, cPickle
configFileName = ".gimmick"
class Item():
kind = "" #bug or feature
name = ""
id_number = ""
status = ""
def newDataFile():
# If the .gimmick file doesn't exist
if not os.path.exists(configFileName):
# Make a new blank file, and just close it
gimmickFile = open(configFileName, "w")
cPickle.dump([], gimmickFile)
gimmickFile.close()
else:
print "Data file already exists."
def readDataFile():
# Read the items from the data file
try:
gimmickFile = open(configFileName, "r")
gimmicks = cPickle.load(gimmickFile)
gimmickFile.close()
return gimmicks
except IOError:
print "IO Error on reading data file."
def writeDataFile(listOfGimmicks):
try:
gimmickFile = open(configFileName, "w")
cPickle.dump(listOfGimmicks, gimmickFile)
gimmickFile.close()
except IOError:
print "IO Error on writing data file."
def addNewItem(kind):
gimmicks = readDataFile()
# Make a new item
newItem = Item()
newItem.kind = kind
newItem.name = str(sys.argv[2])
newItem.id_number = len(gimmicks) + 1
newItem.status = "open"
# And add it to the front of the list
gimmicks.insert(0, newItem)
# And write it to the file
writeDataFile(gimmicks)
def showAllItems():
gimmicks = readDataFile()
try:
# If showing all, show whether open or closed
if sys.argv[2] == "-a":
for item in gimmicks:
print str(item.id_number) + ": " + item.kind[0] + ": " + item.name + ": " + item.status
# Show only bugs
elif sys.argv[2] == "-b":
for item in gimmicks:
if item.status == "open":
if item.kind == "bug":
print str(item.id_number) + ": " + item.name
# Show only features
elif sys.argv[2] == "-f":
for item in gimmicks:
if item.status == "open":
if item.kind == "feature":
print str(item.id_number) + ": " + item.name
except IndexError:
# If only showing working items, only show open, and bugs first
for item in gimmicks:
if item.status == "open":
if item.kind == "bug":
print str(item.id_number) + ": " + item.kind[0] + ": " + item.name
for item in gimmicks:
if item.status == "open":
if item.kind == "feature":
print str(item.id_number) + ": " + item.kind[0] + ": " + item.name
def closeItem():
try:
if sys.argv[2]:
gimmicks = readDataFile()
for item in gimmicks:
if item.id_number == int(sys.argv[2]):
item.status = "closed"
writeDataFile(gimmicks)
except IndexError:
"Bug ID number is required."
def main():
# New data file
if sys.argv[1] == "-n":
newDataFile()
# Add new bug
elif sys.argv[1] == "-b":
addNewItem("bug")
# Add new feature
elif sys.argv[1] == "-f":
addNewItem("feature")
# Show all items
elif sys.argv[1] == "-s":
showAllItems()
# Close an items
elif sys.argv[1] == "-c":
closeItem()
else:
print "Unknown command-line argument."
main()
|