Always success in untrack if the id is in the storage
This commit is contained in:
parent
2a0d4a5e7f
commit
695b98ee79
1 changed files with 21 additions and 9 deletions
|
|
@ -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):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue