Use a context manager for some file objects.
This commit is contained in:
parent
24e561ae04
commit
7dde792e62
|
@ -61,21 +61,19 @@ def main():
|
||||||
else: optfile = "Lib/keyword.py"
|
else: optfile = "Lib/keyword.py"
|
||||||
|
|
||||||
# scan the source file for keywords
|
# scan the source file for keywords
|
||||||
fp = open(iptfile)
|
with open(iptfile) as fp:
|
||||||
strprog = re.compile('"([^"]+)"')
|
strprog = re.compile('"([^"]+)"')
|
||||||
lines = []
|
lines = []
|
||||||
for line in fp:
|
for line in fp:
|
||||||
if '{1, "' in line:
|
if '{1, "' in line:
|
||||||
match = strprog.search(line)
|
match = strprog.search(line)
|
||||||
if match:
|
if match:
|
||||||
lines.append(" '" + match.group(1) + "',\n")
|
lines.append(" '" + match.group(1) + "',\n")
|
||||||
fp.close()
|
|
||||||
lines.sort()
|
lines.sort()
|
||||||
|
|
||||||
# load the output skeleton from the target
|
# load the output skeleton from the target
|
||||||
fp = open(optfile)
|
with open(optfile) as fp:
|
||||||
format = fp.readlines()
|
format = fp.readlines()
|
||||||
fp.close()
|
|
||||||
|
|
||||||
# insert the lines of keywords
|
# insert the lines of keywords
|
||||||
try:
|
try:
|
||||||
|
|
14
Lib/pdb.py
14
Lib/pdb.py
|
@ -155,21 +155,15 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
||||||
if 'HOME' in os.environ:
|
if 'HOME' in os.environ:
|
||||||
envHome = os.environ['HOME']
|
envHome = os.environ['HOME']
|
||||||
try:
|
try:
|
||||||
rcFile = open(os.path.join(envHome, ".pdbrc"))
|
with open(os.path.join(envHome, ".pdbrc")) as rcFile:
|
||||||
|
self.rcLines.extend(rcFile)
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
else:
|
|
||||||
for line in rcFile.readlines():
|
|
||||||
self.rcLines.append(line)
|
|
||||||
rcFile.close()
|
|
||||||
try:
|
try:
|
||||||
rcFile = open(".pdbrc")
|
with open(".pdbrc") as rcFile:
|
||||||
|
self.rcLines.extend(rcFile)
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
else:
|
|
||||||
for line in rcFile.readlines():
|
|
||||||
self.rcLines.append(line)
|
|
||||||
rcFile.close()
|
|
||||||
|
|
||||||
self.commands = {} # associates a command list to breakpoint numbers
|
self.commands = {} # associates a command list to breakpoint numbers
|
||||||
self.commands_doprompt = {} # for each bp num, tells if the prompt
|
self.commands_doprompt = {} # for each bp num, tells if the prompt
|
||||||
|
|
|
@ -200,9 +200,8 @@ def _dist_try_harder(distname,version,id):
|
||||||
"""
|
"""
|
||||||
if os.path.exists('/var/adm/inst-log/info'):
|
if os.path.exists('/var/adm/inst-log/info'):
|
||||||
# SuSE Linux stores distribution information in that file
|
# SuSE Linux stores distribution information in that file
|
||||||
info = open('/var/adm/inst-log/info').readlines()
|
|
||||||
distname = 'SuSE'
|
distname = 'SuSE'
|
||||||
for line in info:
|
for line in open('/var/adm/inst-log/info'):
|
||||||
tv = line.split()
|
tv = line.split()
|
||||||
if len(tv) == 2:
|
if len(tv) == 2:
|
||||||
tag,value = tv
|
tag,value = tv
|
||||||
|
@ -217,8 +216,7 @@ def _dist_try_harder(distname,version,id):
|
||||||
|
|
||||||
if os.path.exists('/etc/.installed'):
|
if os.path.exists('/etc/.installed'):
|
||||||
# Caldera OpenLinux has some infos in that file (thanks to Colin Kong)
|
# Caldera OpenLinux has some infos in that file (thanks to Colin Kong)
|
||||||
info = open('/etc/.installed').readlines()
|
for line in open('/etc/.installed'):
|
||||||
for line in info:
|
|
||||||
pkg = line.split('-')
|
pkg = line.split('-')
|
||||||
if len(pkg) >= 2 and pkg[0] == 'OpenLinux':
|
if len(pkg) >= 2 and pkg[0] == 'OpenLinux':
|
||||||
# XXX does Caldera support non Intel platforms ? If yes,
|
# XXX does Caldera support non Intel platforms ? If yes,
|
||||||
|
@ -327,9 +325,8 @@ def linux_distribution(distname='', version='', id='',
|
||||||
return _dist_try_harder(distname,version,id)
|
return _dist_try_harder(distname,version,id)
|
||||||
|
|
||||||
# Read the first line
|
# Read the first line
|
||||||
f = open('/etc/'+file, 'r')
|
with open('/etc/'+file, 'r') as f:
|
||||||
firstline = f.readline()
|
firstline = f.readline()
|
||||||
f.close()
|
|
||||||
_distname, _version, _id = _parse_release_file(firstline)
|
_distname, _version, _id = _parse_release_file(firstline)
|
||||||
|
|
||||||
if _distname and full_distribution_name:
|
if _distname and full_distribution_name:
|
||||||
|
|
|
@ -169,9 +169,8 @@ _CFG = {"width" : 0.5, # Screen
|
||||||
|
|
||||||
def config_dict(filename):
|
def config_dict(filename):
|
||||||
"""Convert content of config-file into dictionary."""
|
"""Convert content of config-file into dictionary."""
|
||||||
f = open(filename, "r")
|
with open(filename, "r") as f:
|
||||||
cfglines = f.readlines()
|
cfglines = f.readlines()
|
||||||
f.close()
|
|
||||||
cfgdict = {}
|
cfgdict = {}
|
||||||
for line in cfglines:
|
for line in cfglines:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
|
|
Loading…
Reference in New Issue