parameters: (self)
docstring: Delete old cron by resetting a new cron file
docstring_summary: Delete old cron by resetting a new cron file
docstring_tokens: Delete old cron by resetting a new cron file
function: def del_cron(self):
          """
          Delete old cron by resetting a new cron file
          """
          self.logger.debug("Deleting old cron...")
          crontab_str = self.get_old_cron()
          crontab_list = crontab_str.split('\n')
          crontab_list_new = []
          clean_cmd = self.cmd
          versions = re.findall(r'\d{5}/', self.cmd)
          version = versions[0] if versions else None
          if version:
              clean_cmd = clean_cmd.split(version)[-1]
          self.logger.debug('Clean cron with [%s]' % clean_cmd)
  
          for old_cron in crontab_list:
              if clean_cmd not in old_cron:
                  crontab_list_new.append(old_cron)
          cron_str = "\n".join(crontab_list_new) + "\n"
          with os.fdopen(os.open(self.tmp_file, flags, modes), "w") as fp:
              fp.write(cron_str)
          del_cron_cmd = ["crontab", self.tmp_file]
          status, output = self.exe_cmd(del_cron_cmd)
          if os.path.isfile(self.tmp_file):
              os.remove(self.tmp_file)
          self.logger.info("Delete cron result:status[%s]-output[%s]." % (
              status or Constant.SUCCESS, output))
function_tokens: def del_cron ( self ) : self . logger . debug ( "Deleting old cron..." ) crontab_str = self . get_old_cron ( ) crontab_list = crontab_str . split ( '\n' ) crontab_list_new = [ ] clean_cmd = self . cmd versions = re . findall ( r'\d{5}/' , self . cmd ) version = versions [ 0 ] if versions else None if version : clean_cmd = clean_cmd . split ( version ) [ - 1 ] self . logger . debug ( 'Clean cron with [%s]' % clean_cmd ) for old_cron in crontab_list : if clean_cmd not in old_cron : crontab_list_new . append ( old_cron ) cron_str = "\n" . join ( crontab_list_new ) + "\n" with os . fdopen ( os . open ( self . tmp_file , flags , modes ) , "w" ) as fp : fp . write ( cron_str ) del_cron_cmd = [ "crontab" , self . tmp_file ] status , output = self . exe_cmd ( del_cron_cmd ) if os . path . isfile ( self . tmp_file ) : os . remove ( self . tmp_file ) self . logger . info ( "Delete cron result:status[%s]-output[%s]." % ( status or Constant . SUCCESS , output ) )