Exemplo n.º 1
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."""
    remove()
    try:
        if MSWINDOWS:
            # We'll edit PyCrontab directly
            crontab = getPyCrontab()
            fh = open(crontab, 'w')
        else:
            # We'll create a temporary file to pass to crontab as input
            fd, path = tempfile.mkstemp()
            fh = os.fdopen(fd, 'wb')

        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()))

        fh.close()
        if not MSWINDOWS:
            execute(['crontab', path])
            os.remove(path)
    except IOError:
        return False
    return True
Exemplo n.º 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."""
    remove()
    try:
        if MSWINDOWS:
            # We'll edit PyCrontab directly
            crontab = getPyCrontab()
            fh = open(crontab, "w")
        else:
            # We'll create a temporary file to pass to crontab as input
            fd, path = tempfile.mkstemp()
            fh = os.fdopen(fd, "wb")

        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()))

        fh.close()
        if not MSWINDOWS:
            execute(["crontab", path])
            os.remove(path)
    except IOError:
        return False
    return True
Exemplo n.º 3
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
Exemplo n.º 4
0
def getPyCrontab():
    """Read the PyCron crontab file on Windows"""
    prefConf = config.PrefsConf()
    pycronLoc = prefConf.get('Preferences', 'pycronLoc')
    # See if the configuration file exists
    pycronConfig = os.path.join(encode(pycronLoc), 'pycron.cfg')
    if os.path.exists(pycronConfig):
        pycronConf = config.ConfigFile(decode(pycronConfig))
    # If not, does the sample configuation exist?
    elif os.path.exists('%s.sample' % pycronConfig):
        pycronConf = config.ConfigFile(decode('%s.sample' % pycronConfig))
    # No cron file found!
    else:
        raise CronError(
            _("Could not locate the pycron or the sample pycron configuration in %s"
              % pycronLoc))
    # Read in the configuration file we found
    pycrontab = os.path.join(pycronLoc,
                             pycronConf.get('pycron', 'crontab_filename'))
    if not os.path.exists(pycrontab):
        try:
            fh = open(pycrontab, 'w')
            fh.write('# PyCron crontab file\n')
            fh.close()
        except:
            raise CronError(
                _("Could not locate the pycron or the sample pycron crontab file in %s"
                  % pycronLoc))
    return pycrontab
Exemplo n.º 5
0
    def envoi_irc(self):
        '''Fonction pour envoyer les messages sur IRC (le contenu de self.line_Edit_chat.text()'''
        if self.line_Edit_chat.text() != '':
            texte = (unicode(self.line_Edit_chat.text())).encode('utf-8')

            if texte[0] != "/":  # On envoi rien si c'est une commande
                # Si c'est un message normal...
                if self.info_13 == 1:
                    # niveau de gris si le fond est noir
                    couleur = "150, 150, 150"
                else:
                    couleur = "100, 100, 100"

                chaine = i18n.encode(
                    "--><span style='color: rgb(" + couleur + ");'> " + str(self.pseudo) + ': ' + texte + '\n' + "</span>")

                #variables.liste_canaux[variables.canal_courant] = variables.liste_canaux[variables.canal_courant] + chaine
                # self.insert_txt_irc(chaine,1)
                canal = self.trouve_canal_courant()
                self.Aliste_txt_irc(chaine, canal, envoi=1)
                self.th_irc.envoi(texte, canal)

            self.line_Edit_chat.setText("")
Exemplo n.º 6
0
def getPyCrontab():
  """Read the PyCron crontab file on Windows"""
  prefConf = config.PrefsConf()
  pycronLoc = prefConf.get('Preferences', 'pycronLoc')
  # See if the configuration file exists
  pycronConfig = os.path.join(encode(pycronLoc), 'pycron.cfg')
  if os.path.exists(pycronConfig):
    pycronConf = config.ConfigFile(decode(pycronConfig))
  # If not, does the sample configuation exist?
  elif os.path.exists('%s.sample' % pycronConfig):
    pycronConf = config.ConfigFile(decode('%s.sample' % pycronConfig))
  # No cron file found!
  else:
    raise CronError(_("Could not locate the pycron or the sample pycron configuration in %s" % pycronLoc))
  # Read in the configuration file we found
  pycrontab = os.path.join(pycronLoc, pycronConf.get('pycron', 'crontab_filename'))
  if not os.path.exists(pycrontab):
    try:
      fh = open(pycrontab, 'w')
      fh.write('# PyCron crontab file\n')
      fh.close()
    except:
      raise CronError(_("Could not locate the pycron or the sample pycron crontab file in %s" % pycronLoc))
  return pycrontab