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