Commits

Ronny Pfannschmidt committed 67ffe80

introduce the anyvc.workdir.open api

  • Participants
  • Parent commits 3208f18
  • Tags 0.3

Comments (0)

Files changed (7)

File anyvc/__init__.py

     'workdir':{
         'all_known':'anyvc._workdir:all_known',
         'get_workdir_manager_for_path':'anyvc._workdir:get_workdir_manager_for_path',
+        'open':'anyvc._workdir:open',
         },
     })

File anyvc/_workdir.py

 
 
 from .metadata import backends, get_backend
+import os
+
+from .common.workdir import find_basepath
 
 def fill(listing):
     for backend in backends:
 all_known = LazyAllKnown()
 
 def get_workdir_manager_for_path(path):
-    #XXX: this has to die
+    """
+    deprecate
+    """
+    import warnings
+    warnings.warn(
+            'get_workdir_manager_for_path is outdated,'
+            'please use anyvc.workdir.open',
+            DeprecationWarning,
+            stacklevel=2)
     found_vcm = None
     for vcm in all_known:
         try:
         except ValueError:
             pass
     return found_vcm
+
+
+def open(path):
+    """
+    open a workdir manager for the scm that controlls the given path
+    this might be a super
+    """
+    path = str(path) # so we can use py.path instances
+    path = os.path.normpath(path)
+    known_backends = [get_backend(bn) for bn in backends]
+
+    res = {}
+    for backend in known_backends:
+        #XXX: walkdown sould be iterate on same level instead
+        #     of walk all per backend
+        try:
+            base = find_basepath(path, backend.workdir_control)
+            if base:
+                res[base] = backend
+        except AttributeError:
+            pass # backend is missing workdir_control
+    if res:
+        found_backend = res[max(res)] #max gives us the longest path
+        return found_backend.Workdir(path)

File anyvc/backend.py

         except (ImportError, AttributeError):
             raise ImportError(name)
 
+    @property
+    def workdir_control(self):
+        print self.module
+        print dir(self.module)
+        return self.module.workdir_control
+
     @cachedproperty
     def Repository(self):
         return self._import(self.module.repo_class)

File anyvc/git/__init__.py

 repo_class = 'anyvc.git.repo:GitRepository'
 workdir_class = 'anyvc.git.workdir:Git'
+workdir_control = '.git'

File anyvc/mercurial/__init__.py

 repo_class = 'anyvc.mercurial.repo:MercurialRepository'
 workdir_class = 'anyvc.mercurial.workdir:Mercurial'
+workdir_control = '.hg'
 

File anyvc/subversion/__init__.py

 workdir_class = 'anyvc.subversion.workdir:SubVersion'
 repo_class = 'anyvc.subversion.repo:SubversionRepository'
+workdir_control = '.svn'

File tests/workdir/test_common.py

     WD = get_wd_impl(mgr.vc)
     test = WD(str(wd.bpath('wd/test.py')))
 
-@py.test.mark.xfail
 @has_files
 @commited
 def test_workdir_open(wd):
     import anyvc
-    anyvc.workdir.open(wd.bpath())
+    anyvc.workdir.open(wd.bpath(''))