summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-01-11 19:38:05 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2011-01-11 19:38:05 +0100
commit44bfc9675204f65ea79bdefa4c66ccfedbfa0664 (patch)
treeddd71e29b876226ed4afef7a77c752b5d2e9fe99 /modules
parent573b40f76a1692f87a0eb80120cab5f7b3bf6cee (diff)
tracking: Attempt to detect conflicts by committing when a package is added.
Diffstat (limited to 'modules')
-rw-r--r--modules/tracking.py28
1 files changed, 13 insertions, 15 deletions
diff --git a/modules/tracking.py b/modules/tracking.py
index 1b7428c..08af651 100644
--- a/modules/tracking.py
+++ b/modules/tracking.py
@@ -15,7 +15,7 @@ from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relation, backref
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.exc import IntegrityError
-from sqlalchemy.sql import or_
+from sqlalchemy.sql import or_, and_
engine = Session = None
Base = declarative_base()
@@ -312,11 +312,19 @@ class Module:
return
for data in data_:
try:
- package = session.query(Package).filter_by(code = data[0]).one()
+ package = session.query(Package).filter(and_(Package.consignment_id == consignment.id, Package.code == data[0])).one()
except NoResultFound:
package = Package(consignment.id, data[0])
session.add(package)
- package = session.query(Package).filter_by(code = data[0]).one()
+ try:
+ session.commit()
+ except IntegrityError:
+ # assume several packets within the same consignment was added as a consignment
+ session.rollback()
+ removed = True
+ self.irc.msg(target, '%s: \002%s\002 conflicts with another consignment' % (target, code))
+ break
+ package = session.query(Package).filter(and_(Package.consignment_id == consignment.id, Package.code == data[0])).one()
if package.last == None or data[1] > package.last:
code = data[0]
@@ -335,8 +343,7 @@ class Module:
self.irc.msg(target, msg)
if removed and len(consignment.packages) == 0:
msg = '%s: \002%s\002%s is no longer being tracked' % (consignment.nick, consignment.code, label)
- if announce:
- self.irc.msg(target, msg.encode('utf-8'))
+ self.irc.msg(target, msg.encode('utf-8'))
session.delete(consignment)
def lc_callback(self):
@@ -345,16 +352,7 @@ class Module:
consignments = session.query(Consignment).filter(Consignment.channel.in_(config.get(self.irc.factory.server, 'channels').split()))
for row in consignments:
self.update_consignment(session, row)
- try:
- session.commit()
- except IntegrityError as e:
- # assume several packets within the same consignment was added as a consignment
- target = consignment.channel or consignment.nick
- target = target.encode('utf-8')
- session.rollback()
- session.delete(consignment)
- session.commit()
- self.irc.msg(target, '%s: \002%s\002 conflicts with another consignment - tracking stopped' % (target, code))
+ session.commit()
finally:
session.close()