Apply modernize transform libmodernize.fixes.fix_file.
This replaces use of file() with open() which is python 3 compatible, and also adds it to our python 3 support test suite.
This commit is contained in:
parent
9db342950e
commit
91d851c448
|
@ -10,7 +10,7 @@ def nagios_from_file(results_file):
|
||||||
This file is created by various nagios checking cron jobs such as
|
This file is created by various nagios checking cron jobs such as
|
||||||
check-rabbitmq-queues and check-rabbitmq-consumers"""
|
check-rabbitmq-queues and check-rabbitmq-consumers"""
|
||||||
|
|
||||||
data = file(results_file).read().strip()
|
data = open(results_file).read().strip()
|
||||||
pieces = data.split('|')
|
pieces = data.split('|')
|
||||||
|
|
||||||
if not len(pieces) == 4:
|
if not len(pieces) == 4:
|
||||||
|
|
|
@ -376,7 +376,7 @@ option does not affect login credentials.'''.replace("\n", " "))
|
||||||
|
|
||||||
config = SafeConfigParser()
|
config = SafeConfigParser()
|
||||||
try:
|
try:
|
||||||
with file(config_file, 'r') as f:
|
with open(config_file, 'r') as f:
|
||||||
config.readfp(f, config_file)
|
config.readfp(f, config_file)
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -9,7 +9,7 @@ ccache_data_encoded = sys.argv[3]
|
||||||
|
|
||||||
# Update the Kerberos ticket cache file
|
# Update the Kerberos ticket cache file
|
||||||
program_name = "zmirror-%s" % (short_user,)
|
program_name = "zmirror-%s" % (short_user,)
|
||||||
with file("/home/zulip/ccache/%s" % (program_name,), "w") as f:
|
with open("/home/zulip/ccache/%s" % (program_name,), "w") as f:
|
||||||
f.write(base64.b64decode(ccache_data_encoded))
|
f.write(base64.b64decode(ccache_data_encoded))
|
||||||
|
|
||||||
# Setup API key
|
# Setup API key
|
||||||
|
|
|
@ -191,7 +191,7 @@ def zephyr_bulk_subscribe(subs):
|
||||||
|
|
||||||
def update_subscriptions():
|
def update_subscriptions():
|
||||||
try:
|
try:
|
||||||
f = file(options.stream_file_path, "r")
|
f = open(options.stream_file_path, "r")
|
||||||
public_streams = simplejson.loads(f.read())
|
public_streams = simplejson.loads(f.read())
|
||||||
f.close()
|
f.close()
|
||||||
except:
|
except:
|
||||||
|
@ -287,7 +287,7 @@ def parse_zephyr_body(zephyr_data):
|
||||||
|
|
||||||
def parse_crypt_table(zephyr_class, instance):
|
def parse_crypt_table(zephyr_class, instance):
|
||||||
try:
|
try:
|
||||||
crypt_table = file(os.path.join(os.environ["HOME"], ".crypt-table"))
|
crypt_table = open(os.path.join(os.environ["HOME"], ".crypt-table"))
|
||||||
except IOError:
|
except IOError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ def process_notice(notice, log):
|
||||||
|
|
||||||
if zephyr_class == options.nagios_class:
|
if zephyr_class == options.nagios_class:
|
||||||
# Mark that we got the message and proceed
|
# Mark that we got the message and proceed
|
||||||
with file(options.nagios_path, "w") as f:
|
with open(options.nagios_path, "w") as f:
|
||||||
f.write("0\n")
|
f.write("0\n")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -468,7 +468,7 @@ def zephyr_load_session_autoretry(session_path):
|
||||||
backoff = zulip.RandomExponentialBackoff()
|
backoff = zulip.RandomExponentialBackoff()
|
||||||
while backoff.keep_going():
|
while backoff.keep_going():
|
||||||
try:
|
try:
|
||||||
session = file(session_path, "r").read()
|
session = open(session_path, "r").read()
|
||||||
zephyr._z.initialize()
|
zephyr._z.initialize()
|
||||||
zephyr._z.load_session(session)
|
zephyr._z.load_session(session)
|
||||||
zephyr.__inited = True
|
zephyr.__inited = True
|
||||||
|
@ -510,7 +510,7 @@ def zephyr_to_zulip(options):
|
||||||
if options.nagios_class:
|
if options.nagios_class:
|
||||||
zephyr_subscribe_autoretry((options.nagios_class, "*", "*"))
|
zephyr_subscribe_autoretry((options.nagios_class, "*", "*"))
|
||||||
if options.use_sessions:
|
if options.use_sessions:
|
||||||
file(options.session_path, "w").write(zephyr._z.dump_session())
|
open(options.session_path, "w").write(zephyr._z.dump_session())
|
||||||
|
|
||||||
if options.logs_to_resend is not None:
|
if options.logs_to_resend is not None:
|
||||||
with open(options.logs_to_resend, 'r') as log:
|
with open(options.logs_to_resend, 'r') as log:
|
||||||
|
@ -857,7 +857,7 @@ def parse_zephyr_subs(verbose=False):
|
||||||
logger.error("Couldn't find ~/.zephyr.subs!")
|
logger.error("Couldn't find ~/.zephyr.subs!")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
for line in file(subs_file, "r").readlines():
|
for line in open(subs_file, "r").readlines():
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if len(line) == 0:
|
if len(line) == 0:
|
||||||
continue
|
continue
|
||||||
|
@ -1050,7 +1050,7 @@ Could not find API key file.
|
||||||
You need to either place your api key file at %s,
|
You need to either place your api key file at %s,
|
||||||
or specify the --api-key-file option.""" % (options.api_key_file,))))
|
or specify the --api-key-file option.""" % (options.api_key_file,))))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
api_key = file(options.api_key_file).read().strip()
|
api_key = open(options.api_key_file).read().strip()
|
||||||
# Store the API key in the environment so that our children
|
# Store the API key in the environment so that our children
|
||||||
# don't need to read it in
|
# don't need to read it in
|
||||||
os.environ["HUMBUG_API_KEY"] = api_key
|
os.environ["HUMBUG_API_KEY"] = api_key
|
||||||
|
|
|
@ -164,7 +164,7 @@ class Client(object):
|
||||||
config_file = get_default_config_filename()
|
config_file = get_default_config_filename()
|
||||||
if os.path.exists(config_file):
|
if os.path.exists(config_file):
|
||||||
config = SafeConfigParser()
|
config = SafeConfigParser()
|
||||||
with file(config_file, 'r') as f:
|
with open(config_file, 'r') as f:
|
||||||
config.readfp(f, config_file)
|
config.readfp(f, config_file)
|
||||||
if api_key is None:
|
if api_key is None:
|
||||||
api_key = config.get("api", "key")
|
api_key = config.get("api", "key")
|
||||||
|
|
Loading…
Reference in a new issue