示例#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
示例#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
示例#3
0
 def createDiskInfo(self):
   """Print disk info to a file in tempdir"""
   fd, path = tempfile.mkstemp(suffix='.txt', prefix="%s - tmp" % _('Disk Information'))
   fh = os.fdopen(fd, 'w')
   retval, stdout, stderr = fwbackups.execute('fdisk -l', env=self.environment, shell=True, stdoutfd=fh)
   fh.close()
   return path
示例#4
0
def remove():
  """Removes/empties a user's crontab"""
  if MSWINDOWS:
    crontab = getPyCrontab()
    fh = open(crontab, 'w')
    fh.write('')
    fh.close()
  else:
    sub, stdout, stderr = execute(['crontab', '-r'], stdoutfd=subprocess.PIPE)
示例#5
0
def remove():
    """Removes/empties a user's crontab"""
    if MSWINDOWS:
        crontab = getPyCrontab()
        fh = open(crontab, "w")
        fh.write("")
        fh.close()
    else:
        sub, stdout, stderr = execute(["crontab", "-r"], stdoutfd=subprocess.PIPE)
示例#6
0
def remove():
    """Removes/empties a user's crontab"""
    if MSWINDOWS:
        crontab = getPyCrontab()
        fh = open(crontab, 'w')
        fh.write('')
        fh.close()
    else:
        sub, stdout, stderr = execute(['crontab', '-r'],
                                      stdoutfd=subprocess.PIPE)
示例#7
0
    def createPkgLists(self):
        """Create the pkg lists in tempdir"""
        # Start as a dictionary so we can keep track of which items we have already
        # processed. See comment at retur for more info.
        pkgListFiles = {}
        for path in os.environ["PATH"].split(":"):
            if os.path.exists(os.path.join(path, "rpm")) and not pkgListFiles.has_key("rpm"):
                fd, path = tempfile.mkstemp(suffix=".txt", prefix="%s - tmp" % _("rpm - Package list"))
                fh = os.fdopen(fd, "w")
                # try with rpm-python, but if not just execute it like the rest
                try:
                    import rpm

                    pyrpm = True
                except ImportError:
                    pyrpm = False
                if pyrpm:
                    ts = rpm.ts()
                    # Equivalent to rpm -qa
                    mi = ts.dbMatch()
                    for hdr in mi:
                        fh.write("%s-%s-%s.%s\n" % (hdr["name"], hdr["version"], hdr["release"], hdr["arch"]))
                else:
                    retval, stdout, stderr = fwbackups.execute("rpm -qa", env=self.environment, shell=True, stdoutfd=fh)
                pkgListFiles["rpm"] = path
                fh.close()
            if os.path.exists(os.path.join(path, "pacman")) and not pkgListFiles.has_key("pacman"):
                fd, path = tempfile.mkstemp(suffix=".txt", prefix="%s - tmp" % _("Pacman - Package list"))
                fh = os.fdopen(fd, "w")
                retval, stdout, stderr = fwbackups.execute("pacman -Qq", env=self.environment, shell=True, stdoutfd=fh)
                pkgListFiles["pacman"] = path
                fh.close()
            if os.path.exists(os.path.join(path, "dpkg")) and not pkgListFiles.has_key("dpkg"):
                fd, path = tempfile.mkstemp(suffix=".txt", prefix="%s - tmp" % _("dpkg - Package list"))
                fh = os.fdopen(fd, "w")
                retval, stdout, stderr = fwbackups.execute("dpkg -l", env=self.environment, shell=True, stdoutfd=fh)
                pkgListFiles["dpkg"] = path
                fh.close()
        # We want to return a list of only the filenames
        return pkgListFiles.values()
示例#8
0
 def createPkgLists(self):
   """Create the pkg lists in tempdir"""
   # Start as a dictionary so we can keep track of which items we have already
   # processed. See comment at retur for more info.
   pkgListFiles = {}
   for path in os.environ['PATH'].split(':'):
     if os.path.exists(os.path.join(path, 'rpm')) and not pkgListFiles.has_key('rpm'):
       fd, path = tempfile.mkstemp(suffix='.txt', prefix="%s - tmp" % _('rpm - Package list'))
       fh = os.fdopen(fd, "w")
       # try with rpm-python, but if not just execute it like the rest
       try:
         import rpm
         pyrpm = True
       except ImportError:
         pyrpm = False
       if pyrpm:
         ts=rpm.ts()
         # Equivalent to rpm -qa
         mi=ts.dbMatch()
         for hdr in mi:
           fh.write("%s-%s-%s.%s\n" % (hdr['name'], hdr['version'], hdr['release'], hdr['arch']))
       else:
         retval, stdout, stderr = fwbackups.execute('rpm -qa', env=self.environment, shell=True, stdoutfd=fh)
       pkgListFiles['rpm'] = path
       fh.close()
     if os.path.exists(os.path.join(path, 'pacman')) and not pkgListFiles.has_key('pacman'):
       fd, path = tempfile.mkstemp(suffix='.txt', prefix="%s - tmp" % _('Pacman - Package list'))
       fh = os.fdopen(fd, 'w')
       retval, stdout, stderr = fwbackups.execute('pacman -Qq', env=self.environment, shell=True, stdoutfd=fh)
       pkgListFiles['pacman'] = path
       fh.close()
     if os.path.exists(os.path.join(path, 'dpkg')) and not pkgListFiles.has_key('dpkg'):
       fd, path = tempfile.mkstemp(suffix='.txt', prefix="%s - tmp" % _('dpkg - Package list'))
       fh = os.fdopen(fd, 'w')
       retval, stdout, stderr = fwbackups.execute('dpkg -l', env=self.environment, shell=True, stdoutfd=fh)
       pkgListFiles['dpkg'] = path
       fh.close()
   # We want to return a list of only the filenames
   return pkgListFiles.values()