Skip to content

Commit

Permalink
Bugfix for editing too much
Browse files Browse the repository at this point in the history
  • Loading branch information
fundor333 committed Aug 13, 2020
1 parent 5ef7110 commit af6bef6
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions crontab.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def _read_cron_file(self, rows):
except Exception as e:
self._log.error(e)
self._delete_line(self._temp_file)
with open(self._temp_file, "w+") as file_object:
with open(self._temp_file, "a") as file_object:
for row in rows:
file_object.write("\n{}".format(row))
file_object.write("{}".format(row))
subprocess.call(["crontab", "-r"])
subprocess.call(["crontab", self._temp_file])
os.remove(self._temp_file)
Expand All @@ -50,10 +50,8 @@ def _delete_line(self, original_file):
try:
is_skipped = False
dummy_file = original_file + '.bak'
with open(original_file, 'r+') as read_obj, open(dummy_file, 'w+') as write_obj:
with open(original_file, 'r') as read_obj, open(dummy_file, 'w+') as write_obj:
for line in read_obj:
self._log.info(line)
self._log.info(not self._comment in line)
if not self._comment in line:
write_obj.write(line)
else:
Expand Down

0 comments on commit af6bef6

Please sign in to comment.