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.
"""
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):
"""