diff options
author | Dan Fandrich <danf@mageia.org> | 2024-05-27 15:53:38 -0700 |
---|---|---|
committer | Dan Fandrich <danf@mageia.org> | 2024-05-27 16:13:17 -0700 |
commit | 6d2c594260832373595effa4f63552a8068ae92c (patch) | |
tree | dd65b2a5e075310a9dbdecd07a78e920a2d77c42 /MgaRepo | |
parent | d9ad707ebbacca2bb13bf2d116b063518fb5c173 (diff) | |
download | mgarepo-6d2c594260832373595effa4f63552a8068ae92c.tar mgarepo-6d2c594260832373595effa4f63552a8068ae92c.tar.gz mgarepo-6d2c594260832373595effa4f63552a8068ae92c.tar.bz2 mgarepo-6d2c594260832373595effa4f63552a8068ae92c.tar.xz mgarepo-6d2c594260832373595effa4f63552a8068ae92c.zip |
Diffstat (limited to 'MgaRepo')
-rw-r--r-- | MgaRepo/svn.py | 67 |
1 files changed, 29 insertions, 38 deletions
diff --git a/MgaRepo/svn.py b/MgaRepo/svn.py index 1730901..c0d587f 100644 --- a/MgaRepo/svn.py +++ b/MgaRepo/svn.py @@ -1,12 +1,13 @@ from MgaRepo import Error, SilentError, config -from MgaRepo.util import execcmd, get_auth -import sys +from MgaRepo.util import execcmd import os import re +import sys import time __all__ = ["SVN", "SVNLook", "SVNLogEntry"] + class SVNLogEntry: def __init__(self, revision, author, date): self.revision = revision @@ -17,36 +18,29 @@ class SVNLogEntry: def __lt__(self, other): return (self.date < other.date) - - def __eq__(self,other): + + def __eq__(self, other): return (self.date == other.date) + class SVN: def _execsvn(self, *args, **kwargs): - localcmds = ("add", "revert", "cleanup", "mv") + localcmds = frozenset(("add", "revert", "cleanup", "mv")) if not kwargs.get("show") and args[0] not in localcmds: args = list(args) args.append("--non-interactive") else: - if args[0] == "mv": - kwargs["geterr"] = False - else: - kwargs["geterr"] = True + kwargs["geterr"] = args[0] != "mv" kwargs["cleanerr"] = True if kwargs.get("xml"): + args = list(args) args.append("--xml") self._set_env() svn_command = config.get("global", "svn-command", "svn") cmdstr = svn_command + " " + " ".join(args) try: - if args[0] in ('info', 'checkout','log'): - kwargs['info'] = True - else: - kwargs['info'] = False - if args[0] in ('status','propedit'): - kwargs['noprefix'] = True - else: - kwargs['noprefix'] = False + kwargs["info"] = args[0] in ("info", "checkout", "log") + kwargs["noprefix"] = args[0] in ("status", "propedit") return execcmd(cmdstr, **kwargs) except Error as e: msg = None @@ -64,9 +58,7 @@ class SVN: # svn has already dumped error messages, we don't need to # do it too if msg: - sys.stderr.write("\n") - sys.stderr.write(msg) - sys.stderr.write("\n") + sys.stderr.write("\n" + msg + "\n") raise SilentError elif msg: raise Error("%s\n%s" % (e, msg)) @@ -76,8 +68,8 @@ class SVN: wrapper = "mgarepo-ssh" repsys = config.get("global", "mgarepo-cmd") if repsys: - dir = os.path.dirname(repsys) - path = os.path.join(dir, wrapper) + dirname = os.path.dirname(repsys) + path = os.path.join(dirname, wrapper) if os.path.exists(path): wrapper = path defaults = {"SVN_SSH": wrapper} @@ -101,8 +93,7 @@ class SVN: def _add_log(self, cmd_args, received_kwargs, optional=0): if (not optional or - "log" in received_kwargs or - "logfile" in received_kwargs): + "log" in received_kwargs or "logfile" in received_kwargs): ret = received_kwargs.get("log") if ret is not None: cmd_args.append("-m '%s'" % ret) @@ -114,14 +105,14 @@ class SVN: if not optional or "rev" in received_kwargs: ret = received_kwargs.get("rev") if isinstance(ret, str): - if not ret.startswith("{"): # if not a datespec + if not ret.startswith("{"): # if not a datespec try: ret = int(ret) except ValueError: raise Error("invalid revision provided") if ret: cmd_args.append("-r '%s'" % ret) - + def add(self, path, **kwargs): cmd = ["add", path + '@' if '@' in path else path] return self._execsvn_success(noauth=1, *cmd, **kwargs) @@ -182,7 +173,7 @@ class SVN: self._add_revision(cmd, kwargs) status, output = self._execsvn(local=True, *cmd, **kwargs) return output - + def propset(self, propname, value, targets, **kwargs): cmd = ["propset", propname, "'%s'" % value, targets] return self._execsvn_success(*cmd, **kwargs) @@ -202,7 +193,7 @@ class SVN: if line.startswith("Last Changed Rev: "): return int(line.split()[3]) return None - + def info(self, path, **kwargs): cmd = ["info", path + '@' if '@' in path else path] status, output = self._execsvn(local=True, noerror=True, *cmd, **kwargs) @@ -218,9 +209,9 @@ class SVN: info = {} for pair in pairs: if pair != ['']: - info[pair[0]]=pair[1] + info[pair[0]] = pair[1] return info - + def ls(self, path, **kwargs): cmd = ["ls", path + '@' if '@' in path else path] status, output = self._execsvn(*cmd, **kwargs) @@ -256,8 +247,8 @@ class SVN: cmd = ["switch"] if relocate: if oldurl is None: - raise Error("You must supply the old URL when "\ - "relocating working copies") + raise Error("You must supply the old URL when " + "relocating working copies") cmd.append("--relocate") cmd.append(oldurl) cmd.append(url) @@ -273,8 +264,8 @@ class SVN: return [x.split() for x in output.split()] return None - def merge(self, url1, url2=None, rev1=None, rev2=None, path=None, - **kwargs): + def merge(self, url1, url2=None, rev1=None, rev2=None, path=None, + **kwargs): cmd = ["merge"] if rev1 and rev2 and not url2: cmd.append("-r") @@ -341,7 +332,7 @@ class SVN: if status != 0: return None - revheader = re.compile("^r(?P<revision>[0-9]+) \| (?P<author>[^\|]+) \| (?P<date>[^\|]+) \| (?P<lines>[0-9]+) (?:line|lines)$") + revheader = re.compile(r"^r(?P<revision>[0-9]+) \| (?P<author>[^\|]+) \| (?P<date>[^\|]+) \| (?P<lines>[0-9]+) (?:line|lines)$") changedpat = re.compile(r"^\s+(?P<action>[^\s]+) (?P<path>[^\s]+)(?: \([^\s]+ (?P<from_path>[^:]+)(?:\:(?P<from_rev>[0-9]+))?\))?$") logseparator = "-"*72 linesleft = 0 @@ -388,14 +379,15 @@ class SVN: return log def mv(self, path, dest, message=None, **kwargs): - cmd = ["mv", path, dest, ] + cmd = ["mv", path, dest] if message: - cmd.append("-m '%s'"%message) + cmd.append("-m '%s'" % message) else: kwargs['show'] = True self._add_log(cmd, kwargs) return self._execsvn_success(*cmd, **kwargs) + class SVNLook: def __init__(self, repospath, txn=None, rev=None): self.repospath = repospath @@ -436,7 +428,6 @@ class SVNLook: line = line.rstrip() if not line: continue - entry = [None, None, None] changedata, changeprop, path = None, None, None if line[0] != "_": changedata = line[0] |