# -*- coding: utf-8 -*-""" vcs.backends ~~~~~~~~~~~~ Main package for scm backends :created_on: Apr 8, 2010 :copyright: (c) 2010-2011 by Marcin Kuzminski, Lukasz Balcerzak."""importosfrompprintimportpformatfromrhodecode.lib.vcs.confimportsettingsfromrhodecode.lib.vcs.exceptionsimportVCSErrorfromrhodecode.lib.vcs.utils.helpersimportget_scmfromrhodecode.lib.vcs.utils.pathsimportabspathfromrhodecode.lib.vcs.utils.importsimportimport_classdefget_repo(path=None,alias=None,create=False):""" Returns ``Repository`` object of type linked with given ``alias`` at the specified ``path``. If ``alias`` is not given it will try to guess it using get_scm method """ifcreate:ifnot(pathoralias):raiseTypeError("If create is specified, we need path and scm type")returnget_backend(alias)(path,create=True)ifpathisNone:path=abspath(os.path.curdir)try:scm,path=get_scm(path,search_up=True)path=abspath(path)alias=scmexceptVCSError:raiseVCSError("No scm found at %s"%path)ifaliasisNone:alias=get_scm(path)[0]backend=get_backend(alias)repo=backend(path,create=create)returnrepodefget_backend(alias):""" Returns ``Repository`` class identified by the given alias or raises VCSError if alias is not recognized or backend class cannot be imported. """ifaliasnotinsettings.BACKENDS:raiseVCSError("Given alias '%s' is not recognized! Allowed aliases:\n""%s"%(alias,pformat(settings.BACKENDS.keys())))backend_path=settings.BACKENDS[alias]klass=import_class(backend_path)returnklassdefget_supported_backends():""" Returns list of aliases of supported backends. """returnsettings.BACKENDS.keys()