Use with statement.
This commit is contained in:
parent
39c23ddf37
commit
d0b5f254bb
|
@ -32,14 +32,11 @@ def extract_bzip2 (archive, compression, cmd, **kwargs):
|
|||
targetname = util.get_single_outfile(outdir, archive)
|
||||
bz2file = bz2.BZ2File(archive)
|
||||
try:
|
||||
targetfile = open(targetname, 'wb')
|
||||
try:
|
||||
with open(targetname, 'wb') as targetfile:
|
||||
data = bz2file.read(READ_SIZE_BYTES)
|
||||
while data:
|
||||
targetfile.write(data)
|
||||
data = bz2file.read(READ_SIZE_BYTES)
|
||||
finally:
|
||||
targetfile.close()
|
||||
finally:
|
||||
bz2file.close()
|
||||
if verbose:
|
||||
|
@ -57,16 +54,13 @@ def create_bzip2 (archive, compression, cmd, *args, **kwargs):
|
|||
bz2file = bz2.BZ2File(archive, 'wb')
|
||||
try:
|
||||
filename = args[0]
|
||||
srcfile = open(filename)
|
||||
try:
|
||||
with open(filename) as srcfile:
|
||||
data = srcfile.read(READ_SIZE_BYTES)
|
||||
while data:
|
||||
bz2file.write(data)
|
||||
data = srcfile.read(READ_SIZE_BYTES)
|
||||
if verbose:
|
||||
util.log_info('... added %s' % filename)
|
||||
finally:
|
||||
srcfile.close()
|
||||
finally:
|
||||
bz2file.close()
|
||||
return None
|
||||
|
|
|
@ -30,14 +30,11 @@ def extract_gzip (archive, compression, cmd, **kwargs):
|
|||
targetname = util.get_single_outfile(outdir, archive)
|
||||
gzipfile = gzip.GzipFile(archive)
|
||||
try:
|
||||
targetfile = open(targetname, 'wb')
|
||||
try:
|
||||
with open(targetname, 'wb') as targetfile:
|
||||
data = gzipfile.read(READ_SIZE_BYTES)
|
||||
while data:
|
||||
targetfile.write(data)
|
||||
data = gzipfile.read(READ_SIZE_BYTES)
|
||||
finally:
|
||||
targetfile.close()
|
||||
finally:
|
||||
gzipfile.close()
|
||||
if verbose:
|
||||
|
@ -55,16 +52,13 @@ def create_gzip (archive, compression, cmd, *args, **kwargs):
|
|||
gzipfile = gzip.GzipFile(archive, 'wb')
|
||||
try:
|
||||
filename = args[0]
|
||||
srcfile = open(filename)
|
||||
try:
|
||||
with open(filename) as srcfile:
|
||||
data = srcfile.read(READ_SIZE_BYTES)
|
||||
while data:
|
||||
gzipfile.write(data)
|
||||
data = srcfile.read(READ_SIZE_BYTES)
|
||||
if verbose:
|
||||
util.log_info('... added %s' % filename)
|
||||
finally:
|
||||
srcfile.close()
|
||||
finally:
|
||||
gzipfile.close()
|
||||
return None
|
||||
|
|
Loading…
Reference in New Issue