From 695b98ee791a9710e0683467bc38bf517bd690e8 Mon Sep 17 00:00:00 2001 From: Florent Date: Thu, 27 Feb 2014 16:12:33 +0100 Subject: [PATCH] Always success in untrack if the id is in the storage --- weboob/applications/parceloob/parceloob.py | 30 +++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/weboob/applications/parceloob/parceloob.py b/weboob/applications/parceloob/parceloob.py index 61e5892d..398cf4b0 100644 --- a/weboob/applications/parceloob/parceloob.py +++ b/weboob/applications/parceloob/parceloob.py @@ -122,22 +122,34 @@ class Parceloob(ReplApplication): Stop tracking a parcel. """ - parcel = self.get_object(line, 'get_parcel_tracking') - if not parcel: - print >>sys.stderr, 'Error: the parcel "%s" is not found' % line - return 2 - + removed = False + # Always try to first remove the parcel, the untrack should always success parcels = set(self.storage.get('tracking', default=[])) try: - parcels.remove(parcel.fullid) + parcels.remove(line) + removed = True except KeyError: - print >>sys.stderr, "Error: parcel \"%s\" wasn't tracked" % parcel.fullid - return 2 + pass + + if not removed: + parcel = self.get_object(line, 'get_parcel_tracking') + if not parcel: + print >>sys.stderr, 'Error: the parcel "%s" is not found' % line + return 2 + + try: + parcels.remove(parcel.fullid) + except KeyError: + print >>sys.stderr, "Error: parcel \"%s\" wasn't tracked" % parcel.fullid + return 2 self.storage.set('tracking', list(parcels)) self.storage.save() - print "Parcel \"%s\" isn't tracked anymore." % parcel.fullid + if removed: + print "Parcel \"%s\" isn't tracked anymore." % line + else: + print "Parcel \"%s\" isn't tracked anymore." % parcel.fullid def do_status(self, line): """