Clean up some pylint warnings

Mostly logging, using .format() on the strings.
This commit is contained in:
Brian C. Lane 2015-04-30 17:10:08 -07:00
parent d88cb00943
commit a6e469e0e6
8 changed files with 29 additions and 32 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.pyc *.pyc
src/pylorax/version.py* src/pylorax/version.py*
_build/ _build/
tests/pylint/.pylint.d/

View File

@ -50,7 +50,7 @@ master_doc = 'index'
# General information about the project. # General information about the project.
project = u'Lorax' project = u'Lorax'
copyright = u'2015, Red Hat, Inc.' copyright = u'2015, Red Hat, Inc.' # pylint: disable=redefined-builtin
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the

View File

@ -192,9 +192,6 @@ def main():
sys.exit(e.code) sys.exit(e.code)
except KeyboardInterrupt, e: except KeyboardInterrupt, e:
print >> sys.stderr, "Aborted at user request" print >> sys.stderr, "Aborted at user request"
except Exception, e:
print e
sys.exit(1)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -190,15 +190,15 @@ class Lorax(BaseLoraxClass):
self.init_stream_logging() self.init_stream_logging()
self.init_file_logging(logdir) self.init_file_logging(logdir)
logger.debug("version is {0}".format(vernum)) logger.debug("version is %s", vernum)
logger.debug("using work directory {0.workdir}".format(self)) logger.debug("using work directory %s", self.workdir)
logger.debug("using log directory {0}".format(logdir)) logger.debug("using log directory %s", logdir)
# set up output directory # set up output directory
self.outputdir = outputdir or tempfile.mkdtemp(prefix="pylorax.out.") self.outputdir = outputdir or tempfile.mkdtemp(prefix="pylorax.out.")
if not os.path.isdir(self.outputdir): if not os.path.isdir(self.outputdir):
os.makedirs(self.outputdir) os.makedirs(self.outputdir)
logger.debug("using output directory {0.outputdir}".format(self)) logger.debug("using output directory %s", self.outputdir)
# do we have root privileges? # do we have root privileges?
logger.info("checking for root privileges") logger.info("checking for root privileges")
@ -228,7 +228,7 @@ class Lorax(BaseLoraxClass):
logger.critical("no dnf base object") logger.critical("no dnf base object")
sys.exit(1) sys.exit(1)
self.inroot = dbo.conf.installroot self.inroot = dbo.conf.installroot
logger.debug("using install root: {0}".format(self.inroot)) logger.debug("using install root: %s", self.inroot)
if not buildarch: if not buildarch:
buildarch = get_buildarch(dbo) buildarch = get_buildarch(dbo)
@ -246,8 +246,7 @@ class Lorax(BaseLoraxClass):
# NOTE: if you change isolabel, you need to change pungi to match, or # NOTE: if you change isolabel, you need to change pungi to match, or
# the pungi images won't boot. # the pungi images won't boot.
isolabel = volid or "{0.name}-{0.version}-{1.basearch}".format(self.product, isolabel = volid or "%s-%s-%s" % (product, version, self.arch.basearch)
self.arch)
if len(isolabel) > 32: if len(isolabel) > 32:
logger.fatal("the volume id cannot be longer than 32 characters") logger.fatal("the volume id cannot be longer than 32 characters")

View File

@ -352,9 +352,9 @@ class PartitionMount(object):
except CalledProcessError: except CalledProcessError:
logger.debug(traceback.format_exc()) logger.debug(traceback.format_exc())
if self.mount_dir: if self.mount_dir:
logger.info("Partition mounted on {0} size={1}".format(self.mount_dir, self.mount_size)) logger.info("Partition mounted on %s size=%s", self.mount_dir, self.mount_size)
else: else:
logger.debug("Unable to mount anything from {0}".format(self.disk_img)) logger.debug("Unable to mount anything from %s", self.disk_img)
os.rmdir(mount_dir) os.rmdir(mount_dir)
return self return self

View File

@ -186,7 +186,7 @@ class LoraxTemplateRunner(object):
def run(self, templatefile, **variables): def run(self, templatefile, **variables):
for k,v in self.defaults.items() + self.builtins.items(): for k,v in self.defaults.items() + self.builtins.items():
variables.setdefault(k,v) variables.setdefault(k,v)
logger.debug("executing {0} with variables={1}".format(templatefile, variables)) logger.debug("executing %s with variables=%s", templatefile, variables)
self.templatefile = templatefile self.templatefile = templatefile
t = LoraxTemplate(directories=[self.templatedir]) t = LoraxTemplate(directories=[self.templatedir])
commands = t.parse(templatefile, variables) commands = t.parse(templatefile, variables)

View File

@ -128,7 +128,7 @@ class LogRequestHandler(SocketServer.BaseRequestHandler):
except socket.timeout: except socket.timeout:
pass pass
except: except Exception: # pylint: disable=broad-except
break break
def finish(self): def finish(self):
@ -434,7 +434,7 @@ class VirtualInstall(object):
Could use libvirt for this instead. Could use libvirt for this instead.
""" """
log.info("Shutting down {0}".format(self.virt_name)) log.info("Shutting down %s", self.virt_name)
subprocess.call(["virsh", "destroy", self.virt_name]) subprocess.call(["virsh", "destroy", self.virt_name])
subprocess.call(["virsh", "undefine", self.virt_name]) subprocess.call(["virsh", "undefine", self.virt_name])
@ -503,12 +503,12 @@ def make_appliance(disk_img, name, template, outfile, networks=None, ram=1024,
if not (disk_img and template and outfile): if not (disk_img and template and outfile):
return None return None
log.info("Creating appliance definition using {0}".format(template)) log.info("Creating appliance definition using %s", template)
if not arch: if not arch:
arch = "x86_64" arch = "x86_64"
log.info("Calculating SHA256 checksum of {0}".format(disk_img)) log.info("Calculating SHA256 checksum of %s", disk_img)
sha256 = hashlib.sha256() sha256 = hashlib.sha256()
with open(disk_img) as f: with open(disk_img) as f:
while True: while True:
@ -516,7 +516,7 @@ def make_appliance(disk_img, name, template, outfile, networks=None, ram=1024,
if not data: if not data:
break break
sha256.update(data) sha256.update(data)
log.info("SHA256 of {0} is {1}".format(disk_img, sha256.hexdigest())) log.info("SHA256 of %s is %s", disk_img, sha256.hexdigest())
disk_info = DataHolder(name=os.path.basename(disk_img), format="raw", disk_info = DataHolder(name=os.path.basename(disk_img), format="raw",
checksum_type="sha256", checksum=sha256.hexdigest()) checksum_type="sha256", checksum=sha256.hexdigest())
try: try:
@ -596,7 +596,7 @@ def rebuild_initrds_for_live(opts, sys_root_dir, results_dir):
dracut_args = [] dracut_args = []
for arg in opts.dracut_args: for arg in opts.dracut_args:
dracut_args += arg.split(" ", 1) dracut_args += arg.split(" ", 1)
log.info("dracut args = {0}".format(dracut_args)) log.info("dracut args = %s", dracut_args)
dracut = ["dracut", "--nomdadmconf", "--nolvmconf"] + dracut_args dracut = ["dracut", "--nomdadmconf", "--nolvmconf"] + dracut_args
@ -729,7 +729,7 @@ def make_livecd(opts, mount_dir, work_dir):
dracut_args = [] dracut_args = []
for arg in opts.dracut_args: for arg in opts.dracut_args:
dracut_args += arg.split(" ", 1) dracut_args += arg.split(" ", 1)
log.info("dracut args = {0}".format(dracut_args)) log.info("dracut args = %s", dracut_args)
tb.rebuild_initrds(add_args=dracut_args) tb.rebuild_initrds(add_args=dracut_args)
log.info("Building boot.iso") log.info("Building boot.iso")
tb.build() tb.build()
@ -1056,7 +1056,7 @@ def make_image(opts, ks):
virt_install(opts, install_log, disk_img, disk_size) virt_install(opts, install_log, disk_img, disk_size)
except InstallError as e: except InstallError as e:
log.error("Install failed: {0}".format(e)) log.error("Install failed: %s", e)
if not opts.keep_image and os.path.exists(disk_img): if not opts.keep_image and os.path.exists(disk_img):
log.info("Removing bad disk image") log.info("Removing bad disk image")
os.unlink(disk_img) os.unlink(disk_img)
@ -1436,7 +1436,7 @@ def main():
result_dir = None result_dir = None
if opts.make_iso: if opts.make_iso:
work_dir = tempfile.mkdtemp() work_dir = tempfile.mkdtemp()
log.info("working dir is {0}".format(work_dir)) log.info("working dir is %s", work_dir)
if (opts.fs_image or opts.no_virt) and not opts.disk_image: if (opts.fs_image or opts.no_virt) and not opts.disk_image:
# Create iso from a filesystem image # Create iso from a filesystem image
@ -1469,7 +1469,7 @@ def main():
opts.vcpus, opts.arch, opts.title, opts.project, opts.releasever) opts.vcpus, opts.arch, opts.title, opts.project, opts.releasever)
elif opts.make_pxe_live: elif opts.make_pxe_live:
work_dir = tempfile.mkdtemp() work_dir = tempfile.mkdtemp()
log.info("working dir is {0}".format(work_dir)) log.info("working dir is %s", work_dir)
if (opts.fs_image or opts.no_virt) and not opts.disk_image: if (opts.fs_image or opts.no_virt) and not opts.disk_image:
# Create pxe live images from a filesystem image # Create pxe live images from a filesystem image
@ -1503,12 +1503,12 @@ def main():
log.info("SUMMARY") log.info("SUMMARY")
log.info("-------") log.info("-------")
log.info("Logs are in {0}".format(os.path.abspath(os.path.dirname(opts.logfile)))) log.info("Logs are in %s", os.path.abspath(os.path.dirname(opts.logfile)))
if disk_img: if disk_img:
log.info("Disk image is at {0}".format(disk_img)) log.info("Disk image is at %s", disk_img)
if opts.make_appliance: if opts.make_appliance:
log.info("Appliance description is in {0}".format(opts.app_file)) log.info("Appliance description is in %s", opts.app_file)
log.info("Results are in {0}".format(opts.result_dir)) log.info("Results are in %s", opts.result_dir)
sys.exit( 0 ) sys.exit( 0 )

View File

@ -307,7 +307,7 @@ def get_dnf_base_object(installroot, repositories, mirrorlists=None,
# add the repositories # add the repositories
for i, r in enumerate(repositories): for i, r in enumerate(repositories):
if "SRPM" in r or "srpm" in r: if "SRPM" in r or "srpm" in r:
log.info("Skipping source repo: %s" % r) log.info("Skipping source repo: %s", r)
continue continue
repo_name = "lorax-repo-%d" % i repo_name = "lorax-repo-%d" % i
repo = dnf.repo.Repo(repo_name, cachedir) repo = dnf.repo.Repo(repo_name, cachedir)
@ -327,7 +327,7 @@ def get_dnf_base_object(installroot, repositories, mirrorlists=None,
# add the mirrorlists # add the mirrorlists
for i, r in enumerate(mirrorlists): for i, r in enumerate(mirrorlists):
if "SRPM" in r or "srpm" in r: if "SRPM" in r or "srpm" in r:
log.info("Skipping source repo: %s" % r) log.info("Skipping source repo: %s", r)
continue continue
repo_name = "lorax-mirrorlist-%d" % i repo_name = "lorax-mirrorlist-%d" % i
repo = dnf.repo.Repo(repo_name, cachedir) repo = dnf.repo.Repo(repo_name, cachedir)