def update(self, revision=None, needs_revert=True): """Does a clean update of the given path :param revision: ignored for hg """ output_revert = "" if needs_revert: # revert local changes (avoids conflicts) command = ["hg", "-R", self.root_dir, "revert", "--all", self.location_abs] exitcode, output_revert, error = run_command(command) if exitcode != 0: raise IOError("[Mercurial] error running '%s': %s" % (command, error)) # pull new patches command = ["hg", "-R", self.root_dir, "pull"] exitcode, output_pull, error = run_command(command) if exitcode != 0: raise IOError("[Mercurial] error running '%s': %s" % (command, error)) # update working directory command = ["hg", "-R", self.root_dir, "update"] exitcode, output_update, error = run_command(command) if exitcode != 0: raise IOError("[Mercurial] error running '%s': %s" % (command, error)) return output_revert + output_pull + output_update
def commit(self, message=None, author=None, add=True): """Commits the file and supplies the given commit message if present""" # add the file output_add = "" if add: command = self._get_git_command(["add", self.location_rel]) exitcode, output_add, error = run_command(command, self.root_dir) if exitcode != 0: raise IOError("[GIT] add of ('%s', '%s') failed: %s" \ % (self.root_dir, self.location_rel, error)) # commit file command = self._get_git_command(["commit"]) if message: command.extend(["-m", message]) if author: command.extend(["--author", author]) exitcode, output_commit, error = run_command(command, self.root_dir) if exitcode != 0: if len(error): msg = error else: msg = output_commit raise IOError("[GIT] commit of ('%s', '%s') failed: %s" \ % (self.root_dir, self.location_rel, msg)) # push changes command = self._get_git_command(["push"]) exitcode, output_push, error = run_command(command, self.root_dir) if exitcode != 0: raise IOError("[GIT] push of ('%s', '%s') failed: %s" \ % (self.root_dir, self.location_rel, error)) return output_add + output_commit + output_push
def update(self, revision=None): """Does a clean update of the given path""" # git checkout command = self._get_git_command(["checkout", self.location_rel]) exitcode, output_checkout, error = run_command(command, self.root_dir) if exitcode != 0: raise IOError("[GIT] checkout failed (%s): %s" % (command, error)) # pull changes command = self._get_git_command(["pull"]) exitcode, output_pull, error = run_command(command, self.root_dir) if exitcode != 0: raise IOError("[GIT] pull failed (%s): %s" % (command, error)) return output_checkout + output_pull
def update(self, revision=None): """Does a clean update of the given path""" # bzr revert command = ["bzr", "revert", self.location_abs] exitcode, output_revert, error = run_command(command) if exitcode != 0: raise IOError("[BZR] revert of '%s' failed: %s" \ % (self.location_abs, error)) # bzr pull command = ["bzr", "pull"] exitcode, output_pull, error = run_command(command) if exitcode != 0: raise IOError("[BZR] pull of '%s' failed: %s" \ % (self.location_abs, error)) return output_revert + output_pull
def update(self, revision=None, needs_revert=True): """Does a clean update of the given path""" #TODO: take needs_revert parameter into account working_dir = os.path.dirname(self.location_abs) filename = self.location_abs filename_backup = filename + os.path.extsep + "bak" # rename the file to be updated try: os.rename(filename, filename_backup) except OSError as error: raise IOError("[CVS] could not move the file '%s' to '%s': %s" % ( filename, filename_backup, error)) command = ["cvs", "-Q", "update", "-C"] if revision: command.extend(["-r", revision]) # the filename is the last argument command.append(os.path.basename(filename)) # run the command within the given working_dir exitcode, output, error = run_command(command, working_dir) # restore backup in case of an error - remove backup for success try: if exitcode != 0: os.rename(filename_backup, filename) else: os.remove(filename_backup) except OSError: pass # raise an error or return successfully - depending on the CVS command if exitcode != 0: raise IOError("[CVS] Error running CVS command '%s': %s" % (command, error)) else: return output
def update(self, revision=None): """Does a clean update of the given path :param revision: ignored for darcs """ # revert local changes (avoids conflicts) command = ["darcs", "revert", "--repodir", self.root_dir, "-a", self.location_rel] exitcode, output_revert, error = run_command(command) if exitcode != 0: raise IOError("[Darcs] error running '%s': %s" % (command, error)) # pull new patches command = ["darcs", "pull", "--repodir", self.root_dir, "-a"] exitcode, output_pull, error = run_command(command) if exitcode != 0: raise IOError("[Darcs] error running '%s': %s" % (command, error)) return output_revert + output_pull
def getcleanfile(self, revision=None): """Get a clean version of a file from the git repository""" # run git-show command = self._get_git_command(["show", "HEAD:%s" % self.location_rel]) exitcode, output, error = run_command(command, self.root_dir) if exitcode != 0: raise IOError("[GIT] 'show' failed for ('%s', %s): %s" \ % (self.root_dir, self.location_rel, error)) return output
def getcleanfile(self, revision=None): """Get a clean version of a file from the bzr repository""" # bzr cat command = ["bzr", "cat", self.location_abs] exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[BZR] cat failed for '%s': %s" % ( self.location_abs, error)) return output
def get_version(): """return a tuple of (major, minor) for the installed subversion client""" exitcode, output, error = run_command(["p4", "-V"]) if exitcode == 0: major, minor = output.strip().split("/")[2].split(".")[:2] if (major.isdigit() and minor.isdigit()): return (int(major), int(minor)) # something went wrong above return (0, 0)
def get_version(): """return a tuple of (major, minor) for the installed subversion client""" command = ["svn", "--version", "--quiet"] exitcode, output, error = run_command(command) if exitcode == 0: major, minor = output.strip().split(".")[0:2] if (major.isdigit() and minor.isdigit()): return (int(major), int(minor)) # something went wrong above return (0, 0)
def add(self, files, message=None, author=None): """Add and commit the new files.""" args = ["add"] + prepare_filelist(files) command = self._get_git_command(args) exitcode, output, error = run_command(command, self.root_dir) if exitcode != 0: raise IOError("[GIT] add of files in '%s') failed: %s" \ % (self.root_dir, error)) return output + self.commit(message, author, add=False)
def getcleanfile(self, revision=None): """Get a clean version of a file from the hg repository""" # run hg cat command = ["hg", "-R", self.root_dir, "cat", self.location_abs] exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[Mercurial] Error running '%s': %s" \ % (command, error)) return output
def update(self, revision=None): """update the working copy - remove local modifications if necessary""" # revert the local copy (remove local changes) command = ["svn", "revert", self.location_abs] exitcode, output_revert, error = run_command(command) # any errors? if exitcode != 0: raise IOError("[SVN] Subversion error running '%s': %s" \ % (command, error)) # update the working copy to the given revision command = ["svn", "update"] if not revision is None: command.extend(["-r", revision]) # the filename is the last argument command.append(self.location_abs) exitcode, output_update, error = run_command(command) if exitcode != 0: raise IOError("[SVN] Subversion error running '%s': %s" \ % (command, error)) return output_revert + output_update
def getcleanfile(self, revision=None): """return the content of the 'head' revision of the file""" command = ["svn", "cat"] if not revision is None: command.extend(["-r", revision]) # the filename is the last argument command.append(self.location_abs) exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[SVN] Subversion error running '%s': %s" % (command, error)) return output
def add(self, files, message=None, author=None): """Add and commit the new files.""" command = ["hg", "add", "-q", "--parents"] + prepare_filelist(files) exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[Mercurial] Error running '%s': %s" % (command, error)) # go down as deep as possible in the tree to avoid accidental commits # TODO: explicitly commit files by name youngest_ancestor = os.path.commonprefix(files) return output + type(self)(youngest_ancestor).commit(message, author)
def update(self, revision=None): """update the working copy - remove local modifications if necessary""" # revert the local copy (remove local changes) command = ["p4", "revert", self.location_abs] exitcode, output_revert, error = run_command(command) # any errors? if exitcode != 0: raise IOError("[P4] Perforce error running '%s': %s" \ % (command, error)) # update the working copy to the given revision command = ["p4", "sync"] if not revision is None: command.append(self.location_abs + "@" + revision) if not revision is None: command.append(self.location_abs) exitcode, output_update, error = run_command(command) if exitcode != 0: raise IOError("[P4] Perforce error running '%s': %s" \ % (command, error)) return output_revert + output_update
def add(self, files, message=None, author=None): """Add and commit files.""" command = ["bzr", "add"] + prepare_filelist(files) exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[BZR] add in '%s' failed: %s" \ % (self.location_abs, error)) # go down as deep as possible in the tree to avoid accidental commits # TODO: explicitly commit files by name youngest_ancestor = os.path.commonprefix(files) return output + type(self)(youngest_ancestor).commit(message, author)
def add(self, files, message=None, author=None): """Add and commit files.""" command = ["darcs", "add", "--repodir", self.root_dir] + prepare_filelist(files) exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[Darcs] Error running darcs command '%s': %s" \ % (command, error)) # go down as deep as possible in the tree to avoid accidental commits # TODO: explicitly commit files by name youngest_ancestor = os.path.commonprefix(files) return output + type(self)(youngest_ancestor).commit(message, author)
def commit(self, message=None, author=None): """Commits the file and supplies the given commit message if present""" if message is None: message = "" # commit changes command = ["hg", "-R", self.root_dir, "commit", "-m", message] # add the 'author' argument, if it was given (only supported since v1.0) if author and (get_version() >= (1, 0)): command.extend(["--user", author]) # the location is the last argument command.append(self.location_abs) exitcode, output_commit, error = run_command(command) if exitcode != 0: raise IOError("[Mercurial] Error running '%s': %s" \ % (command, error)) # push changes command = ["hg", "-R", self.root_dir, "push"] exitcode, output_push, error = run_command(command) if exitcode != 0: raise IOError("[Mercurial] Error running '%s': %s" \ % (command, error)) return output_commit + output_push
def add(self, files, message=None, author=None): """Add and commit the new files.""" files = prepare_filelist(files) command = ["svn", "add", "-q", "--non-interactive", "--parents"] + files exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[SVN] Error running SVN command '%s': %s" % (command, error)) # go down as deep as possible in the tree to avoid accidental commits # TODO: explicitly commit files by name ancestor = youngest_ancestor(files) return output + type(self)(ancestor).commit(message, author)
def commit(self, message=None, author=None): """Commits the file and supplies the given commit message if present""" # bzr commit command = ["bzr", "commit"] if message: command.extend(["-m", message]) # the "--author" argument is supported since bzr v0.91rc1 if author and (get_version() >= (0, 91)): command.extend(["--author", author]) # the filename is the last argument command.append(self.location_abs) exitcode, output_commit, error = run_command(command) if exitcode != 0: raise IOError("[BZR] commit of '%s' failed: %s" % ( self.location_abs, error)) # bzr push command = ["bzr", "push"] exitcode, output_push, error = run_command(command) if exitcode != 0: raise IOError("[BZR] push of '%s' failed: %s" % ( self.location_abs, error)) return output_commit + output_push
def commit(self, message=None, author=None): """Commits the file and supplies the given commit message if present""" if message is None: message = "" # set change message command = ["darcs", "record", "-a", "--repodir", self.root_dir, "--skip-long-comment", "-m", message] # add the 'author' to the list of arguments if it was given if author: command.extend(["--author", author]) # the location of the file is the last argument command.append(self.location_rel) exitcode, output_record, error = run_command(command) if exitcode != 0: raise IOError("[Darcs] Error running darcs command '%s': %s" \ % (command, error)) # push changes command = ["darcs", "push", "-a", "--repodir", self.root_dir] exitcode, output_push, error = run_command(command) if exitcode != 0: raise IOError("[Darcs] Error running darcs command '%s': %s" \ % (command, error)) return output_record + output_push
def get_version(): """return a tuple of (major, minor) for the installed bazaar client""" import re command = ["hg", "--version"] exitcode, output, error = run_command(command) if exitcode == 0: version_line = output.splitlines()[0] version_match = re.search(r"\d+\.\d+", version_line) if version_match: major, minor = version_match.group().split(".") if (major.isdigit() and minor.isdigit()): return (int(major), int(minor)) # if anything broke before, then we return the invalid version number return (0, 0)
def commit(self, message=None, author=None): """commit the file and return the given message if present the 'author' parameter is used for revision property 'translate:author' """ command = ["svn", "-q", "--non-interactive", "commit", "-m", message or ""] # the "--with-revprop" argument is support since svn v1.5 if author and (get_version() >= (1, 5)): command.extend(["--with-revprop", "translate:author=%s" % author]) # the location is the last argument command.append(self.location_abs) exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[SVN] Error running SVN command '%s': %s" % (command, error)) return output
def add(self, files, message=None, author=None): """Add and commit the new files.""" working_dir = os.path.dirname(self.location_abs) command = ["cvs", "-Q", "add"] if message: command.extend(["-m", message]) command.extend(prepare_filelist(files)) exitcode, output, error = run_command(command, working_dir) # raise an error or return successfully - depending on the CVS command if exitcode != 0: raise IOError("[CVS] Error running CVS command '%s': %s" \ % (command, error)) # go down as deep as possible in the tree to avoid accidental commits # TODO: explicitly commit files by name youngest_ancestor = os.path.commonprefix(files) return output + type(self)(youngest_ancestor).commit(message, author)
def commit(self, message=None, author=None): """commit the file and return the given message if present the 'author' parameter is used for revision property 'translate:author' """ command = ["svn", "-q", "--non-interactive", "commit"] if message: command.extend(["-m", message]) # the "--with-revprop" argument is support since svn v1.5 if author and (get_version() >= (1, 5)): command.extend(["--with-revprop", "translate:author=%s" % author]) # the location is the last argument command.append(self.location_abs) exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[SVN] Error running SVN command '%s': %s" % (command, error)) return output
def add(self, files, message=None, author=None): """Add and commit the new files.""" working_dir = os.path.dirname(self.location_abs) command = ["cvs", "-Q", "add"] if message: command.extend(["-m", message]) files = prepare_filelist(files) command.extend(files) exitcode, output, error = run_command(command, working_dir) # raise an error or return successfully - depending on the CVS command if exitcode != 0: raise IOError("[CVS] Error running CVS command '%s': %s" % (command, error)) # go down as deep as possible in the tree to avoid accidental commits # TODO: explicitly commit files by name ancestor = youngest_ancestor(files) return output + type(self)(ancestor).commit(message, author)
def get_version(): """Return a tuple of (major, minor) for the installed mercurial client.""" global _version if _version: return _version import re command = ["hg", "--version"] exitcode, output, error = run_command(command) if exitcode == 0: version_line = output.splitlines()[0] version_match = re.search(r"\d+\.\d+", version_line) if version_match: major, minor = version_match.group().split(".") if (major.isdigit() and minor.isdigit()): _version = (int(major), int(minor)) return _version # if anything broke before, then we return the invalid version number return (0, 0)
def commit(self, message=None, author=None): """Commits the file and supplies the given commit message if present the 'author' parameter is not suitable for CVS, thus it is ignored """ working_dir = os.path.dirname(self.location_abs) filename = os.path.basename(self.location_abs) command = ["cvs", "-Q", "commit"] if message: command.extend(["-m", message]) # the filename is the last argument command.append(filename) exitcode, output, error = run_command(command, working_dir) # raise an error or return successfully - depending on the CVS command if exitcode != 0: raise IOError("[CVS] Error running CVS command '%s': %s" \ % (command, error)) else: return output
def _readfile(self, cvsroot, path, revision=None): """ Read a single file from the CVS repository without checking out a full working directory. :param cvsroot: the CVSROOT for the repository :param path: path to the file relative to cvs root :param revision: revision or tag to get (retrieves from HEAD if None) """ command = ["cvs", "-d", cvsroot, "-Q", "co", "-p"] if revision: command.extend(["-r", revision]) # the path is the last argument command.append(path) exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[CVS] Could not read '%s' from '%s': %s / %s" % (path, cvsroot, output, error)) return output
def commit(self, message=None, author=None): """Commits the file and supplies the given commit message if present the 'author' parameter is not suitable for CVS, thus it is ignored """ working_dir = os.path.dirname(self.location_abs) filename = os.path.basename(self.location_abs) command = ["cvs", "-Q", "commit"] if message: command.extend(["-m", message]) # the filename is the last argument command.append(filename) exitcode, output, error = run_command(command, working_dir) # raise an error or return successfully - depending on the CVS command if exitcode != 0: raise IOError("[CVS] Error running CVS command '%s': %s" % (command, error)) else: return output
def _readfile(self, cvsroot, path, revision=None): """ Read a single file from the CVS repository without checking out a full working directory. @param cvsroot: the CVSROOT for the repository @param path: path to the file relative to cvs root @param revision: revision or tag to get (retrieves from HEAD if None) """ command = ["cvs", "-d", cvsroot, "-Q", "co", "-p"] if revision: command.extend(["-r", revision]) # the path is the last argument command.append(path) exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[CVS] Could not read '%s' from '%s': %s / %s" % \ (path, cvsroot, output, error)) return output
def commit(self, message=None, author=None): """commit the file and return the given message if present the 'author' parameter is used for revision property 'translate:author' """ command = ["p4", "submit"] description = "Submission via translation portal" if message: description = "%s : %s" (description, message) command.extend(["-d", description]) if author: description = "%d --- by " % (description, author) # the location is the last argument command.append(self.location_abs) exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[P4] Perforce error running '%s': %s" \ % (command, error)) return output
def is_available(): """check if bzr is installed""" exitcode, output, error = run_command(["bzr", "version"]) return exitcode == 0
def is_available(): """check if bzr is installed""" exitcode, output, error = run_command(["bzr", "version"]) return exitcode == 0
def setup_repo_and_checkout(self): run_command(["svnadmin", "create", "repo"], cwd=self.path) run_command(["svn", "co", "file:///%s/repo" % self.path, "checkout"], cwd=self.path)
class cvs(GenericRevisionControlSystem): """Class to manage items under revision control of CVS.""" RCS_METADIR = "CVS" SCAN_PARENTS = False def _readfile(self, cvsroot, path, revision=None): """ Read a single file from the CVS repository without checking out a full working directory. :param cvsroot: the CVSROOT for the repository :param path: path to the file relative to cvs root :param revision: revision or tag to get (retrieves from HEAD if None) """ command = ["cvs", "-d", cvsroot, "-Q", "co", "-p"] if revision: command.extend(["-r", revision]) # the path is the last argument command.append(path) exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[CVS] Could not read '%s' from '%s': %s / %s" % \ (path, cvsroot, output, error)) return output def getcleanfile(self, revision=None): """Get the content of the file for the given revision""" parentdir = os.path.dirname(self.location_abs) cvsdir = os.path.join(parentdir, "CVS") cvsroot = open(os.path.join(cvsdir, "Root"), "r").read().strip() cvspath = open(os.path.join(cvsdir, "Repository"), "r").read().strip() cvsfilename = os.path.join(cvspath, os.path.basename(self.location_abs)) if revision is None: cvsentries = open(os.path.join(cvsdir, "Entries"), "r").readlines() revision = self._getcvstag(cvsentries) if revision == "BASE": cvsentries = open(os.path.join(cvsdir, "Entries"), "r").readlines() revision = self._getcvsrevision(cvsentries) return self._readfile(cvsroot, cvsfilename, revision) def update(self, revision=None, needs_revert=True): """Does a clean update of the given path""" #TODO: take needs_revert parameter into account working_dir = os.path.dirname(self.location_abs) filename = self.location_abs filename_backup = filename + os.path.extsep + "bak" # rename the file to be updated try: os.rename(filename, filename_backup) except OSError, error: raise IOError("[CVS] could not move the file '%s' to '%s': %s" % \ (filename, filename_backup, error)) command = ["cvs", "-Q", "update", "-C"] if revision: command.extend(["-r", revision]) # the filename is the last argument command.append(os.path.basename(filename)) # run the command within the given working_dir exitcode, output, error = run_command(command, working_dir) # restore backup in case of an error - remove backup for success try: if exitcode != 0: os.rename(filename_backup, filename) else: os.remove(filename_backup) except OSError: pass # raise an error or return successfully - depending on the CVS command if exitcode != 0: raise IOError("[CVS] Error running CVS command '%s': %s" % (command, error)) else: return output
def _has_changes(self): command = self._get_git_command(["diff", "--cached", "--exit-code"]) exitcode, output_checkout, error = run_command(command, self.root_dir) return bool(exitcode)
def setup_repo_and_checkout(self): run_command(["svnadmin", "create", "repo"], cwd=self.path) run_command(["svn", "co", "file:///%s/repo" % self.path, "checkout"], cwd=self.path)
def is_available(): """check if cvs is installed""" exitcode, output, error = run_command(["cvs", "--version"]) return exitcode == 0