def checkout( self, url, local_directory, revision ): self.resetClient() if self.isWorkingCopy( local_directory ): userErrorExit("Unable to checkout '%s', given target directory '%s' is an existing working copy."\ %(url, local_directory)) if not self.isRepoURL(url): userErrorExit("Invalid SVN repository: '%s'"%(url)) rev = self.prepareRevision(revision) if not os.path.isdir(local_directory): userErrorExit("Checkout destination '%s' is not a directory"%(local_directory)) try: #pysvn checkout seems to have a problem when spaces are not escaped but also when other characters are escaped url = urllib.quote(url, safe=',~=!@#$%^&*()+|}{:?><;[]\\/') self.client.checkout(url=url, path=local_directory, recurse=True, revision=rev) except pysvn.ClientError, e: for message, code in e.args[1]: if code in [ERR_HOST_UNRESOLVED,]: errorMessage("Unable to resolve host '%s'. Proceeding.. "%(url)) else: userErrorExit("Unknown failure when checking out '%s'\nPYSVN Exception:\n%s (%d)"%(url, message, code))
def getRevisionFromWorkingCopy(self, repo_path): path = os.path.abspath('') if not os.path.isdir(repo_path): errorMessage("no such git repo: %s"%(repo_path)) exit(42) os.chdir( repo_path ) import subprocess args = [self.git, '--no-pager', 'log', '--pretty=oneline', '--no-color'] p = subprocess.Popen(args, bufsize=8192, stdin=None, stdout=subprocess.PIPE, stderr=None) stdout = p.stdout.read() retcode = p.wait() if stdout.split() != []: rev = stdout.split()[0] if retcode != 0: print stderr errorMessage("could not run git log, git log failed with return code %d"%(retcode)) exit(retcode) os.chdir(path) return rev
def updateWorkingCopy( self, lc_path, rev ): self.resetClient() if not self.isWorkingCopy( lc_path ): userErrorExit("Unable to update '%s'. Not a valid working copy."\ %(lc_path)) if rev.upper() == 'HEAD': rev = pysvn.Revision(pysvn.opt_revision_kind.head ) else: rev = pysvn.Revision(pysvn.opt_revision_kind.number, rev ) try: self.client.update( path=lc_path, recurse=True, revision=rev ) except pysvn.ClientError, e: for message, code in e.args[1]: if code in [ERR_HOST_UNRESOLVED,]: errorMessage("Unable to resolve host '%s'. Proceeding.. "\ %(self.getURLFromWorkingCopy(lc_path))) else: userErrorExit("Unknown failure when updating '%s'\nPYSVN Exception:\n%s (%d)"%(lc_path, message, code))