find_comment(comment) with multiple same comment does not return whole job list
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
python-crontab |
Fix Committed
|
High
|
Martin Owens |
Bug Description
Hi, the method find_comment() seems to not return all lines if we have a mutliple time the same comment name in the crontab.
Step to reproduce:
command = "/path/
comment = "SAMECOMMENT"
period_string = "* * 5 5 *"
my_user_cron = CronTab(user=True)
for x in range(0, 5, 1):
job = my_user_
if CronSlices.
my_
# here we have:
# * * 5 5 * /path/to/my/command # SAMECOMMENT
# * * 5 5 * /path/to/my/command # SAMECOMMENT
# * * 5 5 * /path/to/my/command # SAMECOMMENT
# remove all SAMECOMMENT job
iter = my_user_
for job in iter:
print "remove job %s" % job
my_
my_user_
# now we check the content
new_iter = my_user_
for job in iter:
print "Still a job: %s" % job
# output
# remove job * * 5 5 * /path/to/my/command # SAMECOMMENT
# remove job * * 5 5 * /path/to/my/command # SAMECOMMENT
# Still a job: * * 5 5 * /path/to/my/command # SAMECOMMENT
I've committed a fix. This was an iterator issue, where removal of the items would shorten the list and cause the next iteration to skip one.
Test is now in place to catch this error.