def setGitRepositoryTree(self, databaseSession, repositoryUrl, sourceGitRepositoryTree): from gitrepositorytree import GitRepositoryTree destinationGitRepositoryTree = self.gitRepositoryTree if destinationGitRepositoryTree is None: destinationGitRepositoryTree = GitRepositoryTree() destinationGitRepositoryTree.copy(sourceGitRepositoryTree) destinationGitRepositoryTree.setRepositoryUrl(databaseSession, repositoryUrl) self.setType(databaseSession, "git") if self.gitRepositoryTree is None: self.gitRepositoryTree = destinationGitRepositoryTree databaseSession.add(self.gitRepositoryTree)
def validateFormFieldsDictionary(cls, dictionary): from svnrepositorytree import SvnRepositoryTree from gitrepositorytree import GitRepositoryTree type = dictionary.get("type", "") if type == "none": return True, None elif type == "svn": return SvnRepositoryTree.validateFormFieldsDictionary(dictionary) elif type == "git": return GitRepositoryTree.validateFormFieldsDictionary(dictionary) elif type == "raw": return RawDirectoryTree.validateFormFieldsDictionary(dictionary) else: return False, { "field": "type", "message": "You must provide a valid directory tree type." }
def fromFormFieldsDictionary(self, databaseSession, dictionary): from svnrepositorytree import SvnRepositoryTree from gitrepositorytree import GitRepositoryTree if dictionary["type"] == "none": self.setNone(databaseSession) elif dictionary["type"] == "svn": repositoryUrl = dictionary["url"] svnRepositoryTree = SvnRepositoryTree() svnRepositoryTree.fromFormFieldsDictionary(databaseSession, dictionary) self.setSvnRepositoryTree(databaseSession, repositoryUrl, svnRepositoryTree) elif dictionary["type"] == "git": repositoryUrl = dictionary["url"] gitRepositoryTree = GitRepositoryTree() gitRepositoryTree.fromFormFieldsDictionary(databaseSession, dictionary) self.setGitRepositoryTree(databaseSession, repositoryUrl, gitRepositoryTree) elif dictionary["type"] == "raw": raise NotImplementedError() else: raise ValueError() return self