Beispiel #1
0
 def cancelOperation(self):
   """Requests the current operation stops as soon as possible"""
   self.logger.logmsg('INFO', _('Canceling the current operation!'))
   if self.pids:
     for process in self.pids:
       try:
         self.logger.logmsg('DEBUG', _('Stopping process with ID %s') % process)
         fwbackups.kill(process, 9)
       except Exception, error:
         self.logger.logmsg('WARNING', _('Could not stop process %(a)s: %(b)s' % (process, error)))
         continue
Beispiel #2
0
def write(crontabEntries=[]):
  """Write a crontab-formatted file from the list of fstabLines. Return values
  of 0 or 1 to indicate a failure writing to the crontab or a success
  respectively."""
  if LINUX:
    environ = {'EDITOR': 'python %s/cronwriter.py' % INSTALL_DIR,
               'VISUAL': 'python %s/cronwriter.py' % INSTALL_DIR}
  elif DARWIN:
    environ = {'EDITOR': '/fwbackups-cronwriter.py',
               'VISUAL': '/fwbackups-cronwriter.py'}
  else:
    environ = {}
  remove()
  try:
    if MSWINDOWS:
      crontab = getPyCrontab()
      fh = open(crontab, 'w')
    else:
      if DARWIN:
        if os.path.islink('/fwbackups-cronwriter.py'):
          os.remove('/fwbackups-cronwriter.py')
        os.symlink(os.path.join(encode(INSTALL_DIR), 'cronwriter.py'), '/fwbackups-cronwriter.py')
      sub = executeSub(['crontab', '-e'], environ, stdoutfd=subprocess.PIPE)
      fh = sub.stdin
    # Write the content to the crontab
    for crontabEntry in crontabEntries:
      if isinstance(crontabEntry, crontabLine): # generate the entry text
        fh.write(encode(crontabEntry.generate_entry_text()))
      else:
        fh.write(encode(crontabEntry.get_raw_entry_text()))
    time.sleep(1)
    fh.close()
    if not MSWINDOWS:
      counter = 0.0
      while sub.poll() in [None, ""] and counter < 5.0: # After waiting for 5 seconds, assume that the crontab could not be installed
        time.sleep(0.1)
        counter += 0.1
      if sub.poll() in [None, ""]:
        # Soft-terminate the process if it still hasn't finished
        kill(sub.pid, 15)
        sub.wait()
        raise ValidationError(_("The crontab could not be saved"))
      if DARWIN:
        os.remove('/fwbackups-cronwriter.py')
      if sub.poll() != os.EX_OK:
        stdout = ' '.join(sub.stdout.readlines())
        stderr = ' '.join(sub.stderr.readlines())
        raise CronError(_('Could not write new crontab:\n%(a)s%(b)s') % {'a': stdout, 'b': stderr})
    fh.close()
  except IOError: # can't open crontab file
    return 0
  return 1