(self, update_type)
Update the current cronfile, used by run_type `update` or `clear`.
        This will find the block inside cronfile corresponding to this Plan
        object and replace it.

        :param update_type: update or clear, if you choose update, the block
                            corresponding to this plan object will be replaced
                            with the new cron job entries, otherwise, they
                            will be wiped.
Update the current cronfile, used by run_type `update` or `clear`.
        This will find the block inside cronfile corresponding to this Plan
        object and replace it.
Update the current cronfile used by run_type update or clear . This will find the block inside cronfile corresponding to this Plan object and replace it .
def update_crontab(self, update_type):
        """Update the current cronfile, used by run_type `update` or `clear`.
        This will find the block inside cronfile corresponding to this Plan
        object and replace it.

        :param update_type: update or clear, if you choose update, the block
                            corresponding to this plan object will be replaced
                            with the new cron job entries, otherwise, they
                            will be wiped.
        """
        current_crontab = self.read_crontab()

        if update_type == "update":
            action = "updated"
            crontab_content = self.cron_content
        elif update_type == "clear":
            action = "cleared"
            crontab_content = ''

        # Check for unbegined or unended block
        comment_begin_re = re.compile(r"^%s$" % self.comment_begin, re.M)
        comment_end_re = re.compile(r"^%s$" % self.comment_end, re.M)
        cron_block_re = re.compile(r"^%s$.+^%s$" %
                                   (self.comment_begin, self.comment_end),
                                   re.M | re.S)

        comment_begin_match = comment_begin_re.search(current_crontab)
        comment_end_match = comment_end_re.search(current_crontab)

        if comment_begin_match and not comment_end_match:
            raise PlanError("Your crontab file is not ended, it contains "
                            "'%s', but no '%s'" % (self.comment_begin,
                                                   self.comment_end))
        elif not comment_begin_match and comment_end_match:
            raise PlanError("Your crontab file has no begining, it contains "
                            "'%s', but no '%s'" % (self.comment_end,
                                                   self.comment_begin))

        # Found our existing block and replace it with the new one
        # Otherwise, append out new cron jobs after others
        if comment_begin_match and comment_end_match:
            updated_content = cron_block_re.sub(crontab_content,
                                                current_crontab)
        else:
            updated_content = "\n\n".join((current_crontab, crontab_content))

        # Write the updated cronfile back to crontab
        self._write_to_crontab(action, updated_content)
def update_crontab ( self , update_type ) : current_crontab = self . read_crontab ( ) if update_type == "update" : action = "updated" crontab_content = self . cron_content elif update_type == "clear" : action = "cleared" crontab_content = '' # Check for unbegined or unended block comment_begin_re = re . compile ( r"^%s$" % self . comment_begin , re . M ) comment_end_re = re . compile ( r"^%s$" % self . comment_end , re . M ) cron_block_re = re . compile ( r"^%s$.+^%s$" % ( self . comment_begin , self . comment_end ) , re . M | re . S ) comment_begin_match = comment_begin_re . search ( current_crontab ) comment_end_match = comment_end_re . search ( current_crontab ) if comment_begin_match and not comment_end_match : raise PlanError ( "Your crontab file is not ended, it contains " "'%s', but no '%s'" % ( self . comment_begin , self . comment_end ) ) elif not comment_begin_match and comment_end_match : raise PlanError ( "Your crontab file has no begining, it contains " "'%s', but no '%s'" % ( self . comment_end , self . comment_begin ) ) # Found our existing block and replace it with the new one # Otherwise, append out new cron jobs after others if comment_begin_match and comment_end_match : updated_content = cron_block_re . sub ( crontab_content , current_crontab ) else : updated_content = "\n\n" . join ( ( current_crontab , crontab_content ) ) # Write the updated cronfile back to crontab self . _write_to_crontab ( action , updated_content )