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,22 +122,34 @@ class Parceloob(ReplApplication):
Stop tracking a parcel. Stop tracking a parcel.
""" """
parcel = self.get_object(line, 'get_parcel_tracking') removed = False
if not parcel: # Always try to first remove the parcel, the untrack should always success
print >>sys.stderr, 'Error: the parcel "%s" is not found' % line
return 2
parcels = set(self.storage.get('tracking', default=[])) parcels = set(self.storage.get('tracking', default=[]))
try: try:
parcels.remove(parcel.fullid) parcels.remove(line)
removed = True
except KeyError: except KeyError:
print >>sys.stderr, "Error: parcel \"%s\" wasn't tracked" % parcel.fullid pass
return 2
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.set('tracking', list(parcels))
self.storage.save() 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): def do_status(self, line):
""" """