aboutsummaryrefslogtreecommitdiffstats
path: root/MgaRepo
diff options
context:
space:
mode:
Diffstat (limited to 'MgaRepo')
-rw-r--r--MgaRepo/__init__.py2
-rw-r--r--MgaRepo/binrepo.py28
-rw-r--r--MgaRepo/cgi/soapserver.py18
-rw-r--r--MgaRepo/cgi/submit.py23
-rw-r--r--MgaRepo/cgi/xmlrpcserver.py32
-rw-r--r--MgaRepo/cgiutil.py6
-rw-r--r--MgaRepo/command.py14
-rw-r--r--MgaRepo/commands/authoremail.py6
-rw-r--r--MgaRepo/commands/changed.py2
-rw-r--r--MgaRepo/commands/co.py2
-rw-r--r--MgaRepo/commands/create.py2
-rw-r--r--MgaRepo/commands/del.py2
-rw-r--r--MgaRepo/commands/editlog.py2
-rw-r--r--MgaRepo/commands/getspec.py2
-rw-r--r--MgaRepo/commands/getsrpm.py4
-rw-r--r--MgaRepo/commands/maintdb.py2
-rw-r--r--MgaRepo/commands/markrelease.py14
-rw-r--r--MgaRepo/commands/patchspec.py2
-rw-r--r--MgaRepo/commands/rpmlog.py4
-rw-r--r--MgaRepo/commands/submit.py44
-rw-r--r--MgaRepo/layout.py38
-rw-r--r--MgaRepo/log.py24
-rw-r--r--MgaRepo/mirror.py30
-rw-r--r--MgaRepo/plugins/__init__.py4
-rw-r--r--MgaRepo/plugins/ldapusers.py32
-rw-r--r--MgaRepo/rpmutil.py136
-rw-r--r--MgaRepo/svn.py35
-rw-r--r--MgaRepo/util.py12
28 files changed, 260 insertions, 262 deletions
diff --git a/MgaRepo/__init__.py b/MgaRepo/__init__.py
index b0df184..1758b83 100644
--- a/MgaRepo/__init__.py
+++ b/MgaRepo/__init__.py
@@ -3,7 +3,7 @@ import re
import os
import tempfile
-import ConfigParser
+from . import ConfigParser
config = ConfigParser.Config()
tempfile.tempdir = config.get("global", "tempdir", None) or None # when ""
diff --git a/MgaRepo/binrepo.py b/MgaRepo/binrepo.py
index ee429f6..b15f4fe 100644
--- a/MgaRepo/binrepo.py
+++ b/MgaRepo/binrepo.py
@@ -10,10 +10,10 @@ import shutil
import re
import tempfile
import hashlib
-import urlparse
+import urllib.parse
import threading
import httplib2
-from cStringIO import StringIO
+from io import StringIO
SOURCES_FILE = "sha1.lst"
@@ -62,25 +62,25 @@ def download_binary(topdir, sha1, filename):
if file_hash(dest) == sha1:
return 1
else:
- raise Error, "File with incorrect sha1sum: %s" % dest
+ raise Error("File with incorrect sha1sum: %s" % dest)
context = {"dest": dest, "url": url}
try:
cmd = string.Template(fmt).substitute(context)
- except KeyError, e:
- raise Error, "invalid variable %r in download-command "\
- "configuration option" % e
+ except KeyError as e:
+ raise Error("invalid variable %r in download-command "\
+ "configuration option" % e)
try:
status, output = execcmd(cmd, show=True)
- except Error, e:
+ except Error as e:
os.unlink(dest)
- raise Error, "Could not download file %s\n" % url
+ raise Error("Could not download file %s\n" % url)
def download_binaries(topdir):
spath = sources_path(topdir)
if not os.path.exists(spath):
- raise Error, "'%s' was not found" % spath
+ raise Error("'%s' was not found" % spath)
entries = parse_sources(spath)
- for name, sha1 in entries.iteritems():
+ for name, sha1 in entries.items():
download_binary(topdir, sha1, name)
def binary_exists(sha1sum):
@@ -94,7 +94,7 @@ def binary_exists(sha1sum):
def upload_binary(topdir, filename):
filepath = os.path.join(topdir, 'SOURCES', filename)
if not os.path.exists(filepath):
- raise Error, "'%s' was not found" % filepath
+ raise Error("'%s' was not found" % filepath)
sha1sum = file_hash(filepath)
if binary_exists(sha1sum):
return
@@ -103,8 +103,8 @@ def upload_binary(topdir, filename):
command = "ssh %s %s %s" % (host, upload_bin_helper, filename)
try:
filein = open(filepath, 'r')
- except Error, e:
- raise Error, "Could not open file %s\n" % filepath
+ except Error as e:
+ raise Error("Could not open file %s\n" % filepath)
status, output = execcmd(command, show=True, geterr=True, stdin=filein)
def import_binaries(topdir, pkgname):
@@ -133,7 +133,7 @@ def parse_sources(path):
sum, name = line.split(None, 1)
except ValueError:
# failed to unpack, line format error
- raise Error, "invalid line in sources file: %s" % rawline
+ raise Error("invalid line in sources file: %s" % rawline)
entries[name] = sum
return entries
diff --git a/MgaRepo/cgi/soapserver.py b/MgaRepo/cgi/soapserver.py
index a203940..2fdbe0b 100644
--- a/MgaRepo/cgi/soapserver.py
+++ b/MgaRepo/cgi/soapserver.py
@@ -18,28 +18,28 @@ class SoapIface:
username = os.environ.get("REMOTE_USER")
packager = config.get("users", username)
if not packager:
- raise CgiError, "your email was not found"
+ raise CgiError("your email was not found")
elif not packagerev:
- raise CgiError, "no revision provided"
+ raise CgiError("no revision provided")
elif not targetname:
- raise CgiError, "no target provided"
+ raise CgiError("no target provided")
else:
targetname = targetname.lower()
for target in get_targets():
if target.name.lower() == targetname:
break
else:
- raise CgiError, "target not found"
+ raise CgiError("target not found")
try:
tmp = int(packagerev)
except ValueError:
- raise CgiError, "invalid revision provided"
+ raise CgiError("invalid revision provided")
for allowed in target.allowed:
if packageurl.startswith(allowed):
break
else:
- raise CgiError, "%s is not allowed for this target" \
- % packageurl
+ raise CgiError("%s is not allowed for this target" \
+ % packageurl)
get_srpm(packageurl,
revision=packagerev,
targetdirs=target.target,
@@ -73,10 +73,10 @@ Content-type: text/html
def show(msg="", error=0):
if error:
msg = '<font color="red">%s</font>' % msg
- print TEMPLATE % {"message":msg}
+ print(TEMPLATE % {"message":msg})
def main():
- if not os.environ.has_key('REQUEST_METHOD'):
+ if 'REQUEST_METHOD' not in os.environ:
sys.stderr.write("error: this program is meant to be used as a cgi\n")
sys.exit(1)
if not NINZ:
diff --git a/MgaRepo/cgi/submit.py b/MgaRepo/cgi/submit.py
index cba5977..e06ae07 100644
--- a/MgaRepo/cgi/submit.py
+++ b/MgaRepo/cgi/submit.py
@@ -55,7 +55,7 @@ def get_targetoptions():
def show(msg="", error=0):
if error:
msg = '<font color="red">%s</font>' % msg
- print TEMPLATE % {"message":msg, "targetoptions":get_targetoptions()}
+ print(TEMPLATE % {"message":msg, "targetoptions":get_targetoptions()})
def submit_packages(packager):
form = cgi.FieldStorage()
@@ -64,25 +64,25 @@ def submit_packages(packager):
if not packageurl:
show()
elif not packagerev:
- raise CgiError, "No revision provided!"
+ raise CgiError("No revision provided!")
else:
targetname = form.getfirst("target")
if not targetname:
- raise CgiError, "No target selected!"
+ raise CgiError("No target selected!")
for target in get_targets():
if target.name == targetname:
break
else:
- raise CgiError, "Target not found!"
+ raise CgiError("Target not found!")
try:
tmp = int(packagerev)
except ValueError:
- raise CgiError, "Invalid revision provided!"
+ raise CgiError("Invalid revision provided!")
for allowed in target.allowed:
if packageurl.startswith(allowed):
break
else:
- raise CgiError, "%s is not allowed for this target!" % packageurl
+ raise CgiError("%s is not allowed for this target!" % packageurl)
get_srpm(packageurl,
revision=packagerev,
targetdirs=target.target,
@@ -93,10 +93,10 @@ def submit_packages(packager):
show("Package submitted!")
def main():
- if not os.environ.has_key('REQUEST_METHOD'):
+ if 'REQUEST_METHOD' not in os.environ:
sys.stderr.write("error: this program is meant to be used as a cgi\n")
sys.exit(1)
- print "Content-type: text/html\n\n"
+ print("Content-type: text/html\n\n")
try:
username = os.environ.get("REMOTE_USER")
method = os.environ.get("REQUEST_METHOD")
@@ -105,12 +105,11 @@ def main():
else:
useremail = config.get("users", username)
if not useremail:
- raise CgiError, \
- "Your email was not found. Contact the administrator!"
+ raise CgiError("Your email was not found. Contact the administrator!")
submit_packages(useremail)
- except CgiError, e:
+ except CgiError as e:
show(str(e), error=1)
- except Error, e:
+ except Error as e:
error = str(e)
show(error[0].upper()+error[1:], error=1)
except:
diff --git a/MgaRepo/cgi/xmlrpcserver.py b/MgaRepo/cgi/xmlrpcserver.py
index 8521b4f..a1b2b73 100644
--- a/MgaRepo/cgi/xmlrpcserver.py
+++ b/MgaRepo/cgi/xmlrpcserver.py
@@ -5,7 +5,7 @@ from MgaRepo.cgiutil import CgiError, get_targets
import sys
import os
-import xmlrpclib, cgi
+import xmlrpc.client, cgi
class XmlRpcIface:
def author_email(self, author):
@@ -15,28 +15,28 @@ class XmlRpcIface:
username = os.environ.get("REMOTE_USER")
packager = config.get("users", username)
if not packager:
- raise CgiError, "your email was not found"
+ raise CgiError("your email was not found")
elif not packagerev:
- raise CgiError, "no revision provided"
+ raise CgiError("no revision provided")
elif not targetname:
- raise CgiError, "no target provided"
+ raise CgiError("no target provided")
else:
targetname = targetname.lower()
for target in get_targets():
if target.name.lower() == targetname:
break
else:
- raise CgiError, "target not found"
+ raise CgiError("target not found")
try:
tmp = int(packagerev)
except ValueError:
- raise CgiError, "invalid revision provided"
+ raise CgiError("invalid revision provided")
for allowed in target.allowed:
if packageurl.startswith(allowed):
break
else:
- raise CgiError, "%s is not allowed for this target" \
- % packageurl
+ raise CgiError("%s is not allowed for this target" \
+ % packageurl)
get_srpm(packageurl,
revision=packagerev,
targetdirs=target.target,
@@ -70,10 +70,10 @@ Content-type: text/html
def show(msg="", error=0):
if error:
msg = '<font color="red">%s</font>' % msg
- print TEMPLATE % {"message":msg}
+ print(TEMPLATE % {"message":msg})
def main():
- if not os.environ.has_key('REQUEST_METHOD'):
+ if 'REQUEST_METHOD' not in os.environ:
sys.stderr.write("error: this program is meant to be used as a cgi\n")
sys.exit(1)
username = os.environ.get("REMOTE_USER")
@@ -87,25 +87,25 @@ def main():
response = ""
try:
form = cgi.FieldStorage()
- parms, method = xmlrpclib.loads(form.value)
+ parms, method = xmlrpc.client.loads(form.value)
meth = getattr(iface, method)
response = (meth(*parms),)
- except CgiError, e:
+ except CgiError as e:
msg = str(e)
try:
msg = msg.decode("iso-8859-1")
except UnicodeError:
pass
- response = xmlrpclib.Fault(1, msg)
- except Exception, e:
+ response = xmlrpc.client.Fault(1, msg)
+ except Exception as e:
msg = str(e)
try:
msg = msg.decode("iso-8859-1")
except UnicodeError:
pass
- response = xmlrpclib.Fault(1, msg)
+ response = xmlrpc.client.Fault(1, msg)
sys.stdout.write("Content-type: text/xml\n\n")
- sys.stdout.write(xmlrpclib.dumps(response, methodresponse=1))
+ sys.stdout.write(xmlrpc.client.dumps(response, methodresponse=1))
# vim:et:ts=4:sw=4
diff --git a/MgaRepo/cgiutil.py b/MgaRepo/cgiutil.py
index 68afdcd..f55518b 100644
--- a/MgaRepo/cgiutil.py
+++ b/MgaRepo/cgiutil.py
@@ -24,8 +24,8 @@ def parse_macrosref(refs, config):
try:
macros.extend(config.walk(secname, raw=True))
except NoSectionError:
- raise Error, "missing macros section " \
- "%r in configuration" % secname
+ raise Error("missing macros section " \
+ "%r in configuration" % secname)
return macros
def get_targets():
@@ -46,7 +46,7 @@ def get_targets():
refs = value.split()
target.macros = parse_macrosref(refs, config)
else:
- raise Error, "unknown [%s] option %s" % (section, option)
+ raise Error("unknown [%s] option %s" % (section, option))
TARGETS.append(target)
return TARGETS
diff --git a/MgaRepo/command.py b/MgaRepo/command.py
index 9028b3b..9fc9cef 100644
--- a/MgaRepo/command.py
+++ b/MgaRepo/command.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
from MgaRepo import SilentError, Error, config
import sys, os
-import urlparse
+import urllib.parse
import optparse
__all__ = ["OptionParser", "do_command", "default_parent"]
@@ -31,7 +31,7 @@ class OptionParser(optparse.OptionParser):
return optparse.OptionParser.format_help(self, formatter)
def error(self, msg):
- raise Error, msg
+ raise Error(msg)
def do_command(parse_options_func, main_func):
try:
@@ -39,7 +39,7 @@ def do_command(parse_options_func, main_func):
main_func(**opt.__dict__)
except SilentError:
sys.exit(1)
- except Error, e:
+ except Error as e:
sys.stderr.write("error: %s\n" % str(e))
sys.exit(1)
except KeyboardInterrupt:
@@ -51,11 +51,11 @@ def default_parent(url):
if url.find("://") == -1:
default_parent = config.get("global", "default_parent")
if not default_parent:
- raise Error, "received a relative url, " \
- "but default_parent was not setup"
- parsed = list(urlparse.urlparse(default_parent))
+ raise Error("received a relative url, " \
+ "but default_parent was not setup")
+ parsed = list(urllib.parse.urlparse(default_parent))
parsed[2] = os.path.normpath(parsed[2] + "/" + url)
- url = urlparse.urlunparse(parsed)
+ url = urllib.parse.urlunparse(parsed)
return url
# vim:et:ts=4:sw=4
diff --git a/MgaRepo/commands/authoremail.py b/MgaRepo/commands/authoremail.py
index edfe332..fcb8a86 100644
--- a/MgaRepo/commands/authoremail.py
+++ b/MgaRepo/commands/authoremail.py
@@ -21,15 +21,15 @@ def parse_options():
parser = OptionParser(help=HELP)
opts, args = parser.parse_args()
if len(args) != 1:
- raise Error, "invalid arguments"
+ raise Error("invalid arguments")
opts.author = args[0]
return opts
def print_author_email(author):
email = config.get("users", author)
if not email:
- raise Error, "author not found"
- print email
+ raise Error("author not found")
+ print(email)
def main():
do_command(parse_options, print_author_email)
diff --git a/MgaRepo/commands/changed.py b/MgaRepo/commands/changed.py
index a17226b..4ac16bc 100644
--- a/MgaRepo/commands/changed.py
+++ b/MgaRepo/commands/changed.py
@@ -30,7 +30,7 @@ def parse_options():
callback=disable_mirror)
opts, args = parser.parse_args()
if len(args) != 1:
- raise Error, "invalid arguments"
+ raise Error("invalid arguments")
opts.pkgdirurl = package_url(args[0])
opts.verbose = 1 # Unconfigurable
return opts
diff --git a/MgaRepo/commands/co.py b/MgaRepo/commands/co.py
index 0a111e2..24ce257 100644
--- a/MgaRepo/commands/co.py
+++ b/MgaRepo/commands/co.py
@@ -42,7 +42,7 @@ def parse_options():
callback=disable_mirror)
opts, args = parser.parse_args()
if len(args) not in (1, 2):
- raise Error, "invalid arguments"
+ raise Error("invalid arguments")
# here we don't use package_url in order to notify the user we are
# using the mirror
opts.pkgdirurl = args[0]
diff --git a/MgaRepo/commands/create.py b/MgaRepo/commands/create.py
index da8f16c..e9a89e8 100644
--- a/MgaRepo/commands/create.py
+++ b/MgaRepo/commands/create.py
@@ -23,7 +23,7 @@ def parse_options():
parser = OptionParser(help=HELP)
opts, args = parser.parse_args()
if len(args) != 1:
- raise Error, "invalid arguments"
+ raise Error("invalid arguments")
opts.pkgdirurl = package_url(args[0], mirrored=False)
opts.verbose = 1 # Unconfigurable
return opts
diff --git a/MgaRepo/commands/del.py b/MgaRepo/commands/del.py
index f61a1d5..050c7bc 100644
--- a/MgaRepo/commands/del.py
+++ b/MgaRepo/commands/del.py
@@ -18,7 +18,7 @@ def parse_options():
if len(args):
opts.paths = args
else:
- raise Error, "you need to provide a path"
+ raise Error("you need to provide a path")
return opts
def main():
diff --git a/MgaRepo/commands/editlog.py b/MgaRepo/commands/editlog.py
index c58c16b..163651d 100644
--- a/MgaRepo/commands/editlog.py
+++ b/MgaRepo/commands/editlog.py
@@ -24,7 +24,7 @@ def parse_options():
elif len(args) == 1:
pkgdirurl, revision = "", args[0]
else:
- raise Error, "invalid arguments"
+ raise Error("invalid arguments")
opts.pkgdirurl = package_url(pkgdirurl, mirrored=False)
opts.revision = re.compile(r".*?(\d+).*").sub(r"\1", revision)
return opts
diff --git a/MgaRepo/commands/getspec.py b/MgaRepo/commands/getspec.py
index 08407bc..e1ba4c4 100644
--- a/MgaRepo/commands/getspec.py
+++ b/MgaRepo/commands/getspec.py
@@ -28,7 +28,7 @@ def parse_options():
callback=disable_mirror)
opts, args = parser.parse_args()
if len(args) != 1:
- raise Error, "invalid arguments"
+ raise Error("invalid arguments")
opts.pkgdirurl = package_url(args[0])
return opts
diff --git a/MgaRepo/commands/getsrpm.py b/MgaRepo/commands/getsrpm.py
index 9c96309..82bd626 100644
--- a/MgaRepo/commands/getsrpm.py
+++ b/MgaRepo/commands/getsrpm.py
@@ -49,7 +49,7 @@ def mode_callback(option, opt, val, parser, mode):
try:
opts.version, opts.release = val.split("-", 1)
except ValueError:
- raise Error, "wrong version, use something like 2.2-1mdk"
+ raise Error("wrong version, use something like 2.2-1mdk")
elif mode == "revision":
opts.revision = val
@@ -83,7 +83,7 @@ def parse_options():
opts, args = parser.parse_args()
del opts.__ignore
if len(args) != 1:
- raise Error, "invalid arguments"
+ raise Error("invalid arguments")
opts.pkgdirurl = package_url(args[0])
opts.verbose = 1
return opts
diff --git a/MgaRepo/commands/maintdb.py b/MgaRepo/commands/maintdb.py
index 08bf723..9a97be8 100644
--- a/MgaRepo/commands/maintdb.py
+++ b/MgaRepo/commands/maintdb.py
@@ -27,7 +27,7 @@ def parse_options():
if len(args):
opts.maintdb_args = args
else:
- raise Error, "you need to provide arguments, see them with --help"
+ raise Error("you need to provide arguments, see them with --help")
return opts
def maintdb(maintdb_args):
diff --git a/MgaRepo/commands/markrelease.py b/MgaRepo/commands/markrelease.py
index 857d38d..534d87f 100644
--- a/MgaRepo/commands/markrelease.py
+++ b/MgaRepo/commands/markrelease.py
@@ -45,7 +45,7 @@ def version_callback(option, opt, val, parser):
try:
opts.version, opts.release = val.split("-", 1)
except ValueError:
- raise Error, "wrong version, use something like 1:2.2-1mdk"
+ raise Error("wrong version, use something like 1:2.2-1mdk")
def parse_options():
parser = OptionParser(help=HELP)
@@ -59,7 +59,7 @@ def parse_options():
opts, args = parser.parse_args()
if len(args) != 1:
- raise Error, "invalid arguments"
+ raise Error("invalid arguments")
opts.pkgdirurl = package_url(args[0], mirrored=False)
@@ -69,12 +69,12 @@ def parse_options():
if filename:
if not os.path.isfile(filename):
- raise Error, "file not found: "+filename
+ raise Error("file not found: "+filename)
if not opts.revision:
basename = os.path.basename(filename)
end = basename.find(":")
if basename[0] != "@" or end == -1:
- raise Error, "couldn't guess revision from filename"
+ raise Error("couldn't guess revision from filename")
opts.revision = basename[1:end]
srpm = None
if not opts.version:
@@ -89,11 +89,11 @@ def parse_options():
srpm = SRPM(filename)
opts.pkgdirurl = "/".join([opts.pkgdirurl, srpm.name])
elif appendname:
- raise Error, "option -n requires option -f"
+ raise Error("option -n requires option -f")
elif not opts.revision:
- raise Error, "no revision provided"
+ raise Error("no revision provided")
elif not opts.version:
- raise Error, "no version provided"
+ raise Error("no version provided")
#get_auth()
return opts
diff --git a/MgaRepo/commands/patchspec.py b/MgaRepo/commands/patchspec.py
index 9a5811c..dfe54dc 100644
--- a/MgaRepo/commands/patchspec.py
+++ b/MgaRepo/commands/patchspec.py
@@ -27,7 +27,7 @@ def parse_options():
parser.add_option("-l", dest="log", default="")
opts, args = parser.parse_args()
if len(args) != 2:
- raise Error, "invalid arguments"
+ raise Error("invalid arguments")
opts.pkgdirurl = package_url(args[0], mirrored=False)
opts.patchfile = args[1]
return opts
diff --git a/MgaRepo/commands/rpmlog.py b/MgaRepo/commands/rpmlog.py
index 722cfe9..88dfc4b 100644
--- a/MgaRepo/commands/rpmlog.py
+++ b/MgaRepo/commands/rpmlog.py
@@ -7,7 +7,7 @@ from MgaRepo import Error, layout, disable_mirror
from MgaRepo.command import *
from MgaRepo.svn import SVN
from MgaRepo.log import get_changelog, split_spec_changelog
-from cStringIO import StringIO
+from io import StringIO
import getopt
import os
import sys
@@ -47,7 +47,7 @@ def parse_options():
callback=disable_mirror)
opts, args = parser.parse_args()
if len(args) != 1:
- raise Error, "invalid arguments"
+ raise Error("invalid arguments")
opts.pkgdirurl = layout.package_url(args[0])
return opts
diff --git a/MgaRepo/commands/submit.py b/MgaRepo/commands/submit.py
index d9dfdbc..9f05dca 100644
--- a/MgaRepo/commands/submit.py
+++ b/MgaRepo/commands/submit.py
@@ -4,14 +4,14 @@ from MgaRepo.svn import SVN
from MgaRepo.command import *
from MgaRepo.rpmutil import get_spec, get_submit_info
from MgaRepo.util import get_auth, execcmd, get_helper
-import urllib
+import urllib.request, urllib.parse, urllib.error
import getopt
import sys
import re
import subprocess
import uuid
-import xmlrpclib
+import xmlrpc.client
HELP = """\
Usage: mgarepo submit [OPTIONS] [URL[@REVISION] ...]
@@ -77,14 +77,14 @@ def parse_options():
if not args:
name, url, rev = get_submit_info(".")
args = ["%s@%s" % (url, str(rev))]
- print "Submitting %s at revision %s" % (name, rev)
- print "URL: %s" % url
+ print("Submitting %s at revision %s" % (name, rev))
+ print("URL: %s" % url)
if opts.revision is not None:
# backwards compatibility with the old -r usage
if len(args) == 1:
args[0] = args[0] + "@" + opts.revision
else:
- raise Error, "can't use -r REV with more than one package name"
+ raise Error("can't use -r REV with more than one package name")
del opts.revision
if len(args) == 2:
# prevent from using the old <name> <rev> syntax
@@ -94,14 +94,14 @@ def parse_options():
# ok, it is a package name, let it pass
pass
else:
- raise Error, "the format <name> <revision> is deprecated, "\
- "use <name>@<revision> instead"
+ raise Error("the format <name> <revision> is deprecated, "\
+ "use <name>@<revision> instead")
# expand group aliases
expanded = []
for nameurl in args:
expanded.extend(expand_group(nameurl))
if expanded != args:
- print "Submitting: %s" % " ".join(expanded)
+ print("Submitting: %s" % " ".join(expanded))
args = expanded
# generate URLs for package names:
opts.urls = [mirror.strip_username(
@@ -111,28 +111,28 @@ def parse_options():
newurls = []
for url in opts.urls:
if not "@" in url:
- print "Fetching revision..."
+ print("Fetching revision...")
courl = layout.checkout_url(url)
log = SVN().log(courl, limit=1)
if not log:
- raise Error, "can't find a revision for %s" % courl
+ raise Error("can't find a revision for %s" % courl)
ci = log[0]
- print "URL:", url
- print "Commit:",
- print "%d | %s" % (ci.revision, ci.author),
+ print("URL:", url)
+ print("Commit:", end=' ')
+ print("%d | %s" % (ci.revision, ci.author), end=' ')
if ci.lines:
line = " ".join(ci.lines).strip()
if len(line) > 57:
line = line[:57] + "..."
- print "| %s" % line,
- print
+ print("| %s" % line, end=' ')
+ print()
url = url + "@" + str(ci.revision)
newurls.append(url)
opts.urls[:] = newurls
# choose a target if not specified:
if opts.target is None and opts.distro is None:
target = layout.distro_branch(opts.urls[0]) or DEFAULT_TARGET
- print "Implicit target: %s" % target
+ print("Implicit target: %s" % target)
opts.target = target
del opts.distro
return opts
@@ -157,7 +157,7 @@ def expand_group(group):
def list_targets(option, opt, val, parser):
host = config.get("submit", "host")
if host is None:
- raise Error, "no submit host defined in mgarepo.conf"
+ raise Error("no submit host defined in mgarepo.conf")
createsrpm = get_helper("create-srpm")
#TODO make it configurable
command = "ssh %s %s --list" % (host, createsrpm)
@@ -169,10 +169,10 @@ def submit(urls, target, define=[], submithost=None, atonce=False, sid=None):
submithost = config.get("submit", "host")
if submithost is None:
# extract the submit host from the svn host
- type, rest = urllib.splittype(pkgdirurl)
- host, path = urllib.splithost(rest)
- user, host = urllib.splituser(host)
- submithost, port = urllib.splitport(host)
+ type, rest = urllib.parse.splittype(pkgdirurl)
+ host, path = urllib.parse.splithost(rest)
+ user, host = urllib.parse.splituser(host)
+ submithost, port = urllib.parse.splitport(host)
del type, user, port, path, rest
# runs a create-srpm in the server through ssh, which will make a
# copy of the rpm in the export directory
@@ -200,7 +200,7 @@ def submit(urls, target, define=[], submithost=None, atonce=False, sid=None):
command = subprocess.list2cmdline(cmdargs)
status, output = execcmd(command)
if status == 0:
- print "Package submitted!"
+ print("Package submitted!")
else:
sys.stderr.write(output)
sys.exit(status)
diff --git a/MgaRepo/layout.py b/MgaRepo/layout.py
index 093b276..e1cc6f4 100644
--- a/MgaRepo/layout.py
+++ b/MgaRepo/layout.py
@@ -1,7 +1,7 @@
""" Handles repository layout scheme and package URLs."""
import os
-import urlparse
+import urllib.parse
from MgaRepo import Error, config
from MgaRepo.svn import SVN
@@ -35,10 +35,10 @@ def unsplit_url_revision(url, rev):
if rev is None:
newurl = url
else:
- parsed = list(urlparse.urlparse(url))
+ parsed = list(urllib.parse.urlparse(url))
path = os.path.normpath(parsed[2])
parsed[2] = path + "@" + str(rev)
- newurl = urlparse.urlunparse(parsed)
+ newurl = urllib.parse.urlunparse(parsed)
return newurl
def split_url_revision(url):
@@ -46,7 +46,7 @@ def split_url_revision(url):
If the revision is not present in the URL, rev is None.
"""
- parsed = list(urlparse.urlparse(url))
+ parsed = list(urllib.parse.urlparse(url))
path = os.path.normpath(parsed[2])
dirs = path.rsplit("/", 1)
lastname = dirs[-1]
@@ -62,11 +62,11 @@ def split_url_revision(url):
if rev < 0:
raise ValueError
except ValueError:
- raise Error, "invalid revision specification on URL: %s" % url
+ raise Error("invalid revision specification on URL: %s" % url)
dirs[-1] = newname
newpath = "/".join(dirs)
parsed[2] = newpath
- newurl = urlparse.urlunparse(parsed)
+ newurl = urllib.parse.urlunparse(parsed)
return newurl, rev
def checkout_url(pkgdirurl, branch=None, version=None, release=None,
@@ -75,7 +75,7 @@ def checkout_url(pkgdirurl, branch=None, version=None, release=None,
It tries to preserve revisions in the format @REV.
"""
- parsed = list(urlparse.urlparse(pkgdirurl))
+ parsed = list(urllib.parse.urlparse(pkgdirurl))
path, rev = split_url_revision(parsed[2])
if releases:
path = os.path.normpath(path + "/releases")
@@ -92,27 +92,27 @@ def checkout_url(pkgdirurl, branch=None, version=None, release=None,
path = os.path.join(path, append_path)
path = unsplit_url_revision(path, rev)
parsed[2] = path
- newurl = urlparse.urlunparse(parsed)
+ newurl = urllib.parse.urlunparse(parsed)
return newurl
def convert_default_parent(url):
"""Removes the cauldron/ component from the URL"""
- parsed = list(urlparse.urlparse(url))
+ parsed = list(urllib.parse.urlparse(url))
path = os.path.normpath(parsed[2])
rest, last = os.path.split(path)
parsed[2] = rest
- newurl = urlparse.urlunparse(parsed)
+ newurl = urllib.parse.urlunparse(parsed)
return newurl
def remove_current(pkgdirurl):
- parsed = list(urlparse.urlparse(pkgdirurl))
+ parsed = list(urllib.parse.urlparse(pkgdirurl))
path = os.path.normpath(parsed[2])
rest, last = os.path.split(path)
if last == "current":
# FIXME this way we will not allow packages to be named "current"
path = rest
parsed[2] = path
- newurl = urlparse.urlunparse(parsed)
+ newurl = urllib.parse.urlunparse(parsed)
return newurl
def repository_url(mirrored=False):
@@ -125,8 +125,8 @@ def repository_url(mirrored=False):
# compatibility with the default_parent configuration option
default_parent = config.get("global", "default_parent")
if default_parent is None:
- raise Error, "you need to set the 'repository' " \
- "configuration option on mgarepo.conf"
+ raise Error("you need to set the 'repository' " \
+ "configuration option on mgarepo.conf")
url = convert_default_parent(default_parent)
return url
@@ -158,16 +158,16 @@ def package_url(name_or_url, version=None, release=None, distro=None,
else:
default_branch = devel_branch # cauldron
path = os.path.join(default_branch, name)
- parsed = list(urlparse.urlparse(repository_url(mirrored=mirrored)))
+ parsed = list(urllib.parse.urlparse(repository_url(mirrored=mirrored)))
parsed[2] = os.path.join(parsed[2], path)
- pkgdirurl = urlparse.urlunparse(parsed)
+ pkgdirurl = urllib.parse.urlunparse(parsed)
return pkgdirurl
def package_name(pkgdirurl):
"""Returns the package name from a package URL
It takes care of revision numbers"""
- parsed = urlparse.urlparse(pkgdirurl)
+ parsed = urllib.parse.urlparse(pkgdirurl)
path, rev = split_url_revision(parsed[2])
rest, name = os.path.split(path)
return name
@@ -188,10 +188,10 @@ def distro_branch(pkgdirurl):
repo = repository_url()
if same_base(repo, pkgdirurl):
devel_branch, branches_dir = layout_dirs()
- repo_path = urlparse.urlparse(repo)[2]
+ repo_path = urllib.parse.urlparse(repo)[2]
devel_path = os.path.join(repo_path, devel_branch)
branches_path = os.path.join(repo_path, branches_dir)
- parsed = urlparse.urlparse(pkgdirurl)
+ parsed = urllib.parse.urlparse(pkgdirurl)
path = os.path.normpath(parsed[2])
if path.startswith(devel_path):
# devel_branch must be before branches_dir in order to allow
diff --git a/MgaRepo/log.py b/MgaRepo/log.py
index a1ea0bf..5fded7c 100644
--- a/MgaRepo/log.py
+++ b/MgaRepo/log.py
@@ -6,9 +6,9 @@ from MgaRepo.util import execcmd
try:
from Cheetah.Template import Template
except ImportError:
- raise Error, "mgarepo requires the package python-cheetah"
+ raise Error("mgarepo requires the package python-cheetah")
-from cStringIO import StringIO
+from io import StringIO
import sys
import os
@@ -83,7 +83,7 @@ def getrelease(pkgdirurl, rev=None, macros=[], exported=None):
try:
found = glob.glob(os.path.join(tmpdir, "*.spec"))
if not found:
- raise Error, "no .spec file found inside %s" % specurl
+ raise Error("no .spec file found inside %s" % specurl)
specpath = found[0]
options = rpm_macros_defs(macros)
command = (("rpm -q --qf '%%{EPOCH}:%%{VERSION}-%%{RELEASE}\n' "
@@ -95,14 +95,14 @@ def getrelease(pkgdirurl, rev=None, macros=[], exported=None):
output = pipe.stdout.read()
error = pipe.stderr.read()
if pipe.returncode != 0:
- raise Error, "Error in command %s: %s" % (command, error)
+ raise Error("Error in command %s: %s" % (command, error))
releases = output.split()
try:
epoch, vr = releases[0].split(":", 1)
version, release = vr.split("-", 1)
except ValueError:
- raise Error, "Invalid command output: %s: %s" % \
- (command, output)
+ raise Error("Invalid command output: %s: %s" % \
+ (command, output))
#XXX check if this is the right way:
if epoch == "(none)":
ev = version
@@ -197,7 +197,7 @@ def group_releases_by_author(releases):
# create _Authors and sort them by their latest revisions
decorated = []
- for authorname, revs in authors.iteritems():
+ for authorname, revs in authors.items():
author = _Author()
author.name = revs[0].author_name
author.email = revs[0].author_email
@@ -374,7 +374,7 @@ def get_revision_offset():
try:
revoffset = config.getint("log", "revision-offset", 0)
except (ValueError, TypeError):
- raise Error, ("Invalid revision-offset number in configuration "
+ raise Error("Invalid revision-offset number in configuration "
"file(s).")
return revoffset or 0
@@ -479,7 +479,7 @@ def _split_changelog(stream):
def finish(entry):
lines = entry[2]
# strip newlines at the end
- for i in xrange(len(lines)-1, -1, -1):
+ for i in range(len(lines)-1, -1, -1):
if lines[i] != "\n":
break
del lines[i]
@@ -492,8 +492,8 @@ def _split_changelog(stream):
rawdate = " ".join(fields[:5])
try:
date = time.strptime(rawdate, "* %a %b %d %Y")
- except ValueError, e:
- raise Error, "failed to parse spec changelog: %s" % e
+ except ValueError as e:
+ raise Error("failed to parse spec changelog: %s" % e)
curlines = [line]
current = (date, count, curlines)
# count used to ensure stable sorting when changelog entries
@@ -631,6 +631,6 @@ def specfile_svn2rpm(pkgdirurl, specfile, rev=None, size=None,
if __name__ == "__main__":
l = svn2rpm(sys.argv[1])
- print l
+ print(l)
# vim:et:ts=4:sw=4
diff --git a/MgaRepo/mirror.py b/MgaRepo/mirror.py
index 1d1fcf3..205cc52 100644
--- a/MgaRepo/mirror.py
+++ b/MgaRepo/mirror.py
@@ -1,7 +1,7 @@
import sys
import os
-import urlparse
-import urllib
+import urllib.parse
+import urllib.request, urllib.parse, urllib.error
from MgaRepo import Error, config, layout
from MgaRepo.svn import SVN
@@ -12,24 +12,24 @@ def mirror_url():
def normalize_path(url):
"""normalize url for relocate_path needs"""
- parsed = urlparse.urlparse(url)
+ parsed = urllib.parse.urlparse(url)
path = os.path.normpath(parsed[2])
- newurl = urlparse.urlunparse((parsed[0], parsed[1], path,
+ newurl = urllib.parse.urlunparse((parsed[0], parsed[1], path,
parsed[3], parsed[4], parsed[5]))
return newurl
def _joinurl(url, relpath):
- parsed = urlparse.urlparse(url)
+ parsed = urllib.parse.urlparse(url)
newpath = os.path.join(parsed[2], relpath)
- newurl = urlparse.urlunparse((parsed[0], parsed[1], newpath,
+ newurl = urllib.parse.urlunparse((parsed[0], parsed[1], newpath,
parsed[3], parsed[4], parsed[5]))
return newurl
def strip_username(url):
- parsed = list(urlparse.urlparse(url))
- _, parsed[1] = urllib.splituser(parsed[1])
- newurl = urlparse.urlunparse(parsed)
+ parsed = list(urllib.parse.urlparse(url))
+ _, parsed[1] = urllib.parse.splituser(parsed[1])
+ newurl = urllib.parse.urlunparse(parsed)
return newurl
def same_base(parent, url):
@@ -99,13 +99,13 @@ def autoswitch(svn, wcpath, wcurl, newbaseurl=None):
repository = layout.repository_url()
current = repository
if repository is None:
- raise Error, "the option repository from mgarepo.conf is "\
- "required"
+ raise Error("the option repository from mgarepo.conf is "\
+ "required")
indefault = same_base(repository, wcurl)
if not newbaseurl:
if not mirror:
- raise Error, "an URL is needed when the option mirror "\
- "from mgarepo.conf is not set"
+ raise Error("an URL is needed when the option mirror "\
+ "from mgarepo.conf is not set")
if indefault:
chosen = mirror
elif same_base(mirror, wcurl):
@@ -122,8 +122,8 @@ def autoswitch(svn, wcpath, wcurl, newbaseurl=None):
nobase = True
chosen = newbaseurl
if nobase:
- raise Error, "the URL of this working copy is not based in "\
- "repository nor mirror URLs"
+ raise Error("the URL of this working copy is not based in "\
+ "repository nor mirror URLs")
assert current != chosen
newurl = mirror_relocate(current, chosen, wcurl, wcpath)
return newurl
diff --git a/MgaRepo/plugins/__init__.py b/MgaRepo/plugins/__init__.py
index 1eeb3bb..82a4eaa 100644
--- a/MgaRepo/plugins/__init__.py
+++ b/MgaRepo/plugins/__init__.py
@@ -17,11 +17,11 @@ def load():
[entry])
def list():
- return loaded.keys()
+ return list(loaded.keys())
def help(name):
from MgaRepo import Error
try:
return loaded[name].__doc__
except KeyError:
- raise Error, "plugin %s not found" % name
+ raise Error("plugin %s not found" % name)
diff --git a/MgaRepo/plugins/ldapusers.py b/MgaRepo/plugins/ldapusers.py
index dd202ed..a32402c 100644
--- a/MgaRepo/plugins/ldapusers.py
+++ b/MgaRepo/plugins/ldapusers.py
@@ -77,19 +77,19 @@ class LDAPError(Error):
def strip_entry(entry):
"Leave only the first value in all keys in the entry"
- new = dict((key, value[0]) for key, value in entry.iteritems())
+ new = dict((key, value[0]) for key, value in entry.items())
return new
def interpolate(optname, format, data):
tmpl = string.Template(format)
try:
return tmpl.substitute(data)
- except KeyError, e:
- raise Error, "the key %s was not found in LDAP search, " \
- "check your %s configuration" % (e, optname)
- except (TypeError, ValueError), e:
- raise Error, "LDAP response formatting error: %s. Check " \
- "your %s configuration" % (e, optname)
+ except KeyError as e:
+ raise Error("the key %s was not found in LDAP search, " \
+ "check your %s configuration" % (e, optname))
+ except (TypeError, ValueError) as e:
+ raise Error("LDAP response formatting error: %s. Check " \
+ "your %s configuration" % (e, optname))
def used_attributes(format):
class DummyDict:
@@ -117,8 +117,8 @@ def make_handler():
try:
port = int(config.get("global", "ldap-port", 389))
except ValueError:
- raise Error, "the option ldap-port requires an integer, please "\
- "check your configuration files"
+ raise Error("the option ldap-port requires an integer, please "\
+ "check your configuration files")
uri = "ldap://%s:%d" % (server, port)
basedn = config.get("global", "ldap-base")
@@ -133,21 +133,21 @@ def make_handler():
try:
starttls = valid[raw]
except KeyError:
- raise Error, "invalid value %r for ldap-starttls, use "\
- "'yes' or 'no'" % raw
+ raise Error("invalid value %r for ldap-starttls, use "\
+ "'yes' or 'no'" % raw)
try:
import ldap
except ImportError:
- raise Error, "LDAP support needs the python-ldap package "\
- "to be installed"
+ raise Error("LDAP support needs the python-ldap package "\
+ "to be installed")
else:
from ldap.filter import escape_filter_chars
def users_wrapper(section, option=None, default=None, walk=False):
global users_cache
if walk:
- raise Error, "ldapusers plugin does not support user listing"
+ raise Error("ldapusers plugin does not support user listing")
assert option is not None, \
"When not section walking, option is required"
@@ -161,7 +161,7 @@ def make_handler():
l.start_tls_s()
if binddn:
l.bind(binddn, bindpw)
- except ldap.LDAPError, e:
+ except ldap.LDAPError as e:
raise LDAPError(e)
try:
data = {"username": escape_filter_chars(option)}
@@ -170,7 +170,7 @@ def make_handler():
try:
found = l.search_s(basedn, ldap.SCOPE_SUBTREE, filter,
attrlist=attrs)
- except ldap.LDAPError, e:
+ except ldap.LDAPError as e:
raise LDAPError(e)
if found:
dn, entry = found[0]
diff --git a/MgaRepo/rpmutil.py b/MgaRepo/rpmutil.py
index 53fb3b2..facdd44 100644
--- a/MgaRepo/rpmutil.py
+++ b/MgaRepo/rpmutil.py
@@ -6,7 +6,7 @@ from MgaRepo.simplerpm import SRPM
from MgaRepo.util import execcmd
from MgaRepo.command import default_parent
import rpm
-import urlparse
+import urllib.parse
import tempfile
import shutil
import string
@@ -23,12 +23,12 @@ def get_spec(pkgdirurl, targetdir=".", submit=False):
svn.export("'%s'" % geturl, tmpdir)
speclist = glob.glob(os.path.join(tmpdir, "*.spec"))
if not speclist:
- raise Error, "no spec files found"
+ raise Error("no spec files found")
spec = speclist[0]
shutil.copy(spec, targetdir)
name = os.path.basename(spec)
path = os.path.join(targetdir, name)
- print "Wrote %s" % (name)
+ print("Wrote %s" % (name))
finally:
if os.path.isdir(tmpdir):
shutil.rmtree(tmpdir)
@@ -43,7 +43,7 @@ def rev_touched_url(url, rev):
svn = SVN()
info = svn.info2(url)
if info is None:
- raise Error, "can't fetch svn info about the URL: %s" % url
+ raise Error("can't fetch svn info about the URL: %s" % url)
root = info["Repository Root"]
urlpath = url[len(root):]
touched = False
@@ -90,13 +90,13 @@ def get_srpm(pkgdirurl,
#FIXME we should handle revisions specified using @REV
geturl = layout.checkout_url(pkgdirurl)
else:
- raise Error, "unsupported get_srpm mode: %s" % mode
+ raise Error("unsupported get_srpm mode: %s" % mode)
strict = strict or config.getbool("submit", "strict-revision", False)
if strict and not rev_touched_url(geturl, revision):
#FIXME would be nice to have the revision number even when
# revision is None
- raise Error, "the revision %s does not change anything "\
- "inside %s" % (revision or "HEAD", geturl)
+ raise Error("the revision %s does not change anything "\
+ "inside %s" % (revision or "HEAD", geturl))
mirror.info(geturl)
svn.export(geturl, tmpdir, rev=revision)
binrepo.download_binaries(tmpdir)
@@ -109,7 +109,7 @@ def get_srpm(pkgdirurl,
if os.path.exists(makefile):
execcmd("make", "-C", tmpdir, "srpm-prep")
if not speclist:
- raise Error, "no spec files found"
+ raise Error("no spec files found")
spec = speclist[0]
if svnlog:
submit = not not revision
@@ -120,7 +120,7 @@ def get_srpm(pkgdirurl,
status, output = execcmd(script, tmpdir, spec, str(revision),
noerror=1)
if status != 0:
- raise Error, "script %s failed" % script
+ raise Error("script %s failed" % script)
if packager:
packager = " --define 'packager %s'" % packager
@@ -140,7 +140,7 @@ def get_srpm(pkgdirurl,
srpms = glob.glob(os.path.join(srpmsdir, "*.src.rpm"))
if not srpms:
# something fishy happened
- raise Error, "no SRPMS were found at %s" % srpmsdir
+ raise Error("no SRPMS were found at %s" % srpmsdir)
for srpm in srpms:
name = os.path.basename(srpm)
if revname:
@@ -168,11 +168,11 @@ def patch_spec(pkgdirurl, patchfile, log=""):
svn.checkout(geturl, tmpdir)
speclist = glob.glob(os.path.join(tmpdir, "*.spec"))
if not speclist:
- raise Error, "no spec files found"
+ raise Error("no spec files found")
spec = speclist[0]
status, output = execcmd("patch", spec, patchfile)
if status != 0:
- raise Error, "can't apply patch:\n%s\n" % output
+ raise Error("can't apply patch:\n%s\n" % output)
else:
svn.commit(tmpdir, log="")
finally:
@@ -189,7 +189,7 @@ def put_srpm(srpmfile, markrelease=False, striplog=True, branch=None,
else:
pkgurl = layout.package_url(srpm.name, distro=branch,
mirrored=False)
- print "Importing package to %s" % pkgurl
+ print("Importing package to %s" % pkgurl)
try:
if srpm.epoch:
version = "%s:%s" % (srpm.epoch, srpm.version)
@@ -209,7 +209,7 @@ def put_srpm(srpmfile, markrelease=False, striplog=True, branch=None,
#svn.commit(tmpdir,log="Created package structure.")
version_exists = 1
else:
- raise Error, "package already exists or error creating package directory"
+ raise Error("package already exists or error creating package directory")
specsdir = os.path.join(currentdir, "SPECS")
sourcesdir = os.path.join(currentdir, "SOURCES")
@@ -264,9 +264,9 @@ def put_srpm(srpmfile, markrelease=False, striplog=True, branch=None,
specs = glob.glob(os.path.join(specsdir, "*.spec"))
if not specs:
- raise Error, "no spec file found on %s" % specsdir
+ raise Error("no spec file found on %s" % specsdir)
if len(specs) > 1:
- raise Error, "more than one spec file found on %s" % specsdir
+ raise Error("more than one spec file found on %s" % specsdir)
specpath = specs[0]
if rename:
specfile = os.path.basename(specpath)
@@ -343,26 +343,26 @@ def create_package(pkgdirurl, log="", verbose=0):
try:
basename = layout.package_name(pkgdirurl)
if verbose:
- print "Creating package directory...",
+ print("Creating package directory...", end=' ')
sys.stdout.flush()
ret = svn.mkdir(pkgdirurl,
log="Created package directory for '%s'." % basename)
if verbose:
- print "done"
- print "Checking it out...",
+ print("done")
+ print("Checking it out...", end=' ')
svn.checkout(pkgdirurl, tmpdir)
if verbose:
- print "done"
- print "Creating package structure...",
+ print("done")
+ print("Creating package structure...", end=' ')
svn.mkdir(os.path.join(tmpdir, "current"))
svn.mkdir(os.path.join(tmpdir, "current", "SPECS"))
svn.mkdir(os.path.join(tmpdir, "current", "SOURCES"))
if verbose:
- print "done"
- print "Committing...",
+ print("done")
+ print("Committing...", end=' ')
svn.commit(tmpdir,
log="Created package structure for '%s'." % basename)
- print "done"
+ print("done")
finally:
if os.path.isdir(tmpdir):
shutil.rmtree(tmpdir)
@@ -385,7 +385,7 @@ def mark_release(pkgdirurl, version, release, revision):
releaseurl = "/".join([versionurl, release])
currenturl = layout.checkout_url(pkgdirurl)
if svn.ls(releaseurl, noerror=1):
- raise Error, "release already exists"
+ raise Error("release already exists")
svn.mkdir(releasesurl, noerror=1,
log="Created releases directory.")
svn.mkdir(versionurl, noerror=1,
@@ -406,13 +406,13 @@ def check_changed(pkgdirurl, all=0, show=0, verbose=0):
baseurl = pkgdirurl
packages = []
if verbose:
- print "Getting list of packages...",
+ print("Getting list of packages...", end=' ')
sys.stdout.flush()
packages = [x[:-1] for x in svn.ls(baseurl)]
if verbose:
- print "done"
+ print("done")
if not packages:
- raise Error, "couldn't get list of packages"
+ raise Error("couldn't get list of packages")
else:
baseurl, basename = os.path.split(pkgdirurl)
packages = [basename]
@@ -425,36 +425,36 @@ def check_changed(pkgdirurl, all=0, show=0, verbose=0):
current = layout.checkout_url(pkgdirurl)
pristine = layout.checkout_url(pkgdirurl, pristine=True)
if verbose:
- print "Checking package %s..." % package,
+ print("Checking package %s..." % package, end=' ')
sys.stdout.flush()
if not svn.ls(current, noerror=1):
if verbose:
- print "NO CURRENT"
+ print("NO CURRENT")
nocurrent.append(package)
elif not svn.ls(pristine, noerror=1):
if verbose:
- print "NO PRISTINE"
+ print("NO PRISTINE")
nopristine.append(package)
else:
diff = svn.diff(pristine, current)
if diff:
changed.append(package)
if verbose:
- print "CHANGED"
+ print("CHANGED")
if show:
- print diff
+ print(diff)
else:
if verbose:
- print "clean"
+ print("clean")
clean.append(package)
if verbose:
if not packages:
- print "No packages found!"
+ print("No packages found!")
elif all:
- print "Total clean packages: %s" % len(clean)
- print "Total CHANGED packages: %d" % len(changed)
- print "Total NO CURRENT packages: %s" % len(nocurrent)
- print "Total NO PRISTINE packages: %s" % len(nopristine)
+ print("Total clean packages: %s" % len(clean))
+ print("Total CHANGED packages: %d" % len(changed))
+ print("Total NO CURRENT packages: %s" % len(nocurrent))
+ print("Total NO PRISTINE packages: %s" % len(nopristine))
return {"clean": clean,
"changed": changed,
"nocurrent": nocurrent,
@@ -484,7 +484,7 @@ def getpkgtopdir(basedir=None):
basedir = os.path.curdir
while not ispkgtopdir(basedir):
if os.path.abspath(basedir) == "/":
- raise Error, "can't find top package directories SOURCES and SPECS"
+ raise Error("can't find top package directories SOURCES and SPECS")
basedir = os.path.join(basedir, os.path.pardir)
if basedir.startswith("./"):
basedir = basedir[2:]
@@ -508,16 +508,16 @@ def sync(dryrun=False, commit=False, download=False):
sourcesdir = os.path.join(topdir, "SOURCES/")
for path in (specsdir, sourcesdir):
if not os.path.isdir(path):
- raise Error, "%s directory not found" % path
+ raise Error("%s directory not found" % path)
specs = glob.glob(os.path.join(specsdir, "*.spec"))
if not specs:
- raise Error, "no .spec files found in %s" % specsdir
+ raise Error("no .spec files found in %s" % specsdir)
specpath = specs[0] # FIXME better way?
try:
rpm.addMacro("_topdir", os.path.abspath(topdir))
spec = rpm.TransactionSet().parseSpec(specpath)
- except rpm.error, e:
- raise Error, "could not load spec file: %s" % e
+ except rpm.error as e:
+ raise Error("could not load spec file: %s" % e)
srclist = spec.sources if isinstance(spec.sources, (list, tuple)) \
else spec.sources()
sources = dict((os.path.basename(name), name)
@@ -533,7 +533,7 @@ def sync(dryrun=False, commit=False, download=False):
if specst == "?":
toadd.append(specpath)
# add source files:
- for source, url in sources.iteritems():
+ for source, url in sources.items():
sourcepath = os.path.join(sourcesdir, source)
if sourcesst.get(source):
if not (source in binrepoentries) and sourcesst.get(source)[1] == '?':
@@ -541,25 +541,25 @@ def sync(dryrun=False, commit=False, download=False):
elif not download and not os.path.isfile(sourcepath):
sys.stderr.write("warning: %s not found\n" % sourcepath)
elif download and not os.path.isfile(sourcepath):
- print "%s not found, downloading from %s" % (sourcepath, url)
+ print("%s not found, downloading from %s" % (sourcepath, url))
fmt = config.get("global", "download-command",
"wget -c -O '$dest' $url")
context = {"dest": sourcepath, "url": url}
try:
cmd = string.Template(fmt).substitute(context)
- except KeyError, e:
- raise Error, "invalid variable %r in download-command "\
- "configuration option" % e
+ except KeyError as e:
+ raise Error("invalid variable %r in download-command "\
+ "configuration option" % e)
try:
status, output = execcmd(cmd, show=True)
- except Error, e:
+ except Error as e:
os.unlink(sourcepath)
- raise Error, "Could not download file %s\n" % url
+ raise Error("Could not download file %s\n" % url)
if os.path.isfile(sourcepath):
toadd.append(sourcepath)
else:
- raise Error, "file not found: %s" % sourcepath
+ raise Error("file not found: %s" % sourcepath)
# rm entries not found in sources and still in svn
found = os.listdir(sourcesdir)
for entry in found:
@@ -571,11 +571,11 @@ def sync(dryrun=False, commit=False, download=False):
if status is None or entry in binrepoentries:
toremove.append(path)
for path in toremove:
- print "D\t%s" % path
+ print("D\t%s" % path)
if not dryrun:
delete([path], commit=commit)
for path in toadd:
- print "A\t%s" % path
+ print("A\t%s" % path)
if not dryrun:
upload([path], commit=commit)
@@ -583,16 +583,16 @@ def commit(target=".", message=None, logfile=None):
svn = SVN()
status = svn.status(target, quiet=True)
if not status:
- print "nothing to commit"
+ print("nothing to commit")
return
info = svn.info2(target)
url = info.get("URL")
if url is None:
- raise Error, "working copy URL not provided by svn info"
+ raise Error("working copy URL not provided by svn info")
mirrored = mirror.using_on(url)
if mirrored:
newurl = mirror.switchto_parent(svn, url, target)
- print "relocated to", newurl
+ print("relocated to", newurl)
# we can't use the svn object here because svn --non-interactive option
# hides VISUAL
opts = []
@@ -603,8 +603,8 @@ def commit(target=".", message=None, logfile=None):
mopts = " ".join(opts)
os.system("svn ci %s %s" % (mopts, target))
if mirrored:
- print "use \"mgarepo switch\" in order to switch back to mirror "\
- "later"
+ print("use \"mgarepo switch\" in order to switch back to mirror "\
+ "later")
def spec_sources(topdir):
specs = glob.glob(os.path.join(topdir, "SPECS/*.spec"))
@@ -630,8 +630,8 @@ def update(target=None):
if br_target:
info = svn.info2(svn_target)
if not br_target and not svn_target:
- raise Error, "target not in SVN nor in binaries "\
- "repository: %s" % target
+ raise Error("target not in SVN nor in binaries "\
+ "repository: %s" % target)
url = info["URL"]
binrepo.download_binaries(br_target)
@@ -676,9 +676,9 @@ def switch(mirrorurl=None):
info = svn.info2(topdir)
wcurl = info.get("URL")
if wcurl is None:
- raise Error, "working copy URL not provided by svn info"
+ raise Error("working copy URL not provided by svn info")
newurl = mirror.autoswitch(svn, topdir, wcurl, mirrorurl)
- print "switched to", newurl
+ print("switched to", newurl)
def get_submit_info(path):
path = os.path.abspath(path)
@@ -694,11 +694,11 @@ def get_submit_info(path):
break
path = os.path.dirname(path)
if not found:
- raise Error, "SPECS and/or SOURCES directories not found"
+ raise Error("SPECS and/or SOURCES directories not found")
# Then, check if this is really a subversion directory.
if not os.path.isdir(os.path.join(path, ".svn")):
- raise Error, "subversion directory not found"
+ raise Error("subversion directory not found")
svn = SVN()
@@ -706,10 +706,10 @@ def get_submit_info(path):
info = svn.info2(path)
url = info.get("URL")
if url is None:
- raise Error, "missing URL from svn info %s" % path
+ raise Error("missing URL from svn info %s" % path)
toks = url.split("/")
if len(toks) < 2 or toks[-1] != "current":
- raise Error, "unexpected URL received from 'svn info'"
+ raise Error("unexpected URL received from 'svn info'")
name = toks[-2]
url = "/".join(toks[:-1])
@@ -732,7 +732,7 @@ def get_submit_info(path):
if rev > max:
max = rev
if max == -1:
- raise Error, "revision tag not found in 'svn info' output"
+ raise Error("revision tag not found in 'svn info' output")
if mirror.using_on(url):
url = mirror.switchto_parent_url(url)
diff --git a/MgaRepo/svn.py b/MgaRepo/svn.py
index 89de8f9..5254ab1 100644
--- a/MgaRepo/svn.py
+++ b/MgaRepo/svn.py
@@ -38,7 +38,7 @@ class SVN:
else:
kwargs['info'] = False
return execcmd(cmdstr, **kwargs)
- except Error, e:
+ except Error as e:
msg = None
if e.args:
if "Permission denied" in e.args[0]:
@@ -59,7 +59,7 @@ class SVN:
sys.stderr.write("\n")
raise SilentError
elif msg:
- raise Error, "%s\n%s" % (e, msg)
+ raise Error("%s\n%s" % (e, msg))
raise
def _set_env(self):
@@ -91,8 +91,8 @@ class SVN:
def _add_log(self, cmd_args, received_kwargs, optional=0):
if (not optional or
- received_kwargs.has_key("log") or
- received_kwargs.has_key("logfile")):
+ "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)
@@ -101,14 +101,14 @@ class SVN:
cmd_args.append("-F '%s'" % ret)
def _add_revision(self, cmd_args, received_kwargs, optional=0):
- if not optional or received_kwargs.has_key("rev"):
+ if not optional or "rev" in received_kwargs:
ret = received_kwargs.get("rev")
- if isinstance(ret, basestring):
+ if isinstance(ret, str):
if not ret.startswith("{"): # if not a datespec
try:
ret = int(ret)
except ValueError:
- raise Error, "invalid revision provided"
+ raise Error("invalid revision provided")
if ret:
cmd_args.append("-r '%s'" % ret)
@@ -243,8 +243,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)
@@ -269,8 +269,7 @@ class SVN:
cmd.append(url1)
else:
if not url2:
- raise ValueError, \
- "url2 needed if two revisions are not provided"
+ raise ValueError("url2 needed if two revisions are not provided")
if rev1:
cmd.append("%s@%s" % (url1, rev1))
else:
@@ -311,19 +310,19 @@ class SVN:
try:
start = int(start)
except (ValueError, TypeError):
- raise Error, "invalid log start revision provided"
+ raise Error("invalid log start revision provided")
if type(end) is not type(0):
try:
end = int(end)
except (ValueError, TypeError):
- raise Error, "invalid log end revision provided"
+ raise Error("invalid log end revision provided")
start = start or "HEAD"
cmd.append("-r %s:%s" % (start, end))
if limit is not None:
try:
limit = int(limit)
except (ValueError, TypeError):
- raise Error, "invalid limit number provided"
+ raise Error("invalid limit number provided")
cmd.append("--limit %d" % limit)
status, output = self._execsvn(*cmd, **kwargs)
if status != 0:
@@ -354,7 +353,7 @@ class SVN:
try:
changed["from_rev"] = int(from_rev)
except (ValueError, TypeError):
- raise Error, "invalid revision number in svn log"
+ raise Error("invalid revision number in svn log")
entry.changed.append(changed)
elif linesleft == 0:
if line != logseparator:
@@ -388,18 +387,18 @@ class SVNLook:
execcmd_kwargs = {}
keywords = ["show", "noerror"]
for key in keywords:
- if kwargs.has_key(key):
+ if key in kwargs:
execcmd_kwargs[key] = kwargs[key]
return execcmd(*execcmd_args, **execcmd_kwargs)
def _add_txnrev(self, cmd_args, received_kwargs):
- if received_kwargs.has_key("txn"):
+ if "txn" in received_kwargs:
txn = received_kwargs.get("txn")
if txn is not None:
cmd_args += ["-t", txn]
elif self.txn is not None:
cmd_args += ["-t", self.txn]
- if received_kwargs.has_key("rev"):
+ if "rev" in received_kwargs:
rev = received_kwargs.get("rev")
if rev is not None:
cmd_args += ["-r", rev]
diff --git a/MgaRepo/util.py b/MgaRepo/util.py
index 54348d6..8271aec 100644
--- a/MgaRepo/util.py
+++ b/MgaRepo/util.py
@@ -8,7 +8,7 @@ import sys
import os
import re
import select
-from cStringIO import StringIO
+from io import StringIO
import httplib2
#import commands
@@ -64,11 +64,11 @@ def execcmd(*cmd, **kwargs):
verbose = config.getbool("global", "verbose", 0)
if status != 0 and not kwargs.get("noerror"):
if kwargs.get("cleanerr") and not verbose:
- raise Error, output
+ raise Error(output)
else:
- raise Error, "command failed: %s\n%s\n" % (cmdstr, output)
+ raise Error("command failed: %s\n%s\n" % (cmdstr, output))
if verbose:
- print cmdstr
+ print(cmdstr)
sys.stdout.write(output)
return status, output
@@ -78,7 +78,7 @@ def get_auth(username=None, password=None):
if not username:
username = config.get("auth", "username")
if not username:
- username = raw_input("username: ")
+ username = input("username: ")
else:
set_username = 0
if not password:
@@ -108,7 +108,7 @@ def mapurl(url):
else:
try:
newurl = re.sub(expr_, replace, url)
- except re.error, errmsg:
+ except re.error as errmsg:
sys.stderr.write("error in URL mapping regexp: %s" % errmsg)
return newurl