Пример #1
0
    def action_create(self):
        path = self.resource.path

        if sudo.path_lexists(path):
            oldpath = os.path.realpath(path)
            if oldpath == self.resource.to:
                return
            if not sudo.path_lexists(path):
                raise Fail(
                    "%s trying to create a symlink with the same name as an existing file or directory"
                    % self.resource)
            Logger.info("%s replacing old symlink to %s" %
                        (self.resource, oldpath))
            sudo.unlink(path)

        if self.resource.hard:
            if not sudo.path_exists(self.resource.to):
                raise Fail(
                    "Failed to apply %s, linking to nonexistent location %s" %
                    (self.resource, self.resource.to))
            if sudo.path_isdir(self.resource.to):
                raise Fail(
                    "Failed to apply %s, cannot create hard link to a directory (%s)"
                    % (self.resource, self.resource.to))

            Logger.info("Creating hard %s" % self.resource)
            sudo.link(self.resource.to, path)
        else:
            if not sudo.path_exists(self.resource.to):
                Logger.info("Warning: linking to nonexistent location %s" %
                            self.resource.to)

            Logger.info("Creating symbolic %s to %s" %
                        (self.resource, self.resource.to))
            sudo.symlink(self.resource.to, path)
Пример #2
0
  def action_create(self):
    path = self.resource.path

    if sudo.path_lexists(path):
      oldpath = os.path.realpath(path)
      if oldpath == self.resource.to:
        return
      if not sudo.path_lexists(path):
        raise Fail(
          "%s trying to create a symlink with the same name as an existing file or directory" % self.resource)
      Logger.info("%s replacing old symlink to %s" % (self.resource, oldpath))
      sudo.unlink(path)
      
    if self.resource.hard:
      if not sudo.path_exists(self.resource.to):
        raise Fail("Failed to apply %s, linking to nonexistent location %s" % (self.resource, self.resource.to))
      if sudo.path_isdir(self.resource.to):
        raise Fail("Failed to apply %s, cannot create hard link to a directory (%s)" % (self.resource, self.resource.to))
      
      Logger.info("Creating hard %s" % self.resource)
      sudo.link(self.resource.to, path)
    else:
      if not sudo.path_exists(self.resource.to):
        Logger.info("Warning: linking to nonexistent location %s" % self.resource.to)
        
      Logger.info("Creating symbolic %s to %s" % (self.resource, self.resource.to))
      sudo.symlink(self.resource.to, path)
Пример #3
0
  def action_create(self):
    path = self.resource.path

    if not sudo.path_exists(path):
      Logger.info("Creating directory %s since it doesn't exist." % self.resource)
      
      # dead links should be followed, else we gonna have failures on trying to create directories on top of them.
      if self.resource.follow:
        # Follow symlink until the tail.
        followed_links = set()
        while sudo.path_lexists(path):
          if path in followed_links:
            raise Fail("Applying %s failed, looped symbolic links found while resolving %s" % (self.resource, path))
          followed_links.add(path)
          path = sudo.readlink(path)
          
        if path != self.resource.path:
          Logger.info("Following the link {0} to {1} to create the directory".format(self.resource.path, path))

      if self.resource.create_parents:
        sudo.makedirs(path, self.resource.mode or 0755)
      else:
        dirname = os.path.dirname(path)
        if not sudo.path_isdir(dirname):
          raise Fail("Applying %s failed, parent directory %s doesn't exist" % (self.resource, dirname))
        
        sudo.makedir(path, self.resource.mode or 0755)
      
    if not sudo.path_isdir(path):
      raise Fail("Applying %s failed, file %s already exists" % (self.resource, path))
    
    _ensure_metadata(path, self.resource.owner, self.resource.group,
                        mode=self.resource.mode, cd_access=self.resource.cd_access,
                        recursive_ownership=self.resource.recursive_ownership, recursive_mode_flags=self.resource.recursive_mode_flags, 
                        recursion_follow_links=self.resource.recursion_follow_links, safemode_folders=self.resource.safemode_folders)
Пример #4
0
  def action_create(self):
    path = self.resource.path

    if not sudo.path_exists(path):
      Logger.info("Creating directory %s since it doesn't exist." % self.resource)
      
      # dead links should be followed, else we gonna have failures on trying to create directories on top of them.
      if self.resource.follow:
        # Follow symlink until the tail.
        followed_links = set()
        while sudo.path_lexists(path):
          if path in followed_links:
            raise Fail("Applying %s failed, looped symbolic links found while resolving %s" % (self.resource, path))
          followed_links.add(path)
          path = sudo.readlink(path)
          
        if path != self.resource.path:
          Logger.info("Following the link {0} to {1} to create the directory".format(self.resource.path, path))

      if self.resource.recursive:
        sudo.makedirs(path, self.resource.mode or 0755)
      else:
        dirname = os.path.dirname(path)
        if not sudo.path_isdir(dirname):
          raise Fail("Applying %s failed, parent directory %s doesn't exist" % (self.resource, dirname))
        
        sudo.makedir(path, self.resource.mode or 0755)
      
    if not sudo.path_isdir(path):
      raise Fail("Applying %s failed, file %s already exists" % (self.resource, path))
    
    _ensure_metadata(path, self.resource.owner, self.resource.group,
                        mode=self.resource.mode, cd_access=self.resource.cd_access)
Пример #5
0
  def get_content(self):
    # absolute path
    if self.name.startswith(os.path.sep):
      path = self.name
    # relative path
    else:
      basedir = self.env.config.basedir
      path = os.path.join(basedir, "files", self.name)
      
    if not sudo.path_isfile(path) and not sudo.path_lexists(path):
      raise Fail("{0} Source file {1} is not found".format(repr(self), path))

    return self.read_file(path)
Пример #6
0
 def action_delete(self):
     path = self.resource.path
     if sudo.path_lexists(path):
         Logger.info("Deleting %s" % self.resource)
         sudo.unlink(path)
Пример #7
0
 def action_delete(self):
   path = self.resource.path
   if sudo.path_lexists(path):
     Logger.info("Deleting %s" % self.resource)
     sudo.unlink(path)