Beispiel #1
0
    def get_resource(self, resource_name):
        """Get a resource in a project.

        `resource_name` is the path of a resource in a project.  It is
        the path of a resource relative to project root.  Project root
        folder address is an empty string.  If the resource does not
        exist a `exceptions.ResourceNotFound` exception would be
        raised.  Use `get_file()` and `get_folder()` when you need to
        get nonexistent `Resource`\s.

        """
        path = self._get_resource_path(resource_name)
        if not os.path.exists(path):
            raise exceptions.ResourceNotFoundError(
                'Resource <%s> does not exist' % resource_name)
        elif os.path.isfile(path):
            return File(self, resource_name)
        elif os.path.isdir(path):
            return Folder(self, resource_name)
        else:
            raise exceptions.ResourceNotFoundError('Unknown resource ' +
                                                   resource_name)
Beispiel #2
0
 def _create_resource(self, file_name, kind='file'):
     resource_path = self.project._get_resource_path(file_name)
     if os.path.exists(resource_path):
         raise exceptions.RopeError('Resource <%s> already exists'
                                    % resource_path)
     resource = self.project.get_file(file_name)
     if not resource.parent.exists():
         raise exceptions.ResourceNotFoundError(
             'Parent folder of <%s> does not exist' % resource.path)
     fscommands = self._get_fscommands(resource)
     try:
         if kind == 'file':
             fscommands.create_file(resource_path)
         else:
             fscommands.create_folder(resource_path)
     except IOError as e:
         raise exceptions.RopeError(e)