diff --git a/mrepo.py b/mrepo.py index 68d7fae..6a2f738 100755 --- a/mrepo.py +++ b/mrepo.py @@ -71,8 +71,8 @@ def __init__(self, args): opts, args = getopt.getopt(args, 'c:d:fghnqr:t:uvx', ('config=', 'dist=', 'dry-run', 'force', 'generate', 'help', 'quiet', 'repo=', 'type=', 'update', 'verbose', 'version', 'extras')) - except getopt.error, exc: - print 'mrepo: %s, try mrepo -h for a list of all the options' % str(exc) + except getopt.error, instance: + print 'mrepo: %s, try mrepo -h for a list of all the options' % str(instance) sys.exit(1) for opt, arg in opts: @@ -232,13 +232,13 @@ def read(self, configfile): configfh = urllib.urlopen(configfile) try: self.cfg.readfp(configfh) - except ConfigParser.MissingSectionHeaderError: + except IOError: die(6, 'Error accessing URL: %s' % configfile) else: if os.access(configfile, os.R_OK): try: self.cfg.read(configfile) - except: + except ConfigParser.MissingSectionHeaderError: die(7, 'Syntax error reading file: %s' % configfile) else: die(6, 'Error accessing file: %s' % configfile) @@ -311,9 +311,9 @@ def getoption(self, section, option, var): try: var = self.cfg.get(section, option) info(3, 'Setting option %s in section [%s] to: %s' % (option, section, var)) - except ConfigParser.NoSectionError, e: + except ConfigParser.NoSectionError: error(5, 'Failed to find section [%s]' % section) - except ConfigParser.NoOptionError, e: + except ConfigParser.NoOptionError: info(5, 'Setting option %s in section [%s] to: %s (default)' % (option, section, var)) return var @@ -470,9 +470,9 @@ def mirror(self): mirrorreposync(url, self.srcdir, '%s-%s' % (self.dist.nick, self.name), self.dist) else: error(2, 'Scheme %s:// not implemented yet (in %s)' % (s, url)) - except mrepoMirrorException, e: - error(0, 'Mirroring failed for %s with message:\n %s' % (url, e.value)) - exitcode = 2 + except MrepoMirrorException as instance: + error(0, 'Mirroring failed for %s with message:\n %s' % (url, instance.value)) + EXITCODE = 2 if not self.url: ### Create directory in case no URL is given mkdir(self.srcdir) @@ -578,14 +578,14 @@ def createmd(self): if md in ('createrepo', 'repomd'): self.repomd() - except mrepoGenerateException, e: - error(0, 'Generating repo failed for %s with message:\n %s' % (self.name, e.value)) + except MrepoGenerateException as instance: + error(0, 'Generating repo failed for %s with message:\n %s' % (self.name, instance.value)) exitcode = 2 def repomd(self): "Create a repomd repository" if not cf.cmd['createrepo']: - raise mrepoGenerateException('Command createrepo is not found. Skipping.') + raise MrepoGenerateException('Command createrepo is not found. Skipping.') groupfilename = 'comps.xml' @@ -613,10 +613,10 @@ def repomd(self): info(2, '%s: Create repomd repository for %s' % (self.dist.nick, self.name)) ret = run('%s %s %s' % (cf.cmd['createrepo'], repoopts, self.wwwdir)) if ret: - raise(mrepoGenerateException('%s failed with return code: %s' % (cf.cmd['createrepo'], ret))) + raise MrepoGenerateException('%s failed with return code: %s' % (cf.cmd['createrepo'], ret)) -class mrepoMirrorException(Exception): +class MrepoMirrorException(Exception): def __init__(self, value): self.value = value @@ -624,7 +624,7 @@ def __str__(self): return repr(self.value) -class mrepoGenerateException(Exception): +class MrepoGenerateException(Exception): def __init__(self, value): self.value = value @@ -889,7 +889,7 @@ def mirrorrsync(url, path): ret = run('%s %s %s %s' % (cf.cmd['rsync'], opts, url, path), dryrun=True) if ret: - raise(mrepoMirrorException('Failed with return code: %s' % ret)) + raise MrepoMirrorException('Failed with return code: %s' % ret) def mirrorlftp(url, path, dist): @@ -932,7 +932,7 @@ def mirrorlftp(url, path, dist): ret = run('%s %s -c \'%s mirror %s %s %s\'' % (cf.cmd['lftp'], opts, cmds, mirroropts, url, path), dryrun=True) if ret: - raise(mrepoMirrorException('Failed with return code: %s' % ret)) + raise MrepoMirrorException('Failed with return code: %s' % ret) def mirrorreposync(url, path, reponame, dist): @@ -987,7 +987,7 @@ def mirrorreposync(url, path, reponame, dist): os.remove(reposync_conf_file) if ret: - raise(mrepoMirrorException('Failed with return code: %s' % ret)) + raise MrepoMirrorException('Failed with return code: %s' % ret) def which(cmd): @@ -1252,7 +1252,7 @@ def formatlist(pkglist): cf = readconfig() try: main() - except KeyboardInterrupt, e: + except KeyboardInterrupt: die(6, 'Exiting on user request') sys.exit(exitcode)