-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommands.py
More file actions
271 lines (226 loc) · 7.73 KB
/
commands.py
File metadata and controls
271 lines (226 loc) · 7.73 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
"""
The main engine of the checkList program.
Some notes:
- Checklists are always referred by name ("checklist")
- Most functions operate on either the current list or a specified list
"""
import checkBuilder
from os.path import exists
from datetime import date
#Eliminates the magic string "current"!
current = "current"
helpDoc ="""\
Checklist creates, displays, and controls lists of tasks.
It's used for things like To-do lists or instructions.
Commands:
new: create a new checklist
load: load a checklist
save: save current checklist
add: create a new item and add to a list
remove: remove item X from checklist
clean: removes old or finished items from a list
list: display a checklist's items
linfo: display information about a list
info X: display information about item X
edit X: edit the information of item X
next: display the item that is due soonest
exit: Exit from the program
help: Displays this help message
version: Displays the version number
add, delete, list, info, edit, and next can be used on more
than just the current list. The 'X's refer to the index of
the item to be affected; lists are indexed from 1.
Ex:
info(1, "tuesday") would display the information of the
first item in the list called "tuesday". Lists can be
referred to by either filename or listname.\
PLEASE use help topics for further information. To see a help topic:
help <command>
ex:
help help
help add
"""
curList = [] #the current check list
def newCheckList(name='NewList'):
"""
Returns a new, empty checklist.
Alias: new
name -- the name of the new checklist. (Default: "NewList")
Usage:
newCheckList "tuesday" -- creates list "tuesday"
new -- creates a new list called "NewList"
"""
return checkBuilder.checkList()
def loadCheckList(fp):
"""
Loads a checklist from a YAML file.
Alias: load
fp -- the identifier of the file.
fp can either be the filename ("checklist.yaml"), the path to
the file ("Lists/checklist.yaml"), or the name of the checklist
("checklist"). Since the checklist files are named after the
checklist they hold, this is rather simple to implement.
Usage:
load tuesday -- sets "tuesday" as current list
"""
if exists(fp):
print "Will now load file---filename or filepath!"
else:
print "Now we would check for a checklist of the same name as file"
return exists(fp)
def saveCheckList():
"""
Saves a checklist in a YAML file.
Alias: save
The file will be named after checklist and stored in the local dir,
~/.checklists. On Windows, it would be AppData/.../.checklists.
Usage:
save -- saves the current list
"""
return "It would be saved in the YAML format in a file nearby"
def addItem(item, clist=current, idx=0):
"""
Adds a new task to a checklist.
Alias: add
item -- the item to add, a CheckItem object.
clist -- the name of the checklist to add item to.
idx -- the index to add the item at.
item is the only required argument. If clist is not provided,
it is assumed that the item should be appended to the current list.
Checklists are 1-indexed, so a 0 index indicates that it should be
appended to the list.
Usage:
add newItem tuesday 5 -- adds the newItem to "tuesday" at index 5
"""
return "Item appended!"
def remove(idx=0, clist=current):
"""
Removes the item at index i from the given checklist.
idx -- the index of the item to remove.
clist -- the list to remove the item from.
If clist is absent, the current list is assumed. If idx is missing,
it's assumed that the first item is removed.
If idx = '*', the list is cleared.
if idx = 'list', the list itself is deleted.
Usage:
remove -- removes the first item from current list
remove list tuesday -- deletes "tuesday"
"""
return "Deletes items or a checklist!"
def clean(target="*all", clist=current):
"""
Removes overdue and completed items from a checklist.
target -- what to clean up
clist -- the checklist to clean. Default: current
Possible values for target:
- *all
- *old
- *fin
*fin removes all completed items.
*old removes all overdue items.
*all removes both completed and overdue items.
Possible values for clist:
- a checklist identifier
- *all
*all will clean every checklist that this program manages.
usage:
clean *all
clean *old tuesday --removes overdue items from the list 'tuesday'
"""
def listItems(clist=current):
"""
Displays the checklist in a well-formatted YAML list.
THIS FUNCTION IS NOT IMPLEMENTED.
- YAML List?
- display items?
- what do??
"""
return "The well-formatted items would be displayed here"
def getInfo(idx=0, clist=current):
"""
Displays information about a given item or list.
Alias: info
idx -- the index of the item to investigate
clist -- the list that holds the item
If idx = 'list' or 0, print information about the list.
Usage:
info list -- prints information about current list
info list "tuesday" -- prints info about "tuesday"
info 1 -- prints info about the first item
"""
return "The item information is selected by index"
def editItem(idx):
"""
Edits the item at index i of the current list.
NOT IMPLEMENTED.
"""
return "An interactive editing mode would start"
def nextDue(clist=current):
"""
Displays the information of the item that is due soonest.
Alias: next
clist -- the list to check for items. Default: "current"
If clist = "*all", every list is checked to find the item due
soonest.
Finds the item is due nearest to datetime.date.today.
Usage:
next -- shows what you need to do next from the current list
next tuesday -- displays the item that's due next in "tuesday"
next *all -- displays the very next item that's due from all lists
"""
return "The next item can be really useful!"
def showHelp(topic=False):
"""
Displays the help docs for a specific command or just everything!
topic -- the thing to find help for
"topic" can be any command or the word "commands".
If thing is absent, displays the general help message (helpDoc)
Usage:
help -- displays general help message
help add -- displays documentation for 'add'
help help -- displays this message!
help commands -- displays the list of commands you can find help for
"""
if not topic:
return helpDoc
elif topic == "commands":
return commHelp
elif topic in commands:
return "%s:%s" % (topic, commands[topic].__doc__)
elif topic in commands.values():
return "Please use the alias for %s to see help" % topic
else:
return "There's no help for you, if you want %s" % topic
commands = {
"add" : addItem,
"edit" : editItem,
"info" : getInfo,
"list" : listItems,
"load" : loadCheckList,
"new" : newCheckList,
"next" : nextDue,
"remove" : remove,
"clean" : clean,
"save" : saveCheckList,
"help" : showHelp
}
commList = commands.keys()
commList.sort()
#Splits the list in half: [1,2,3,4,5] ==> [1,2] [3,4,5]
a = commList[:len(commList)/2+1]
b = commList[len(commList)/2+1:]
if len(a) > len(b):
b.append("")
commList = []
for i in range(len(a)):
commList.append(a[i])
commList.append(b[i])
#Combine the list into 2 columns
#Found at: http://stackoverflow.com/a/171707
#By gimel, modified by S.Lott
cols = 2
lines = ("\t".join(commList[i:i+cols])
for i in xrange(0,len(commList),cols))
commHelp = '\n'.join(lines)
commList.sort()
del a,b,cols,lines