Exemplo n.º 1
0
    def __init__(self, projectroot, fscommands=None,
                 ropefolder='.ropeproject', **prefs):
        """A rope project

        :parameters:
            - `projectroot`: The address of the root folder of the project
            - `fscommands`: Implements the file system operations used
              by rope; have a look at `rope.base.fscommands`
            - `ropefolder`: The name of the folder in which rope stores
              project configurations and data.  Pass `None` for not using
              such a folder at all.
            - `prefs`: Specify project preferences.  These values
              overwrite config file preferences.

        """
        if projectroot != '/':
            projectroot = _realpath(projectroot).rstrip('/\\')
        self._address = projectroot
        self._ropefolder_name = ropefolder
        if not os.path.exists(self._address):
            os.mkdir(self._address)
        elif not os.path.isdir(self._address):
            raise exceptions.RopeError('Project root exists and'
                                       ' is not a directory')
        if fscommands is None:
            fscommands = rope.base.fscommands.create_fscommands(self._address)
        super(Project, self).__init__(fscommands)
        self.ignored = _ResourceMatcher()
        self.file_list = _FileListCacher(self)
        self.prefs.add_callback('ignored_resources', self.ignored.set_patterns)
        if ropefolder is not None:
            self.prefs['ignored_resources'] = [ropefolder]
        self._init_prefs(prefs)
Exemplo n.º 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)