Skip to content

Commit

Permalink
Clean up some pylint warnings
Browse files Browse the repository at this point in the history
Mostly logging, using .format() on the strings.
  • Loading branch information
bcl committed May 1, 2015
1 parent a2c2a4b commit d069f84
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
*.pyc
src/pylorax/version.py*
_build/
tests/pylint/.pylint.d/
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -50,7 +50,7 @@

# General information about the project.
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
# |version| and |release|, also used in various other places throughout the
Expand Down
3 changes: 0 additions & 3 deletions src/bin/image-minimizer
Expand Up @@ -192,9 +192,6 @@ def main():
sys.exit(e.code)
except KeyboardInterrupt, e:
print >> sys.stderr, "Aborted at user request"
except Exception, e:
print e
sys.exit(1)

if __name__ == "__main__":
main()
13 changes: 6 additions & 7 deletions src/pylorax/__init__.py
Expand Up @@ -190,15 +190,15 @@ def run(self, dbo, product, version, release, variant="", bugurl="",
self.init_stream_logging()
self.init_file_logging(logdir)

logger.debug("version is {0}".format(vernum))
logger.debug("using work directory {0.workdir}".format(self))
logger.debug("using log directory {0}".format(logdir))
logger.debug("version is %s", vernum)
logger.debug("using work directory %s", self.workdir)
logger.debug("using log directory %s", logdir)

# set up output directory
self.outputdir = outputdir or tempfile.mkdtemp(prefix="pylorax.out.")
if not os.path.isdir(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?
logger.info("checking for root privileges")
Expand Down Expand Up @@ -228,7 +228,7 @@ def run(self, dbo, product, version, release, variant="", bugurl="",
logger.critical("no dnf base object")
sys.exit(1)
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:
buildarch = get_buildarch(dbo)
Expand All @@ -246,8 +246,7 @@ def run(self, dbo, product, version, release, variant="", bugurl="",

# NOTE: if you change isolabel, you need to change pungi to match, or
# the pungi images won't boot.
isolabel = volid or "{0.name}-{0.version}-{1.basearch}".format(self.product,
self.arch)
isolabel = volid or "%s-%s-%s" % (product, version, self.arch.basearch)

if len(isolabel) > 32:
logger.fatal("the volume id cannot be longer than 32 characters")
Expand Down
4 changes: 2 additions & 2 deletions src/pylorax/imgutils.py
Expand Up @@ -352,9 +352,9 @@ def __enter__(self):
except CalledProcessError:
logger.debug(traceback.format_exc())
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:
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)
return self

Expand Down
2 changes: 1 addition & 1 deletion src/pylorax/ltmpl.py
Expand Up @@ -186,7 +186,7 @@ def _getsize(self, *files):
def run(self, templatefile, **variables):
for k,v in self.defaults.items() + self.builtins.items():
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
t = LoraxTemplate(directories=[self.templatedir])
commands = t.parse(templatefile, variables)
Expand Down
32 changes: 16 additions & 16 deletions src/sbin/livemedia-creator
Expand Up @@ -128,7 +128,7 @@ class LogRequestHandler(SocketServer.BaseRequestHandler):

except socket.timeout:
pass
except:
except Exception: # pylint: disable=broad-except
break

def finish(self):
Expand Down Expand Up @@ -434,7 +434,7 @@ class VirtualInstall(object):
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", "undefine", self.virt_name])

Expand Down Expand Up @@ -503,20 +503,20 @@ def make_appliance(disk_img, name, template, outfile, networks=None, ram=1024,
if not (disk_img and template and outfile):
return None

log.info("Creating appliance definition using {0}".format(template))
log.info("Creating appliance definition using %s", template)

if not arch:
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()
with open(disk_img) as f:
while True:
data = f.read(1024**2)
if not data:
break
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",
checksum_type="sha256", checksum=sha256.hexdigest())
try:
Expand Down Expand Up @@ -596,7 +596,7 @@ def rebuild_initrds_for_live(opts, sys_root_dir, results_dir):
dracut_args = []
for arg in opts.dracut_args:
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

Expand Down Expand Up @@ -729,7 +729,7 @@ def make_livecd(opts, mount_dir, work_dir):
dracut_args = []
for arg in opts.dracut_args:
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)
log.info("Building boot.iso")
tb.build()
Expand Down Expand Up @@ -874,8 +874,8 @@ def novirt_install(opts, disk_img, disk_size, repo_url):
if not os.path.isdir(log_anaconda):
os.mkdir(log_anaconda)
for l in glob.glob("/tmp/*log")+glob.glob("/tmp/anaconda-tb-*"):
shutil.copy2(l, log_anaconda)
os.unlink(l)
shutil.copy2(l, log_anaconda)
os.unlink(l)

if opts.make_iso or opts.make_fsimage:
umount(ROOT_PATH)
Expand Down Expand Up @@ -1056,7 +1056,7 @@ def make_image(opts, ks):

virt_install(opts, install_log, disk_img, disk_size)
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):
log.info("Removing bad disk image")
os.unlink(disk_img)
Expand Down Expand Up @@ -1436,7 +1436,7 @@ def main():
result_dir = None
if opts.make_iso:
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:
# Create iso from a filesystem image
Expand Down Expand Up @@ -1469,7 +1469,7 @@ def main():
opts.vcpus, opts.arch, opts.title, opts.project, opts.releasever)
elif opts.make_pxe_live:
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:
# Create pxe live images from a filesystem image
Expand Down Expand Up @@ -1503,12 +1503,12 @@ def main():

log.info("SUMMARY")
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:
log.info("Disk image is at {0}".format(disk_img))
log.info("Disk image is at %s", disk_img)
if opts.make_appliance:
log.info("Appliance description is in {0}".format(opts.app_file))
log.info("Results are in {0}".format(opts.result_dir))
log.info("Appliance description is in %s", opts.app_file)
log.info("Results are in %s", opts.result_dir)

sys.exit( 0 )

Expand Down
4 changes: 2 additions & 2 deletions src/sbin/lorax
Expand Up @@ -307,7 +307,7 @@ def get_dnf_base_object(installroot, repositories, mirrorlists=None,
# add the repositories
for i, r in enumerate(repositories):
if "SRPM" in r or "srpm" in r:
log.info("Skipping source repo: %s" % r)
log.info("Skipping source repo: %s", r)
continue
repo_name = "lorax-repo-%d" % i
repo = dnf.repo.Repo(repo_name, cachedir)
Expand All @@ -327,7 +327,7 @@ def get_dnf_base_object(installroot, repositories, mirrorlists=None,
# add the mirrorlists
for i, r in enumerate(mirrorlists):
if "SRPM" in r or "srpm" in r:
log.info("Skipping source repo: %s" % r)
log.info("Skipping source repo: %s", r)
continue
repo_name = "lorax-mirrorlist-%d" % i
repo = dnf.repo.Repo(repo_name, cachedir)
Expand Down

0 comments on commit d069f84

Please sign in to comment.