Cleanup other misc pylint warnings

This commit is contained in:
Brian C. Lane 2014-05-08 17:22:14 -07:00
parent 6d47689a33
commit 0094fab0d4
7 changed files with 37 additions and 27 deletions

View File

@ -1,7 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
from distutils.core import setup from distutils.core import setup
from glob import glob
import os import os
import sys import sys

View File

@ -19,7 +19,6 @@
import glob import glob
import optparse import optparse
import os import os
import shutil
import sys import sys
import rpm import rpm
@ -46,8 +45,8 @@ class ImageMinimizer:
def add_directory(self, files, dirname): def add_directory(self, files, dirname):
self.visited.add(dirname) self.visited.add(dirname)
for root, dirs, items in os.walk(dirname): for root, dirs, items in os.walk(dirname):
for dir in dirs: for d in dirs:
self.visited.add(os.path.join(root, dir)) self.visited.add(os.path.join(root, d))
for name in items: for name in items:
files.add(os.path.join(root, name)) files.add(os.path.join(root, name))
@ -124,14 +123,14 @@ class ImageMinimizer:
os.remove(tag) os.remove(tag)
#remove all empty directory. Every 8k counts! #remove all empty directory. Every 8k counts!
for dir in sorted(self.visited, reverse=True): for d in sorted(self.visited, reverse=True):
if len(os.listdir(dir)) == 0: if len(os.listdir(d)) == 0:
if self.dryrun: if self.dryrun:
print 'rm -rf ' + dir print 'rm -rf ' + d
else: else:
if self.verbose: if self.verbose:
print 'rm -rf ' + dir print 'rm -rf ' + d
os.rmdir(dir) os.rmdir(d)
def remove_rpm(self): def remove_rpm(self):
@ -182,7 +181,7 @@ def parse_options():
return (options, args) return (options, args)
if __name__ == "__main__": def main():
try: try:
(options, args) = parse_options() (options, args) = parse_options()
filename = args[0] filename = args[0]
@ -192,7 +191,10 @@ if __name__ == "__main__":
except SystemExit, e: except SystemExit, e:
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: except Exception, e:
print e print e
sys.exit(1) sys.exit(1)
if __name__ == "__main__":
main()

View File

@ -79,7 +79,7 @@ class LogRequestHandler(SocketServer.BaseRequestHandler):
""" """
def setup(self): def setup(self):
if self.server.log_path: if self.server.log_path:
self.fp = open(self.server.log_path, "w") self.fp = open(self.server.log_path, "w") # pylint: disable=attribute-defined-outside-init
else: else:
print "no log_path specified" print "no log_path specified"
self.request.settimeout(10) self.request.settimeout(10)
@ -350,8 +350,8 @@ def is_image_mounted(disk_img):
Return True if the disk_img is mounted Return True if the disk_img is mounted
""" """
with open("/proc/mounts") as mounts: with open("/proc/mounts") as mounts:
for mount in mounts: for mnt in mounts:
fields = mount.split() fields = mnt.split()
if len(fields) > 2 and fields[1] == disk_img: if len(fields) > 2 and fields[1] == disk_img:
return True return True
return False return False
@ -430,7 +430,7 @@ def make_fsimage(diskimage, fsimage, img_size=None, label="Anaconda"):
if not img_mount or not img_mount.mount_dir: if not img_mount or not img_mount.mount_dir:
return None return None
log.info("Creating fsimage %s (%s)", (fsimage, img_size or "minimized")) log.info("Creating fsimage %s (%s)", fsimage, img_size or "minimized")
if img_size: if img_size:
# convert to Bytes # convert to Bytes
img_size *= 1024**2 img_size *= 1024**2
@ -503,7 +503,7 @@ def make_livecd(opts, mount_dir, work_dir):
isolabel = opts.volid or "{0.name} {0.version} {1.basearch}".format(product, arch) isolabel = opts.volid or "{0.name} {0.version} {1.basearch}".format(product, arch)
if len(isolabel) > 32: if len(isolabel) > 32:
isolabel = isolabel[:32] isolabel = isolabel[:32]
log.warn("Truncating isolabel to 32 chars: %s" % (isolabel,)) log.warn("Truncating isolabel to 32 chars: %s", isolabel)
tb = TreeBuilder(product=product, arch=arch, domacboot=opts.domacboot, tb = TreeBuilder(product=product, arch=arch, domacboot=opts.domacboot,
inroot=mount_dir, outroot=work_dir, inroot=mount_dir, outroot=work_dir,
@ -774,7 +774,7 @@ def setup_logging(opts):
program_log.addHandler(fh) program_log.addHandler(fh)
if __name__ == '__main__': def main():
parser = argparse.ArgumentParser( description="Create Live Install Media", parser = argparse.ArgumentParser( description="Create Live Install Media",
fromfile_prefix_chars="@" ) fromfile_prefix_chars="@" )
@ -1027,7 +1027,7 @@ if __name__ == '__main__':
try: try:
disk_img = make_image(opts, ks) disk_img = make_image(opts, ks)
except InstallError as e: except InstallError as e:
log.error("ERROR: Image creation failed: %s" % (e)) log.error("ERROR: Image creation failed: %s", e)
sys.exit(1) sys.exit(1)
if not opts.image_only: if not opts.image_only:
@ -1082,3 +1082,5 @@ if __name__ == '__main__':
sys.exit( 0 ) sys.exit( 0 )
if __name__ == '__main__':
main()

View File

@ -34,6 +34,7 @@ import os
import tempfile import tempfile
from optparse import OptionParser, OptionGroup from optparse import OptionParser, OptionGroup
import ConfigParser import ConfigParser
import shutil
import yum import yum
# This is a bit of a hack to short circuit yum's internal logging # This is a bit of a hack to short circuit yum's internal logging
@ -195,8 +196,8 @@ def main(args):
remove_temp=True) remove_temp=True)
def get_yum_base_object(installroot, repositories, mirrorlists=[], def get_yum_base_object(installroot, repositories, mirrorlists=None,
tempdir="/var/tmp", proxy=None, excludepkgs=[]): tempdir="/var/tmp", proxy=None, excludepkgs=None):
def sanitize_repo(repo): def sanitize_repo(repo):
if repo.startswith("/"): if repo.startswith("/"):
@ -207,6 +208,9 @@ def get_yum_base_object(installroot, repositories, mirrorlists=[],
else: else:
return None return None
mirrorlists = mirrorlists or []
excludepkgs = excludepkgs or []
# sanitize the repositories # sanitize the repositories
repositories = map(sanitize_repo, repositories) repositories = map(sanitize_repo, repositories)
mirrorlists = map(sanitize_repo, mirrorlists) mirrorlists = map(sanitize_repo, mirrorlists)

View File

@ -113,7 +113,7 @@ def mkefidisk(efiboot, outfile):
outfile.write(infile.read()) outfile.write(infile.read())
dm_detach(dmdev+"p1") dm_detach(dmdev+"p1")
if __name__ == '__main__': def main():
parser = argparse.ArgumentParser(description="Make an EFI boot image from the given directory.") parser = argparse.ArgumentParser(description="Make an EFI boot image from the given directory.")
parser.add_argument("--debug", action="store_const", const=logging.DEBUG, parser.add_argument("--debug", action="store_const", const=logging.DEBUG,
dest="loglevel", default=log.getEffectiveLevel(), dest="loglevel", default=log.getEffectiveLevel(),
@ -157,3 +157,6 @@ if __name__ == '__main__':
efiboot = tempfile.NamedTemporaryFile(prefix="mkefiboot.").name efiboot = tempfile.NamedTemporaryFile(prefix="mkefiboot.").name
shutil.move(opt.outfile, efiboot) shutil.move(opt.outfile, efiboot)
mkefidisk(efiboot, opt.outfile) mkefidisk(efiboot, opt.outfile)
if __name__ == '__main__':
main()

View File

@ -21,11 +21,11 @@ def main(args):
# parse sourcedir and targetdir # parse sourcedir and targetdir
sourcetree, targettree = {}, {} sourcetree, targettree = {}, {}
for tree, dir in [[sourcetree, sourcedir], [targettree, targetdir]]: for tree, d in [[sourcetree, sourcedir], [targettree, targetdir]]:
for root, dnames, fnames in os.walk(dir): for root, _dnames, fnames in os.walk(d):
for fname in fnames: for fname in fnames:
fpath = os.path.join(root, fname) fpath = os.path.join(root, fname)
rpath = fpath.replace(dir, "", 1) rpath = fpath.replace(d, "", 1)
tree[rpath] = fpath tree[rpath] = fpath
# set up magic # set up magic
@ -116,7 +116,7 @@ def main(args):
[(rpath, sizeinbytes, islink)] [(rpath, sizeinbytes, islink)]
# sort by size # sort by size
for pkg, size in sorted(sizedict.items(), key=operator.itemgetter(1), for pkg, _size in sorted(sizedict.items(), key=operator.itemgetter(1),
reverse=True): reverse=True):
for item in sorted(pkgdict[pkg]): for item in sorted(pkgdict[pkg]):

View File

@ -37,11 +37,11 @@ def get_args(template):
argspec = inspect.getargspec(template.module.render_body) argspec = inspect.getargspec(template.module.render_body)
return set(argspec.args[1:]) # skip "context" return set(argspec.args[1:]) # skip "context"
def readtemplate(templatefile): def readtemplate(filename):
parser = LoraxTemplate(directories=['.']) parser = LoraxTemplate(directories=['.'])
from mako.lookup import TemplateLookup from mako.lookup import TemplateLookup
lookup = TemplateLookup(directories=parser.directories) lookup = TemplateLookup(directories=parser.directories)
return lookup.get_template(templatefile) return lookup.get_template(filename)
if __name__ == '__main__': if __name__ == '__main__':
# check args # check args