1.1 --- a/imip_text_client.py Sat Jan 13 17:26:42 2018 +0100
1.2 +++ b/imip_text_client.py Tue Jan 16 23:29:39 2018 +0100
1.3 @@ -38,6 +38,51 @@
1.4 import vRecurrence
1.5 import sys, os
1.6
1.7 +# User interface definitions.
1.8 +
1.9 +ATTENDANCE_COMMANDS = ("A", "attend", "attendance")
1.10 +ATTENDEE_COMMANDS = ("a", "attendee")
1.11 +CANCEL_COMMANDS = ("c", "cancel")
1.12 +CHANGE_COMMANDS = ("C", "changes")
1.13 +CLASSIFICATION_COMMANDS = ("c", "class", "classification")
1.14 +FINISH_COMMANDS = ("f", "finish")
1.15 +HELP_COMMANDS = ("h", "help", "?")
1.16 +LIST_COMMANDS = ("l", "list", "show")
1.17 +OPERATION_COMMANDS = ("o", "ops", "operations")
1.18 +PERIOD_COMMANDS = ("p", "period")
1.19 +QUIT_COMMANDS = ("q", "quit", "exit")
1.20 +RECURRENCEID_COMMANDS = ("RECURRENCE-ID", "RID")
1.21 +RESET_COMMANDS = ("r", "reload", "reset", "restart")
1.22 +RULE_COMMANDS = ("rr", "rule", "rrule")
1.23 +SUGGESTED_ATTENDEE_COMMANDS = ("as", "attendee-suggested", "suggested-attendee")
1.24 +SUGGESTED_PERIOD_COMMANDS = ("ps", "period-suggested", "suggested-period")
1.25 +SUMMARY_COMMANDS = ("s", "summary")
1.26 +UID_COMMANDS = ("UID",)
1.27 +UNCANCEL_COMMANDS = ("u", "uncancel", "restore")
1.28 +
1.29 +CANCEL_COMMANDS = ("R", "remove", "cancel")
1.30 +PUBLISH_COMMANDS = ("P", "publish")
1.31 +SEND_COMMANDS = ("S", "send")
1.32 +UPDATE_COMMANDS = ("U", "update")
1.33 +
1.34 +EDIT_COMMANDS = ("e", "edit")
1.35 +REMOVE_COMMANDS = ("r", "remove")
1.36 +
1.37 +ACCEPTED_VALUES = ("a", "accept", "accepted", "attend")
1.38 +DECLINED_VALUES = ("d", "decline", "declined")
1.39 +TENTATIVE_VALUES = ("t", "tentative")
1.40 +
1.41 +def commandlist(l, option=None):
1.42 +
1.43 + "Show 'l' as a command list string employing any given 'option'."
1.44 +
1.45 + if option:
1.46 + l2 = []
1.47 + for s in l:
1.48 + l2.append("%s %s" % (s, option))
1.49 + return "\n".join(l2)
1.50 + return ", ".join(l)
1.51 +
1.52 # User interface functions.
1.53
1.54 echo = False
1.55 @@ -542,11 +587,22 @@
1.56 "Edit the attendee at 'index'."
1.57
1.58 t = self.can_edit_attendee(index)
1.59 - if t:
1.60 - attendees = self.state.get("attendees")
1.61 - attendee, attr = t
1.62 - del attendees[attendee]
1.63 - attendee = input_with_default("Attendee (%s)? ", attendee)
1.64 + if not t:
1.65 + return
1.66 +
1.67 + attendees = self.state.get("attendees")
1.68 + old_attendee, attr = t
1.69 +
1.70 + attendee = input_with_default("Attendee (%s) (or return)? ", old_attendee)
1.71 +
1.72 + # Remove the old attendee if null or a replacement is given.
1.73 +
1.74 + if attendee.strip() or not old_attendee:
1.75 + del attendees[old_attendee]
1.76 +
1.77 + # Add any replacement.
1.78 +
1.79 + if attendee.strip():
1.80 attendees[attendee] = attr
1.81
1.82 def edit_period(self, index, args=None):
1.83 @@ -591,7 +647,7 @@
1.84
1.85 # Edit an existing selector.
1.86
1.87 - if cmd in ("e", "edit"):
1.88 + if cmd in EDIT_COMMANDS:
1.89 if isinstance(selector, vRecurrence.LimitSelector):
1.90 add_rule_selector_count(selectors, args, selector)
1.91 elif isinstance(selector, vRecurrence.Pattern):
1.92 @@ -601,7 +657,7 @@
1.93
1.94 # Remove an existing selector.
1.95
1.96 - elif cmd in ("r", "remove"):
1.97 + elif cmd in REMOVE_COMMANDS:
1.98 del selectors[index]
1.99
1.100 # Exit if requested or after a successful
1.101 @@ -1095,55 +1151,67 @@
1.102 print_title("Editing commands")
1.103 print
1.104 print """\
1.105 -a [ <uri> ]
1.106 -attendee [ <uri> ]
1.107 +%(ATTENDEE_NEW_COMMANDS)s
1.108 Add attendee
1.109
1.110 -A, attend, attendance
1.111 - Change attendance/participation
1.112 -
1.113 -a<digit>
1.114 -attendee <digit>
1.115 +%(ATTENDEE_COMMANDS)s
1.116 Select attendee from list
1.117
1.118 -as<digit>
1.119 +%(ATTENDANCE_COMMANDS)s
1.120 + Change attendance/participation
1.121 +
1.122 +%(SUGGESTED_ATTENDEE_COMMANDS)s
1.123 Add suggested attendee from list
1.124
1.125 -f, finish
1.126 +%(FINISH_COMMANDS)s
1.127 Finish editing, confirming changes, proceeding to messaging
1.128
1.129 -h, help, ?
1.130 +%(HELP_COMMANDS)s
1.131 Show this help message
1.132
1.133 -l, list, show
1.134 +%(LIST_COMMANDS)s
1.135 List/show all event details
1.136
1.137 -p, period [ new ]
1.138 +%(PERIOD_NEW_COMMANDS)s
1.139 Add new period
1.140
1.141 -p<digit>
1.142 -period <digit>
1.143 +%(PERIOD_COMMANDS)s
1.144 Select period from list
1.145
1.146 -ps<digit>
1.147 +%(SUGGESTED_PERIOD_COMMANDS)s
1.148 Add or remove suggested period from list
1.149
1.150 -q, quit, exit
1.151 +%(QUIT_COMMANDS)s
1.152 Exit/quit this program
1.153
1.154 -r, reload, reset, restart
1.155 +%(RESET_COMMANDS)s
1.156 Reset event periods (return to editing mode, if already finished)
1.157
1.158 -rule, rrule
1.159 +%(RULE_NEW_COMMANDS)s
1.160 Add a period recurrence rule
1.161
1.162 -rule <digit>
1.163 -rrule <digit>
1.164 +%(RULE_COMMANDS)s
1.165 Select period recurrence rule selector from list
1.166
1.167 -s, summary
1.168 +%(SUMMARY_COMMANDS)s
1.169 Set event summary
1.170 -"""
1.171 +""" % {
1.172 + "ATTENDEE_NEW_COMMANDS" : commandlist(ATTENDEE_COMMANDS, "[ <uri> ]"),
1.173 + "ATTENDEE_COMMANDS" : commandlist(ATTENDEE_COMMANDS, "<number>"),
1.174 + "ATTENDANCE_COMMANDS" : commandlist(ATTENDANCE_COMMANDS),
1.175 + "SUGGESTED_ATTENDEE_COMMANDS" : commandlist(SUGGESTED_ATTENDEE_COMMANDS, "<number>"),
1.176 + "FINISH_COMMANDS" : commandlist(FINISH_COMMANDS),
1.177 + "HELP_COMMANDS" : commandlist(HELP_COMMANDS),
1.178 + "LIST_COMMANDS" : commandlist(LIST_COMMANDS),
1.179 + "PERIOD_NEW_COMMANDS" : commandlist(PERIOD_COMMANDS, "[ new ]"),
1.180 + "PERIOD_COMMANDS" : commandlist(PERIOD_COMMANDS, "<number>"),
1.181 + "SUGGESTED_PERIOD_COMMANDS" : commandlist(SUGGESTED_PERIOD_COMMANDS, "<number>"),
1.182 + "QUIT_COMMANDS" : commandlist(QUIT_COMMANDS),
1.183 + "RESET_COMMANDS" : commandlist(RESET_COMMANDS),
1.184 + "RULE_NEW_COMMANDS" : commandlist(RULE_COMMANDS),
1.185 + "RULE_COMMANDS" : commandlist(RULE_COMMANDS, "<number>"),
1.186 + "SUMMARY_COMMANDS" : commandlist(SUMMARY_COMMANDS),
1.187 + }
1.188
1.189 print_title("Messaging commands")
1.190 print
1.191 @@ -1218,44 +1286,44 @@
1.192
1.193 # Check the status of the periods.
1.194
1.195 - if cmd in ("c", "class", "classification"):
1.196 + if cmd in CLASSIFICATION_COMMANDS:
1.197 cl.show_period_classification()
1.198 print
1.199
1.200 - elif cmd in ("C", "changes"):
1.201 + elif cmd in CHANGE_COMMANDS:
1.202 cl.show_changes()
1.203 print
1.204
1.205 # Finish editing.
1.206
1.207 - elif cmd in ("f", "finish"):
1.208 + elif cmd in FINISH_COMMANDS:
1.209 cl.finish()
1.210
1.211 # Help.
1.212
1.213 - elif cmd in ("h", "?", "help"):
1.214 + elif cmd in HELP_COMMANDS:
1.215 show_commands()
1.216
1.217 # Show object details.
1.218
1.219 - elif cmd in ("l", "list", "show"):
1.220 + elif cmd in LIST_COMMANDS:
1.221 cl.show_object()
1.222 print
1.223
1.224 # Show the operations.
1.225
1.226 - elif cmd in ("o", "ops", "operations"):
1.227 + elif cmd in OPERATION_COMMANDS:
1.228 cl.show_operations()
1.229 print
1.230
1.231 # Quit or exit.
1.232
1.233 - elif cmd in ("q", "quit", "exit"):
1.234 + elif cmd in QUIT_COMMANDS:
1.235 break
1.236
1.237 # Restart editing.
1.238
1.239 - elif cmd in ("r", "reload", "reset", "restart"):
1.240 + elif cmd in RESET_COMMANDS:
1.241 obj = cl.load_object(obj.get_uid(), obj.get_recurrenceid())
1.242 if not obj:
1.243 obj = cl.new_object()
1.244 @@ -1265,11 +1333,11 @@
1.245
1.246 # Show UID details.
1.247
1.248 - elif cmd == "UID":
1.249 + elif cmd in UID_COMMANDS:
1.250 filename = get_text_arg(s)
1.251 write(obj.get_uid(), filename)
1.252
1.253 - elif cmd == "RECURRENCE-ID":
1.254 + elif cmd in RECURRENCEID_COMMANDS:
1.255 filename = get_text_arg(s)
1.256 write(obj.get_recurrenceid() or "", filename)
1.257
1.258 @@ -1279,21 +1347,21 @@
1.259
1.260 # Show messages.
1.261
1.262 - if cmd in ("P", "publish"):
1.263 + if cmd in PUBLISH_COMMANDS:
1.264 filename = get_text_arg(s)
1.265 cl.show_publish_message(plain=not filename, filename=filename)
1.266
1.267 - elif cmd in ("R", "remove", "cancel"):
1.268 + elif cmd in CANCEL_COMMANDS:
1.269 filename = get_text_arg(s)
1.270 cl.show_cancel_message(plain=not filename, filename=filename)
1.271
1.272 - elif cmd in ("U", "update"):
1.273 + elif cmd in UPDATE_COMMANDS:
1.274 filename = get_text_arg(s)
1.275 cl.show_update_message(plain=not filename, filename=filename)
1.276
1.277 # Definitive finishing action.
1.278
1.279 - elif cmd in ("S", "send"):
1.280 + elif cmd in SEND_COMMANDS:
1.281
1.282 # Send update and cancellation messages.
1.283
1.284 @@ -1337,7 +1405,7 @@
1.285
1.286 # Add or edit attendee.
1.287
1.288 - if cmd in ("a", "attendee"):
1.289 + if cmd in ATTENDEE_COMMANDS:
1.290 value = next_arg(args)
1.291 index = to_int_or_none(value)
1.292
1.293 @@ -1367,9 +1435,9 @@
1.294 cmd = next_arg(args)
1.295 if not cmd:
1.296 cmd = read_input("Attendee: (e)dit, (r)emove (or return)> ")
1.297 - if cmd in ("e", "edit"):
1.298 + if cmd in EDIT_COMMANDS:
1.299 cl.edit_attendee(index)
1.300 - elif cmd in ("r", "remove"):
1.301 + elif cmd in REMOVE_COMMANDS:
1.302 cl.remove_attendees([index])
1.303
1.304 # Exit if requested or after a successful
1.305 @@ -1386,7 +1454,7 @@
1.306
1.307 # Add suggested attendee (using index).
1.308
1.309 - elif cmd in ("as", "attendee-suggested", "suggested-attendee"):
1.310 + elif cmd in SUGGESTED_ATTENDEE_COMMANDS:
1.311 value = next_arg(args)
1.312 index = to_int_or_none(value)
1.313
1.314 @@ -1398,7 +1466,7 @@
1.315
1.316 # Edit attendance.
1.317
1.318 - elif cmd in ("A", "attend", "attendance"):
1.319 + elif cmd in ATTENDANCE_COMMANDS:
1.320
1.321 if not cl.is_attendee() and cl.is_organiser():
1.322 cl.add_attendee(cl.user)
1.323 @@ -1413,11 +1481,11 @@
1.324 cmd = next_arg(args)
1.325 if not cmd:
1.326 cmd = read_input("Attendance: (a)ccept, (d)ecline, (t)entative (or return)> ")
1.327 - if cmd in ("a", "accept", "accepted", "attend"):
1.328 + if cmd in ACCEPTED_VALUES:
1.329 cl.edit_attendance("ACCEPTED")
1.330 - elif cmd in ("d", "decline", "declined"):
1.331 + elif cmd in DECLINED_VALUES:
1.332 cl.edit_attendance("DECLINED")
1.333 - elif cmd in ("t", "tentative"):
1.334 + elif cmd in TENTATIVE_VALUES:
1.335 cl.edit_attendance("TENTATIVE")
1.336
1.337 # Exit if requested or after a successful operation.
1.338 @@ -1433,7 +1501,7 @@
1.339
1.340 # Add or edit period.
1.341
1.342 - elif cmd in ("p", "period"):
1.343 + elif cmd in PERIOD_COMMANDS:
1.344 value = next_arg(args)
1.345 index = to_int_or_none(value)
1.346
1.347 @@ -1455,12 +1523,13 @@
1.348
1.349 cmd = next_arg(args)
1.350 if not cmd:
1.351 - cmd = read_input("Period: (e)dit, (c)ancel, (u)ncancel (or return)> ")
1.352 - if cmd in ("e", "edit"):
1.353 + cmd = read_input("Period: (c)ancel, (e)dit, (u)ncancel (or return)> ")
1.354 +
1.355 + if cmd in CANCEL_COMMANDS:
1.356 + cl.cancel_periods([index])
1.357 + elif cmd in EDIT_COMMANDS:
1.358 cl.edit_period(index, args)
1.359 - elif cmd in ("c", "cancel"):
1.360 - cl.cancel_periods([index])
1.361 - elif cmd in ("u", "uncancel", "restore"):
1.362 + elif cmd in UNCANCEL_COMMANDS:
1.363 cl.cancel_periods([index], False)
1.364
1.365 # Exit if requested or after a successful
1.366 @@ -1477,7 +1546,7 @@
1.367
1.368 # Apply suggested period (using index).
1.369
1.370 - elif cmd in ("ps", "period-suggested", "suggested-period"):
1.371 + elif cmd in SUGGESTED_PERIOD_COMMANDS:
1.372 value = next_arg(args)
1.373 index = to_int_or_none(value)
1.374
1.375 @@ -1489,7 +1558,7 @@
1.376
1.377 # Specify a recurrence rule.
1.378
1.379 - elif cmd in ("rule", "rrule"):
1.380 + elif cmd in RULE_COMMANDS:
1.381 value = next_arg(args)
1.382 index = to_int_or_none(value)
1.383
1.384 @@ -1506,7 +1575,7 @@
1.385
1.386 # Set the summary.
1.387
1.388 - elif cmd in ("s", "summary"):
1.389 + elif cmd in SUMMARY_COMMANDS:
1.390 cl.edit_summary(get_text_arg(s))
1.391 cl.show_object()
1.392 print