Fix some PEP8 errors in util.py

Signed-off-by: Qixiang Wan <qwan@redhat.com>
This commit is contained in:
Qixiang Wan 2017-03-29 10:04:42 +08:00
parent 0f508e2228
commit 0ee2189d9c
1 changed files with 9 additions and 7 deletions

View File

@ -37,7 +37,6 @@ from .wrappers import kojiwrapper
def _doRunCommand(command, logger, rundir='/tmp', output=subprocess.PIPE, error=subprocess.PIPE, env=None): def _doRunCommand(command, logger, rundir='/tmp', output=subprocess.PIPE, error=subprocess.PIPE, env=None):
"""Run a command and log the output. Error out if we get something on stderr""" """Run a command and log the output. Error out if we get something on stderr"""
logger.info("Running %s" % subprocess.list2cmdline(command)) logger.info("Running %s" % subprocess.list2cmdline(command))
p1 = subprocess.Popen(command, cwd=rundir, stdout=output, stderr=error, universal_newlines=True, env=env, p1 = subprocess.Popen(command, cwd=rundir, stdout=output, stderr=error, universal_newlines=True, env=env,
@ -50,7 +49,8 @@ def _doRunCommand(command, logger, rundir='/tmp', output=subprocess.PIPE, error=
if p1.returncode != 0: if p1.returncode != 0:
logger.error("Got an error from %s" % command[0]) logger.error("Got an error from %s" % command[0])
logger.error(err) logger.error(err)
raise OSError, "Got an error (%d) from %s: %s" % (p1.returncode, command[0], err) raise OSError("Got an error (%d) from %s: %s" % (p1.returncode, command[0], err))
def _link(local, target, logger, force=False): def _link(local, target, logger, force=False):
"""Simple function to link or copy a package, removing target optionally.""" """Simple function to link or copy a package, removing target optionally."""
@ -58,7 +58,7 @@ def _link(local, target, logger, force=False):
if os.path.exists(target) and force: if os.path.exists(target) and force:
os.remove(target) os.remove(target)
#check for broken links # check for broken links
if force and os.path.islink(target): if force and os.path.islink(target):
if not os.path.exists(os.readlink(target)): if not os.path.exists(os.readlink(target)):
os.remove(target) os.remove(target)
@ -66,13 +66,14 @@ def _link(local, target, logger, force=False):
try: try:
os.link(local, target) os.link(local, target)
except OSError, e: except OSError, e:
if e.errno != 18: # EXDEV if e.errno != 18: # EXDEV
logger.error('Got an error linking from cache: %s' % e) logger.error('Got an error linking from cache: %s' % e)
raise OSError, e raise OSError(e)
# Can't hardlink cross file systems # Can't hardlink cross file systems
shutil.copy2(local, target) shutil.copy2(local, target)
def _ensuredir(target, logger, force=False, clean=False): def _ensuredir(target, logger, force=False, clean=False):
"""Ensure that a directory exists, if it already exists, only continue """Ensure that a directory exists, if it already exists, only continue
if force is set.""" if force is set."""
@ -110,6 +111,7 @@ def _ensuredir(target, logger, force=False, clean=False):
sys.stderr(message) sys.stderr(message)
sys.exit(1) sys.exit(1)
def _doCheckSum(path, hash, logger): def _doCheckSum(path, hash, logger):
"""Generate a checksum hash from a provided path. """Generate a checksum hash from a provided path.
Return a string of type:hash""" Return a string of type:hash"""
@ -131,9 +133,9 @@ def _doCheckSum(path, hash, logger):
# Loop through the file reading chunks at a time as to not # Loop through the file reading chunks at a time as to not
# put the entire file in memory. That would suck for DVDs # put the entire file in memory. That would suck for DVDs
while True: while True:
chunk = myfile.read(8192) # magic number! Taking suggestions for better blocksize chunk = myfile.read(8192) # magic number! Taking suggestions for better blocksize
if not chunk: if not chunk:
break # we're done with the file break # we're done with the file
sum.update(chunk) sum.update(chunk)
myfile.close() myfile.close()