Commits

Ali Gholami Rudi  committed bcc2299

Better symlink handling

  • Participants
  • Parent commits a176b0d

Comments (0)

Files changed (6)

File rope/base/change.py

 
     @_handle_job_set
     def do(self):
-        self.operations.move(self.old_resource, self.new_resource.path)
+        self.operations.move(self.old_resource, self.new_resource)
 
     @_handle_job_set
     def undo(self):
-        self.operations.move(self.new_resource, self.old_resource.path)
+        self.operations.move(self.new_resource, self.old_resource)
 
     def __str__(self):
         return 'Move <%s>' % self.old_resource.path
         for observer in list(self.project.observers):
             observer.resource_changed(resource)
 
-    def move(self, resource, new_location):
-        destination = _get_destination_for_move(resource, new_location)
+    def move(self, resource, new_resource):
         fscommands = self._get_fscommands(resource)
-        fscommands.move(resource.real_path,
-                        self.project._get_resource_path(destination))
-        new_resource = self.project.get_resource(destination)
+        fscommands.move(resource.real_path, new_resource.real_path)
         for observer in list(self.project.observers):
             observer.resource_moved(resource, new_resource)
 

File rope/base/libutils.py

     `Project.get_file()`, and `Project.get_folder()` methods.
 
     """
-    path = os.path.abspath(path)
+    path = rope.base.project._realpath(path)
     project_path = path
     if path.startswith(project.address):
         project_path = path[len(project.address):].lstrip('/' + os.sep)

File rope/base/oi/dynamicoi.py

         source_folders = []
         file_path = self.file.real_path
         for folder in self.pycore.get_source_folders():
-            source_folders.append(os.path.abspath(folder.real_path))
+            source_folders.append(folder.real_path)
         env['PYTHONPATH'] = env.get('PYTHONPATH', '') + os.pathsep + \
                             os.pathsep.join(source_folders)
         runmod_path = self.pycore.find_module('rope.base.oi.runmod').real_path
         if self.receiver:
             send_info = self.receiver.get_send_info()
         args = [sys.executable, runmod_path, send_info,
-                os.path.abspath(self.pycore.project.address),
-                os.path.abspath(self.file.real_path)]
+                self.pycore.project.address, self.file.real_path]
         if self.analyze_data is None:
             del args[1:4]
         if self.args is not None:

File rope/base/oi/runmod.py

         def _is_code_inside_project(self, code):
             source = code.co_filename
             return source and source.endswith('.py') and os.path.exists(source) and \
-                   os.path.abspath(source).startswith(self.project_root)
+                   _realpath(source).startswith(self.project_root)
 
         def _get_persisted_code(self, object_):
             source = object_.co_filename
             if not os.path.exists(source):
                 raise TypeError('no source')
-            return ('defined', os.path.abspath(source),
-                    str(object_.co_firstlineno))
+            return ('defined', _realpath(source), str(object_.co_firstlineno))
 
         def _get_persisted_class(self, object_):
             try:
-                return ('defined', os.path.abspath(inspect.getsourcefile(object_)),
+                return ('defined', _realpath(inspect.getsourcefile(object_)),
                         object_.__name__)
             except (TypeError, AttributeError):
                 return ('unknown',)
             if isinstance(object_, types.MethodType):
                 return self._get_persisted_code(object_.im_func.func_code)
             if isinstance(object_, types.ModuleType):
-                return ('defined', os.path.abspath(object_.__file__))
+                return ('defined', _realpath(object_.__file__))
             if isinstance(object_, (str, unicode, list, dict, tuple, set)):
                 return self._get_persisted_builtin(object_)
             if isinstance(object_, (types.TypeType, types.ClassType)):
                 return self._get_persisted_class(object_)
             return ('instance', self._get_persisted_class(type(object_)))
 
+    def _realpath(path):
+        return os.path.realpath(os.path.abspath(os.path.expanduser(path)))
 
     send_info = sys.argv[1]
     project_root = sys.argv[2]

File rope/base/project.py

               overwrite config file preferences.
 
         """
-        self._address = os.path.abspath(
-            os.path.expanduser(projectroot)).rstrip('/\\')
+        self._address = _realpath(projectroot).rstrip('/\\')
         if not os.path.exists(self._address):
             os.mkdir(self._address)
         elif not os.path.isdir(self._address):
         super(NoProject, self).__init__(fscommands)
 
     def _get_resource_path(self, name):
-        real_name = os.path.abspath(name).replace('/', os.path.sep)
-        return os.path.abspath(real_name)
+        real_name = name.replace('/', os.path.sep)
+        return _realpath(real_name)
 
     def get_resource(self, name):
-        universal_name = os.path.abspath(name).replace(os.path.sep, '/')
+        universal_name = _realpath(name).replace(os.path.sep, '/')
         return super(NoProject, self).get_resource(universal_name)
 
     def get_files(self):
 
     def _validate(self, resource):
         self._list = None
+
+
+def _realpath(path):
+    """Return the real path of `path`
+
+    Is equivalent to ``realpath(abspath(expanduser(path)))``.
+
+    """
+    return os.path.realpath(os.path.abspath(os.path.expanduser(path)))

File ropetest/projecttest.py

 from rope.base.exceptions import RopeError, ResourceNotFoundError
 from rope.base.fscommands import FileSystemCommands
 from rope.base.libutils import path_to_resource
-from rope.base.project import Project, NoProject, FilteredResourceObserver
+from rope.base.project import (Project, NoProject,
+                               FilteredResourceObserver, _realpath)
 from ropetest import testutils
 
 
         unittest.TestCase.tearDown(self)
 
     def test_project_creation(self):
-        self.assertEquals(os.path.abspath(self.project_root),
-                          os.path.abspath(self.project.address))
+        self.assertEquals(_realpath(self.project_root),
+                          self.project.address)
 
     def test_getting_project_file(self):
         project_file = self.project.get_resource(self.sample_file)