summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/tracking.py43
1 files changed, 23 insertions, 20 deletions
diff --git a/modules/tracking.py b/modules/tracking.py
index aa3c309..7303e37 100644
--- a/modules/tracking.py
+++ b/modules/tracking.py
@@ -42,6 +42,12 @@ class Consignment(Base):
self.label = label
self.added = added
+ def __str__(self):
+ s = '\002%s\002' % self.code.encode('utf-8')
+ if self.label:
+ s += ' (%s)' % self.label.encode('utf-8')
+ return s
+
class Package(Base):
__tablename__ = 'package'
@@ -55,6 +61,12 @@ class Package(Base):
self.consignment_id = consignment_id
self.code = code
+ def __str__(self):
+ s = '\002%s\002' % self.code.encode('utf-8')
+ if self.consignment.label:
+ s += ' (%s)' % self.consignment.label.encode('utf-8')
+ return s
+
class PackageError(Exception): pass
class NoPackageFound(PackageError): pass
@@ -197,11 +209,10 @@ class Module:
deleted = []
# we should have exactly one consignment, but need to handle cases when there are more
for consignment in consignments:
- code = consignment.code
+ code = str(consignment)
for p in consignment.packages:
session.delete(p)
- label = (' (%s)' % consignment.label) if consignment.label else ''
- deleted.append('\002%s\002%s' % (code.decode('utf8'), label))
+ deleted.append(code)
session.delete(consignment)
session.commit()
msg = 'No longer tracking %s' % ', '.join(deleted)
@@ -221,14 +232,10 @@ class Module:
consignments = consignments.filter(Consignment.nick == nick)
results = []
for row in consignments:
- if row.label:
- label = ' (%s)' % row.label
- else:
- label = ''
try:
self.track_update(row.code, propagate_error = True)
except PackageError as e:
- results.append('Failed to fetch data for \002%s\002%s.' % (row.code.decode('utf-8'), label))
+ results.append('Failed to fetch data for %s.' % row)
continue
i = 0
@@ -238,14 +245,14 @@ class Module:
desc = package.status
if date and desc:
- s = '\002%s\002%s %s - %s' % (package.code, label, date, desc)
+ s = '%s %s - %s' % (package, date, desc)
else:
- s = 'No tracking info found for \002%s\002%s' % (package.code, label)
+ s = 'No tracking info found for %s' % package
results.append(s)
if i == 0:
- results.append('No packages found for \002%s\002%s' % (row.code, label))
+ results.append('No packages found for %s' % row)
if len(results):
msg = results
@@ -291,10 +298,7 @@ class Module:
trackings = []
consignments = session.query(Consignment).filter_by(nick = nick)
for row in consignments:
- s = row.code
- if row.label:
- s += ' (%s)' % row.label
- trackings.append(s)
+ trackings.append(str(row))
if len(trackings):
msg = 'Trackings for %s: %s' % (nick, ', '.join(trackings))
else:
@@ -394,7 +398,6 @@ class Module:
if consignment.last and consignment.last > now - td:
return
consignment.last = now
- label = (' (%s)' % consignment.label if consignment.label else u'').encode('utf-8')
target = consignment.channel or consignment.nick
target = target.encode('utf-8')
removed = False
@@ -429,7 +432,7 @@ class Module:
code = data.code
last = data.date
desc = data.desc
- msg = '%s: \002%s\002%s %s - %s' % (consignment.nick.encode('utf-8'), package.code.encode('utf-8'), label, last, desc)
+ msg = '%s: %s %s - %s' % (consignment.nick.encode('utf-8'), package, last, desc)
if data.delivered:
session.delete(package)
msg += ' (Package delivered - tracking stopped)'
@@ -441,17 +444,17 @@ class Module:
if announce:
self.irc.msg(target, msg)
elif package.last != None and package.last < datetime.datetime.utcnow() - datetime.timedelta(hours = 24*30):
- msg = '%s: Removing stale package \002%s\002%s' % (consignment.nick.encode('utf-8'), consignment.code.encode('utf-8'), label)
+ msg = '%s: Removing stale package %s' % (consignment.nick.encode('utf-8'), consignment)
self.irc.msg(target, msg)
session.delete(package)
removed = True
# empty consignment and 30 days old
if len(consignment.packages) == 0 and consignment.added < datetime.datetime.utcnow() - datetime.timedelta(hours = 24*30):
- msg = '%s: Removing stale consignment \002%s\002%s' % (consignment.nick.encode('utf-8'), consignment.code.encode('utf-8'), label)
+ msg = '%s: Removing stale consignment %s' % (consignment.nick.encode('utf-8'), consignment)
self.irc.msg(target, msg)
session.delete(consignment)
if removed and len(consignment.packages) == 0:
- msg = '%s: \002%s\002%s is no longer being tracked' % (consignment.nick.encode('utf-8'), consignment.code.encode('utf-8'), label)
+ msg = '%s: %s is no longer being tracked' % (consignment.nick.encode('utf-8'), consignment)
self.irc.msg(target, msg)
session.delete(consignment)