예제 #1
0
파일: Symlink.py 프로젝트: ab/bcfg2
 def install(self, entry):
     ondisk = self._exists(entry, remove=True)
     if ondisk:
         self.logger.info("POSIX: Symlink %s cleanup failed" %
                          entry.get('name'))
     try:
         os.symlink(entry.get('to'), entry.get('name'))
         rv = True
     except OSError:
         err = sys.exc_info()[1]
         self.logger.error("POSIX: Failed to create symlink %s to %s: %s" %
                           (entry.get('name'), entry.get('to'), err))
         rv = False
     return POSIXTool.install(self, entry) and rv
예제 #2
0
파일: File.py 프로젝트: stpierre/bcfg2
    def install(self, entry):
        """Install device entries."""
        if not os.path.exists(os.path.dirname(entry.get('name'))):
            if not self._makedirs(entry,
                                  path=os.path.dirname(entry.get('name'))):
                return False
        newfile = self._write_tmpfile(entry)
        if not newfile:
            return False
        rv = self._set_perms(entry, path=newfile)
        if not self._rename_tmpfile(newfile, entry):
            return False

        return POSIXTool.install(self, entry) and rv
예제 #3
0
파일: Directory.py 프로젝트: ab/bcfg2
    def install(self, entry):
        """Install device entries."""
        fmode = self._exists(entry)

        if fmode and not stat.S_ISDIR(fmode[stat.ST_MODE]):
            self.logger.info("POSIX: Found a non-directory entry at %s, "
                             "removing" % entry.get('name'))
            try:
                os.unlink(entry.get('name'))
                fmode = False
            except OSError:
                err = sys.exc_info()[1]
                self.logger.error("POSIX: Failed to unlink %s: %s" %
                                  (entry.get('name'), err))
                return False
        elif fmode:
            self.logger.debug("POSIX: Found a pre-existing directory at %s" %
                              entry.get('name'))
        
        rv = True
        if not fmode:
            rv &= self._makedirs(entry)

        if entry.get('prune', 'false') == 'true':
            ulfailed = False
            for pent in entry.findall('Prune'):
                pname = pent.get('path')
                ulfailed = False
                if os.path.isdir(pname):
                    rm = shutil.rmtree
                else:
                    rm = os.unlink
                try:
                    self.logger.debug("POSIX: Removing %s" % pname)
                    rm(pname)
                except OSError:
                    err = sys.exc_info()[1]
                    self.logger.error("POSIX: Failed to unlink %s: %s" %
                                      (pname, err))
                    ulfailed = True
            if ulfailed:
                # even if prune failed, we still want to install the
                # entry to make sure that we get permissions and
                # whatnot set
                rv = False
        return POSIXTool.install(self, entry) and rv
예제 #4
0
파일: Device.py 프로젝트: stpierre/bcfg2
 def install(self, entry):
     if not self._exists(entry, remove=True):
         try:
             dev_type = entry.get('dev_type')
             mode = device_map[dev_type] | int(entry.get('perms'), 8)
             if dev_type in ['block', 'char']:
                 major = int(entry.get('major'))
                 minor = int(entry.get('minor'))
                 device = os.makedev(major, minor)
                 os.mknod(entry.get('name'), mode, device)
             else:
                 os.mknod(entry.get('name'), mode)
         except (KeyError, OSError, ValueError):
             err = sys.exc_info()[1]
             self.logger.error('POSIX: Failed to install %s: %s' %
                               (entry.get('name'), err))
             return False
     return POSIXTool.install(self, entry)