# Path: yoda/adapter/bzr.py
# class Bzr(Abstract):
#     """Bzr Adapter."""
#     executable = "bzr"
# 
#     def status(self):
#         """Show bzr status."""
#         return self.exec_on_path("%s status" % self.executable)
# 
#     def update(self):
#         """Update repository."""
#         return self.exec_on_path("%s pull" % self.executable)
# 
#     def clone(self, url):
#         """Clone repository from url."""
#         return self.execute("%s branch %s %s" % (self.executable,
#                                                  url, self.path))
# 
#     def show(self):
#         """Show repository details."""
#         raise NotImplemented("TODO: Not implemented")
# 
# Path: yoda/adapter/git.py
# class Git(Abstract):
#     """Git Adapter."""
# 
#     executable = "git"
# 
#     def status(self):
#         """Show git status."""
#         return self.exec_on_path("git status")
# 
#     def clone(self, url):
#         """Clone repository from url."""
#         return self.execute("git clone %s %s" % (url, self.path))
# 
#     def update(self):
#         """Update repository."""
#         return self.exec_on_path("git pull --rebase")
# 
#     def show(self):
#         """Show repository details."""
#         raise NotImplemented("TODO: Not implemented")
# 
# Path: yoda/adapter/hg.py
# class Hg(Abstract):
#     """Mercurial Adapter."""
#     executable = "hg"
# 
#     def status(self):
#         """Show hg status."""
#         return self.exec_on_path("%s status" % self.executable)
# 
#     def update(self):
#         """Update repository."""
#         return self.exec_on_path("%s pull -u" % self.executable)
# 
#     def clone(self, url):
#         """Clone repository from url."""
#         return self.execute("%s clone %s %s" % (self.executable,
#                                                 url, self.path))
# 
#     def show(self):
#         """Show repository details."""
#         raise NotImplemented("TODO: Not implemented")
# 
# Path: yoda/adapter/svn.py
# class Svn(Abstract):
#     """Svn Adapter."""
# 
#     executable = "svn"
# 
#     def status(self):
#         """Show git status."""
#         return self.exec_on_path("svn status")
# 
#     def clone(self, url):
#         """Checkout repository from url."""
#         return self.execute("svn checkout %s %s" % (url, self.path))
# 
#     def update(self):
#         """Update repository."""
#         return self.exec_on_path("svn update")
# 
#     def show(self):
#         """Show repository details."""
#         raise NotImplemented("TODO: Not implemented")


import os
from yoda.adapter import Bzr
from yoda.adapter import Git
from yoda.adapter import Hg
from yoda.adapter import Svn


class RepositoryPathInvalid(RepositoryError):
    """Repository path is invalid, doesn't exists or is not a directory."""
    pass


class RepositoryAdapterNotFound(RepositoryError):
    """Repository invalid because adapter not found."""
    pass


class Repository:
    path = None
    adapter = None

    scm_dirs = [".git", ".svn", ".bzr", ".hg"]

    def __init__(self, path):
        if not os.path.exists(path) or not os.path.isdir(path):
            raise RepositoryPathInvalid(
                "Path doesn't exists or isn't a directory (%s)\n" % path)

        try:
            scm = (set(self.scm_dirs) & set(os.listdir(path))).pop()
        except KeyError:
            raise RepositoryAdapterNotFound("Can't define repository type")
        else:
            self.path = path
            if scm == ".git":

# Path: yoda/adapter/bzr.py
# class Bzr(Abstract):
#     """Bzr Adapter."""
#     executable = "bzr"
# 
#     def status(self):
#         """Show bzr status."""
#         return self.exec_on_path("%s status" % self.executable)
# 
#     def update(self):
#         """Update repository."""
#         return self.exec_on_path("%s pull" % self.executable)
# 
#     def clone(self, url):
#         """Clone repository from url."""
#         return self.execute("%s branch %s %s" % (self.executable,
#                                                  url, self.path))
# 
#     def show(self):
#         """Show repository details."""
#         raise NotImplemented("TODO: Not implemented")
# 
# Path: yoda/adapter/git.py
# class Git(Abstract):
#     """Git Adapter."""
# 
#     executable = "git"
# 
#     def status(self):
#         """Show git status."""
#         return self.exec_on_path("git status")
# 
#     def clone(self, url):
#         """Clone repository from url."""
#         return self.execute("git clone %s %s" % (url, self.path))
# 
#     def update(self):
#         """Update repository."""
#         return self.exec_on_path("git pull --rebase")
# 
#     def show(self):
#         """Show repository details."""
#         raise NotImplemented("TODO: Not implemented")
# 
# Path: yoda/adapter/hg.py
# class Hg(Abstract):
#     """Mercurial Adapter."""
#     executable = "hg"
# 
#     def status(self):
#         """Show hg status."""
#         return self.exec_on_path("%s status" % self.executable)
# 
#     def update(self):
#         """Update repository."""
#         return self.exec_on_path("%s pull -u" % self.executable)
# 
#     def clone(self, url):
#         """Clone repository from url."""
#         return self.execute("%s clone %s %s" % (self.executable,
#                                                 url, self.path))
# 
#     def show(self):
#         """Show repository details."""
#         raise NotImplemented("TODO: Not implemented")
# 
# Path: yoda/adapter/svn.py
# class Svn(Abstract):
#     """Svn Adapter."""
# 
#     executable = "svn"
# 
#     def status(self):
#         """Show git status."""
#         return self.exec_on_path("svn status")
# 
#     def clone(self, url):
#         """Checkout repository from url."""
#         return self.execute("svn checkout %s %s" % (url, self.path))
# 
#     def update(self):
#         """Update repository."""
#         return self.exec_on_path("svn update")
# 
#     def show(self):
#         """Show repository details."""
#         raise NotImplemented("TODO: Not implemented")


# Path: yoda/repository.py
import os
from yoda.adapter import Bzr
from yoda.adapter import Git
from yoda.adapter import Hg
from yoda.adapter import Svn



class RepositoryPathInvalid(RepositoryError):
    """Repository path is invalid, doesn't exists or is not a directory."""
    pass


class RepositoryAdapterNotFound(RepositoryError):
    """Repository invalid because adapter not found."""
    pass


class Repository:
    path = None
    adapter = None

    scm_dirs = [".git", ".svn", ".bzr", ".hg"]

    def __init__(self, path):
        if not os.path.exists(path) or not os.path.isdir(path):
            raise RepositoryPathInvalid(
                "Path doesn't exists or isn't a directory (%s)\n" % path)

        try:
            scm = (set(self.scm_dirs) & set(os.listdir(path))).pop()
        except KeyError:
            raise RepositoryAdapterNotFound("Can't define repository type")
        else:
            self.path = path
            if scm == ".git":

                self.adapter = Git(path)