Always success in untrack if the id is in the storage

This commit is contained in:
Florent 2014-02-27 16:12:33 +01:00
commit 695b98ee79

View file

@ -122,12 +122,21 @@ class Parceloob(ReplApplication):
Stop tracking a parcel. Stop tracking a parcel.
""" """
removed = False
# Always try to first remove the parcel, the untrack should always success
parcels = set(self.storage.get('tracking', default=[]))
try:
parcels.remove(line)
removed = True
except KeyError:
pass
if not removed:
parcel = self.get_object(line, 'get_parcel_tracking') parcel = self.get_object(line, 'get_parcel_tracking')
if not parcel: if not parcel:
print >>sys.stderr, 'Error: the parcel "%s" is not found' % line print >>sys.stderr, 'Error: the parcel "%s" is not found' % line
return 2 return 2
parcels = set(self.storage.get('tracking', default=[]))
try: try:
parcels.remove(parcel.fullid) parcels.remove(parcel.fullid)
except KeyError: except KeyError:
@ -137,6 +146,9 @@ class Parceloob(ReplApplication):
self.storage.set('tracking', list(parcels)) self.storage.set('tracking', list(parcels))
self.storage.save() self.storage.save()
if removed:
print "Parcel \"%s\" isn't tracked anymore." % line
else:
print "Parcel \"%s\" isn't tracked anymore." % parcel.fullid print "Parcel \"%s\" isn't tracked anymore." % parcel.fullid
def do_status(self, line): def do_status(self, line):