def clean(self, *args, **kwargs): super(CodeRepository, self).clean(*args, **kwargs) if not os.path.isdir(self.location): raise ValidationError('Location is not a valid directory') #svn=0 git=1 bzr=2 hg=3 if self.repository_type == 0: try: import pysvn except ImportError: ValidationError('You must install pysvn to use svn repos') elif self.repository_type == 1: try: from dulwich.repo import Repo, NotGitRepository except ImportError: ValidationError('You must install dulwich to use git repos') try: Repo(self.location) except NotGitRepository: raise ValidationError('Location is not a valid git repository') elif self.repository_type == 2: try: from bzrlib import branch, diff, errors except ImportError: raise ValidationError( 'You must install bzrlib to use bazaar repos') try: branch.Branch.open(self.location.rstrip(os.path.sep)) except errors.NotBranchError: raise ValidationError( 'Location is not a valid bazaar repository') elif self.repository_type == 3: try: from mercurial import ui from mercurial.localrepo import localrepository as hg_repo from mercurial.error import RepoError except ImportError: ValidationError('You must install mercurial to use hg repos') try: hg_repo(ui.ui(), path=self.location) except RepoError: raise ValidationError( 'Location is not a valid mercurial repository')
def __init__(self, path, **kwargs): """ path is the filesystem path where the repo exists, **kwargs are anything extra fnor accessing the repo """ self.repo = hg_repo(ui.ui(), path=path) self.path = path self.extra = kwargs
def clean(self,*args, **kwargs): super(CodeRepository, self).clean(*args, **kwargs) if not os.path.isdir(self.location): raise ValidationError('Location is not a valid directory') #svn=0 git=1 bzr=2 hg=3 if self.repository_type == 0: try: import pysvn except ImportError: ValidationError('You must install pysvn to use svn repos') elif self.repository_type == 1: try: from dulwich.repo import Repo,NotGitRepository except ImportError: ValidationError('You must install dulwich to use git repos') try: Repo(self.location) except NotGitRepository: raise ValidationError('Location is not a valid git repository') elif self.repository_type == 2: try: from bzrlib import branch, diff, errors except ImportError: raise ValidationError('You must install bzrlib to use bazaar repos') try: branch.Branch.open(self.location.rstrip(os.path.sep)) except errors.NotBranchError: raise ValidationError('Location is not a valid bazaar repository') elif self.repository_type == 3: try: from mercurial import ui from mercurial.localrepo import localrepository as hg_repo from mercurial.error import RepoError except ImportError: ValidationError('You must install mercurial to use hg repos') try: hg_repo(ui.ui(),path=self.location) except RepoError: raise ValidationError('Location is not a valid mercurial repository')
def init_new(path): hg_repo(ui.ui(), path=path, create=True) return Repository(path)