except IOError:
return False
- for line in dns_file:
- line = line.strip()
- if line == '' or line[0] == "#":
- continue
- if line.lower() == str(d).lower():
- return True
+ with dns_file:
+ for line in dns_file:
+ line = line.strip()
+ if line == '' or line[0] == "#":
+ continue
+ if line.lower() == str(d).lower():
+ return True
return False
try:
rfile = open(opts.use_file, 'r+')
except IOError:
# Perhaps create it
- open(opts.use_file, 'w+')
+ open(opts.use_file, 'w+').close()
# Open it for reading again, in case someone else got to it first
rfile = open(opts.use_file, 'r+')
fcntl.lockf(rfile, fcntl.LOCK_EX)
(file_dir, file_name) = os.path.split(opts.use_file)
(tmp_fd, tmpfile) = tempfile.mkstemp(dir=file_dir, prefix=file_name, suffix="XXXXXX")
wfile = os.fdopen(tmp_fd, 'a')
- rfile.seek(0)
for line in rfile:
if op == "delete":
l = parse_dns_line(line, {})
wfile.write(line)
if op == "add":
wfile.write(str(d)+"\n")
+ rfile.close()
+ wfile.close()
os.rename(tmpfile, opts.use_file)
- fcntl.lockf(rfile, fcntl.LOCK_UN)
return
if opts.verbose:
cfile = open(dns_update_cache, 'r+')
except IOError:
# Perhaps create it
- open(dns_update_cache, 'w+')
+ open(dns_update_cache, 'w+').close()
# Open it for reading again, in case someone else got to it first
cfile = open(dns_update_cache, 'r+')
fcntl.lockf(cfile, fcntl.LOCK_EX)
cache_list.append(c)
cache_set.add(str(c))
+cfile.close()
+
site_specific_rec = []
# read each line, and check that the DNS name exists
dns_list.append(d)
dup_set.add(str(d))
+file.close()
+
# Perform automatic site coverage by default
auto_coverage = True
if opts.verbose:
print("Adding %s to %s" % (str(d), file_name))
wfile.write(str(d)+"\n")
- wfile.flush()
+ wfile.close()
os.rename(tmpfile, dns_update_cache)
-fcntl.lockf(cfile, fcntl.LOCK_UN)
# delete the ccache if we created it
if ccachename is not None: