Stylistic changes.

This commit is contained in:
Jeremy Fincher 2003-12-07 05:33:31 +00:00
parent ead91da748
commit 0719b5e6b8

View File

@ -93,6 +93,9 @@ class Todo(callbacks.Privmsg):
self.db.close() self.db.close()
del self.db del self.db
def _shrink(self, s):
return utils.ellipsisify(s, 50)
def todo(self, irc, msg, args): def todo(self, irc, msg, args):
"""[<username>|<task id>] """[<username>|<task id>]
@ -101,7 +104,6 @@ class Todo(callbacks.Privmsg):
list. list.
""" """
arg = privmsgs.getArgs(args, required=0, optional=1) arg = privmsgs.getArgs(args, required=0, optional=1)
userid = None userid = None
taskid = None taskid = None
# Figure out what userid and taskid need to be set to (if anything) # Figure out what userid and taskid need to be set to (if anything)
@ -117,25 +119,23 @@ class Todo(callbacks.Privmsg):
irc.error(msg, irc.error(msg,
'%r is not a valid task id or username' % arg) '%r is not a valid task id or username' % arg)
return return
# Everything needs a cursor, might as well plop it outside cursor = self.db.cursor()
if not userid and not taskid: if not userid and not taskid:
try: try:
id = ircdb.users.getUserId(msg.prefix) id = ircdb.users.getUserId(msg.prefix)
except KeyError: except KeyError:
irc.error(msg, conf.replyNotRegistered) irc.error(msg, conf.replyNotRegistered)
return return
cursor = self.db.cursor()
cursor.execute("""SELECT id, task FROM todo cursor.execute("""SELECT id, task FROM todo
WHERE userid = %s AND active = 1 WHERE userid = %s AND active = 1
ORDER BY priority, id""", id) ORDER BY priority, id""", id)
if cursor.rowcount == 0: if cursor.rowcount == 0:
irc.reply(msg, 'You have no tasks in your todo list.') irc.reply(msg, 'You have no tasks in your todo list.')
return else:
s = ['#%s: %s' % (item[0], utils.ellipsisify(item[1], 50)) \ L = ['#%s: %s' % (item[0], self._shrink(item[1]))
for item in cursor.fetchall()] for item in cursor.fetchall()]
irc.reply(msg, utils.commaAndify(s)) irc.reply(msg, utils.commaAndify(L))
else: else:
cursor = self.db.cursor()
if userid: if userid:
cursor.execute("""SELECT id, task FROM todo cursor.execute("""SELECT id, task FROM todo
WHERE userid = %s AND active = 1 WHERE userid = %s AND active = 1
@ -143,13 +143,13 @@ class Todo(callbacks.Privmsg):
if cursor.rowcount == 0: if cursor.rowcount == 0:
irc.reply(msg, 'That user has no todos.') irc.reply(msg, 'That user has no todos.')
return return
s = ['#%s: %s' % (item[0], utils.ellipsisify(item[1], 50)) \ L = ['#%s: %s' % (item[0], self._shrink(item[1]))
for item in cursor.fetchall()] for item in cursor.fetchall()]
reply = "%s for %s: %s" % \ if len(L) == 1:
(utils.pluralize(len(s), 'Todo'), arg, s = 'Todo for %s: %s' % (arg, L[0])
utils.commaAndify(s)) else:
irc.reply(msg, reply) s = 'Todos for %s: %s' % (arg, utils.commaAndify(L))
return irc.reply(msg, s)
else: else:
cursor.execute("""SELECT userid, priority, added_at, task cursor.execute("""SELECT userid, priority, added_at, task
FROM todo WHERE id = %s""", taskid) FROM todo WHERE id = %s""", taskid)
@ -159,14 +159,11 @@ class Todo(callbacks.Privmsg):
userid, pri, added_at, task = cursor.fetchone() userid, pri, added_at, task = cursor.fetchone()
# Construct and return the reply # Construct and return the reply
username = ircdb.users.getUser(userid).name username = ircdb.users.getUser(userid).name
if pri == 0: if pri:
priority = "" task += ', priority: %s' % pri
else: added_at = time.strftime(conf.humanTimestampFormat,
priority = ", priority: %s" % pri time.localtime(int(added_at)))
added_time = time.strftime(conf.humanTimestampFormat, s = "Todo for %s: %s (Added at %s)" % (username,task,added_at)
time.localtime(int(added_at)))
s = "Todo for %s: %s%s (Added at %s)" % \
(username, task, priority, added_time)
irc.reply(msg, s) irc.reply(msg, s)
def add(self, irc, msg, args): def add(self, irc, msg, args):
@ -190,7 +187,7 @@ class Todo(callbacks.Privmsg):
except ValueError, e: except ValueError, e:
irc.error(msg, '%r is an invalid priority' % arg) irc.error(msg, '%r is an invalid priority' % arg)
return return
text = privmsgs.getArgs(rest, required=1) text = privmsgs.getArgs(rest)
cursor = self.db.cursor() cursor = self.db.cursor()
now = int(time.time()) now = int(time.time())
cursor.execute("""INSERT INTO todo cursor.execute("""INSERT INTO todo
@ -212,8 +209,7 @@ class Todo(callbacks.Privmsg):
except KeyError: except KeyError:
irc.error(msg, conf.replyNotRegistered) irc.error(msg, conf.replyNotRegistered)
return return
taskid = privmsgs.getArgs(args)
taskid = privmsgs.getArgs(args, required=1)
cursor = self.db.cursor() cursor = self.db.cursor()
cursor.execute("""SELECT * FROM todo cursor.execute("""SELECT * FROM todo
WHERE id = %s AND userid = %s WHERE id = %s AND userid = %s
@ -243,7 +239,7 @@ class Todo(callbacks.Privmsg):
(optlist, rest) = getopt.getopt(args, '', ['regexp=', 'exact=']) (optlist, rest) = getopt.getopt(args, '', ['regexp=', 'exact='])
if not optlist and not rest: if not optlist and not rest:
raise callbacks.ArgumentError raise callbacks.ArgumentError
criteria = ['userid = %s' % id, 'active = 1'] criteria = ['userid=%s' % id, 'active=1']
formats = [] formats = []
predicateName = 'p' predicateName = 'p'
for (option, arg) in optlist: for (option, arg) in optlist:
@ -271,7 +267,7 @@ class Todo(callbacks.Privmsg):
if cursor.rowcount == 0: if cursor.rowcount == 0:
irc.reply(msg, 'No tasks matched that query.') irc.reply(msg, 'No tasks matched that query.')
else: else:
tasks = ['#%s: %s' % (item[0], utils.ellipsisify(item[1], 50)) \ tasks = ['#%s: %s' % (item[0], self._shrink(item[1]))
for item in cursor.fetchall()] for item in cursor.fetchall()]
irc.reply(msg, utils.commaAndify(tasks)) irc.reply(msg, utils.commaAndify(tasks))