Skip to content
Permalink
Browse files

Python 3: replaced 'file' with 'open' (interim stage)

Change-Id: Ib22d93690b0d031079223a5e1d0624b50f016838
  • Loading branch information...
si-23 committed Sep 9, 2019
1 parent 6080cc6 commit 1b8d68d59903c021251857b3fac93adf4dd7ce86
Showing with 209 additions and 209 deletions.
  1. +1 −1 .pylintrc
  2. +1 −1 active_checks/check_mail
  3. +2 −2 active_checks/check_mail_loop
  4. +1 −1 agents/special/agent_appdynamics
  5. +1 −1 agents/special/agent_emcvnx
  6. +1 −1 agents/special/agent_ibmsvc
  7. +1 −1 agents/special/agent_random
  8. +1 −1 agents/special/agent_vsphere
  9. +1 −1 agents/special/agent_vsphere.pysphere
  10. +1 −1 agents/windows/it/test_agent_start_parameters.py
  11. +6 −6 agents/windows/msibuild/msi-update
  12. +6 −6 agents/windows/msibuild/msi-update-legacy
  13. +5 −5 bin/mkbackup
  14. +2 −2 bin/mkbench
  15. +2 −2 cmk/ec/main.py
  16. +1 −1 cmk/gui/background_job.py
  17. +3 −3 cmk/gui/backup.py
  18. +5 −5 cmk/gui/bi.py
  19. +1 −1 cmk/gui/cron.py
  20. +3 −3 cmk/gui/login.py
  21. +1 −1 cmk/gui/multitar.py
  22. +1 −1 cmk/gui/plugins/sidebar/wiki.py
  23. +2 −2 cmk/gui/plugins/userdb/hook_auth.py
  24. +3 −3 cmk/gui/plugins/userdb/ldap_connector.py
  25. +1 −1 cmk/gui/plugins/views/painters.py
  26. +1 −1 cmk/gui/plugins/wato/ac_tests.py
  27. +3 −3 cmk/gui/userdb.py
  28. +2 −2 cmk/gui/utils.py
  29. +1 −1 cmk/gui/wato/mkeventd.py
  30. +1 −1 cmk/gui/wato/pages/bulk_import.py
  31. +2 −2 cmk/gui/wato/pages/download_agents.py
  32. +2 −2 cmk/gui/watolib/config_domains.py
  33. +3 −3 cmk/gui/watolib/git.py
  34. +5 −5 cmk/gui/watolib/snapshots.py
  35. +2 −2 cmk/gui/watolib/tags.py
  36. +1 −1 cmk/gui/watolib/user_scripts.py
  37. +4 −4 cmk/utils/crash_reporting.py
  38. +1 −1 cmk/utils/prediction.py
  39. +1 −1 cmk/utils/profile.py
  40. +1 −1 cmk/utils/site.py
  41. +2 −2 cmk/utils/store.py
  42. +1 −1 cmk_base/agent_simulator.py
  43. +1 −1 cmk_base/autochecks.py
  44. +6 −6 cmk_base/automations/check_mk.py
  45. +1 −1 cmk_base/backup.py
  46. +2 −2 cmk_base/checking.py
  47. +2 −2 cmk_base/compress_history.py
  48. +1 −1 cmk_base/core.py
  49. +3 −3 cmk_base/core_nagios.py
  50. +4 −4 cmk_base/crash_reporting.py
  51. +1 −1 cmk_base/events.py
  52. +5 −5 cmk_base/localize.py
  53. +1 −1 cmk_base/modes/check_mk.py
  54. +3 −3 cmk_base/notify.py
  55. +2 −2 cmk_base/packaging.py
  56. +2 −2 cmk_base/parent_scan.py
  57. +1 −1 cmk_base/piggyback.py
  58. +2 −2 cmk_base/snmp.py
  59. +2 −2 doc/treasures/Event_Console/nsca2mkeventd/nsca2mkeventd
  60. +2 −2 doc/treasures/livedump/livedump-mail-fetch
  61. +2 −2 doc/treasures/livedump/livedump-ssh-recv
  62. +2 −2 doc/treasures/localchecks/check_fstab_mounts
  63. +2 −2 doc/treasures/migrate_oldcmk2wato.py
  64. +1 −1 doc/treasures/mod_contacts_mk.py
  65. +1 −1 doc/treasures/wato_host_svc_groups.py
  66. +1 −1 doc/treasures/wato_remove_nonsite_folders.py
  67. +1 −1 inventory/export_software_csv
  68. +1 −1 omd/packages/maintenance/merge-crontabs
  69. +24 −24 omd/packages/omd/omdlib/main.py
  70. +10 −10 scripts/autodetect.py
  71. +1 −1 scripts/create-changelog.py
  72. +1 −1 tests/crawl-stats
  73. +3 −3 tests/integration/cmk/gui/test_crawl.py
  74. +4 −4 tests/integration/cmk/gui/test_webapi.py
  75. +3 −3 tests/integration/cmk_base/test_automations.py
  76. +1 −1 tests/integration/cmk_base/test_data_sources.py
  77. +4 −4 tests/integration/cmk_base/test_modes.py
  78. +2 −2 tests/integration/cmk_base/test_services_prediction.py
  79. +1 −1 tests/pylint/test_pylint.py
  80. +3 −3 tests/testlib/__init__.py
  81. +3 −3 tests/testlib/pylint_cmk.py
  82. +2 −2 tests/unit/cmk/utils/test_store.py
  83. +9 −9 werk
@@ -22,7 +22,7 @@ jobs=0
# TODO: Why do we need persistence?
persistent=yes
extension-pkg-whitelist=rrdtool,_ldap,netifaces,pymssql
bad-functions=cmp,apply,execfile,reduce,reload
bad-functions=file,cmp,apply,execfile,reduce,reload

[MESSAGES CONTROL]
disable=
@@ -423,7 +423,7 @@ def forward_to_ec(mails):
file_name = '.%s_%d_%d' % (forward_host, os.getpid(), time.time())
if not os.path.exists(spool_path):
os.makedirs(spool_path)
file('%s/%s' % (spool_path, file_name), 'w').write('\n'.join(messages) + '\n')
open('%s/%s' % (spool_path, file_name), 'w').write('\n'.join(messages) + '\n')
os.rename('%s/%s' % (spool_path, file_name), '%s/%s' % (spool_path, file_name[1:]))

if cleanup_messages:
@@ -260,7 +260,7 @@ g_M = None

def load_expected_mails():
try:
for line in file(status_path):
for line in open(status_path):
ts, key = line.rstrip().split(' ', 1)
g_expected[ts + '-' + key] = (int(ts), int(key))
except IOError:
@@ -275,7 +275,7 @@ def save_expected_mails():
lines = []
for ts, key in g_expected.values():
lines.append('%d %s' % (ts, key))
file(status_path, 'w').write('\n'.join(lines) + '\n')
open(status_path, 'w').write('\n'.join(lines) + '\n')


def add_starttls_support(self, keyfile=None, certfile=None):
@@ -114,7 +114,7 @@ else:

if opt_filename:
try:
data = json.loads(file(opt_filename).read())
data = json.loads(open(opt_filename).read())
except Exception as e:
sys.stderr.write("Cannot read JSON data from file %s: %s\n" % (opt_filename, e))
if opt_debug:
@@ -266,7 +266,7 @@ for module, module_options in naviseccli_options.items():
def output_profile():
g_profile.dump_stats(g_profile_path)
show_profile = os.path.join(os.path.dirname(g_profile_path), 'show_profile.py')
file(show_profile, "w")\
open(show_profile, "w")\
.write("#!/usr/bin/python\n"
"import pstats\n"
"stats = pstats.Stats('%s')\n"
@@ -256,7 +256,7 @@ for line in lines:
def output_profile():
g_profile.dump_stats(g_profile_path)
show_profile = os.path.join(os.path.dirname(g_profile_path), 'show_profile.py')
file(show_profile, "w")\
open(show_profile, "w")\
.write("#!/usr/bin/python\n"
"import pstats\n"
"stats = pstats.Stats('%s')\n"
@@ -45,7 +45,7 @@ if not os.path.exists(state_dir):
os.makedirs(state_dir)
state_file = state_dir + hostname
try:
history = ast.literal_eval(file(state_file).read())
history = ast.literal_eval(open(state_file).read())
except (OSError, SyntaxError, IOError):
history = {}

@@ -1112,7 +1112,7 @@ def main(argv=None):
if opt.tracefile:
tracefile_dir = os.path.dirname(opt.tracefile) or "."
if os.path.exists(tracefile_dir):
opt.tracefile = file(opt.tracefile, "w")
opt.tracefile = open(opt.tracefile, "w")
elif opt.debug:
sys.stderr.write("Path for tracefile %s does not exist" % opt.tracefile)
sys.stderr.flush()
@@ -279,7 +279,7 @@ def convert_hostname(h):
def output_profile():
g_profile.dump_stats(g_profile_path)
show_profile = os.path.join(os.path.dirname(g_profile_path), 'show_profile.py')
file(show_profile, "w")\
open(show_profile, "w")\
.write("#!/usr/bin/python\n"
"import pstats\n"
"stats = pstats.Stats('%s')\n"
@@ -144,7 +144,7 @@ def pack(install_basedir):

def _cap_entry(relpath):
entry = chr(len(relpath)) + relpath
content = file(relpath).read()
content = open(relpath).read()
entry += _cap_filesize(len(content)) + content
return entry

@@ -217,8 +217,8 @@ try:
shutil.copy(source_dir + "/plugins.cap", source_dir + "/plugins_cap")
# checkmk.dat is the same, no need to copy

lines_file_idt = file(work_dir + "/File.idt").readlines()
file_idt_new = file(work_dir + "/File.idt.new", "w")
lines_file_idt = open(work_dir + "/File.idt").readlines()
file_idt_new = open(work_dir + "/File.idt.new", "w")
file_idt_new.write("".join(lines_file_idt[:3]))

cabinet_files = []
@@ -240,8 +240,8 @@ try:

# ==============================================
# Modify Component.idt
lines_component_idt = file(work_dir + "/Component.idt").readlines()
component_idt_new = file(work_dir + "/Component.idt.new", "w")
lines_component_idt = open(work_dir + "/Component.idt").readlines()
component_idt_new = open(work_dir + "/Component.idt.new", "w")
component_idt_new.write("".join(lines_component_idt[:3]))

for line in lines_component_idt[3:]:
@@ -257,8 +257,8 @@ try:
# ==============================================
# Modify Property.idt
product_code = ("{%s}\r\n" % uuid.uuid1()).upper()
lines_property_idt = file(work_dir + "/Property.idt").readlines()
property_idt_new = file(work_dir + "/Property.idt.new", "w")
lines_property_idt = open(work_dir + "/Property.idt").readlines()
property_idt_new = open(work_dir + "/Property.idt.new", "w")
property_idt_new.write("".join(lines_property_idt[:3]))

for line in lines_property_idt[3:]:
@@ -128,8 +128,8 @@ try:
# HACK: the 64 bit agent is msi internally handled as check_mk_agent64.exe
os.rename(source_dir + "/check_mk_agent-64.exe", source_dir + "/check_mk_agent64.exe")

lines_file_idt = file(work_dir + "/File.idt").readlines()
file_idt_new = file(work_dir + "/File.idt.new", "w")
lines_file_idt = open(work_dir + "/File.idt").readlines()
file_idt_new = open(work_dir + "/File.idt.new", "w")
file_idt_new.write("".join(lines_file_idt[:3]))

cabinet_files = []
@@ -149,8 +149,8 @@ try:

# ==============================================
# Modify Component.idt
lines_component_idt = file(work_dir + "/Component.idt").readlines()
component_idt_new = file(work_dir + "/Component.idt.new", "w")
lines_component_idt = open(work_dir + "/Component.idt").readlines()
component_idt_new = open(work_dir + "/Component.idt.new", "w")
component_idt_new.write("".join(lines_component_idt[:3]))

for line in lines_component_idt[3:]:
@@ -168,8 +168,8 @@ try:
# ==============================================
# Modify Property.idt
product_code = ("{%s}\r\n" % uuid.uuid1()).upper()
lines_property_idt = file(work_dir + "/Property.idt").readlines()
property_idt_new = file(work_dir + "/Property.idt.new", "w")
lines_property_idt = open(work_dir + "/Property.idt").readlines()
property_idt_new = open(work_dir + "/Property.idt.new", "w")
property_idt_new.write("".join(lines_property_idt[:3]))

for line in lines_property_idt[3:]:
@@ -169,7 +169,7 @@ def acquire_backup_lock():
except (IOError, OSError) as e:
raise MKGeneralException("Failed to open lock file \"%s\": %s" % (lock_file_path, e))
else:
g_backup_lock_f = file(lock_file_path, "a")
g_backup_lock_f = open(lock_file_path, "a")

try:
fcntl.flock(g_backup_lock_f, fcntl.LOCK_EX | fcntl.LOCK_NB)
@@ -260,7 +260,7 @@ def makedir(path, user=None, group=None, mode=None):
# - Site-Konfiguration laden
def load_config():
def load_file(path):
return ast.literal_eval(file(path).read())
return ast.literal_eval(open(path).read())

if is_root():
config = load_file(system_config_path())
@@ -285,7 +285,7 @@ def load_config():

# TODO: Duplicate code with htdocs/backup.py
def load_backup_info(path):
info = json.load(file(path))
info = json.load(open(path))

# Load the backup_id from the second right path component. This is the
# base directory of the mkbackup.info file. The user might have moved
@@ -1167,7 +1167,7 @@ def do_system_rw_backup(opts):


def do_system_data_backup(opts):
with file(system_data_backup_archive_path(), "w") as backup_file:
with open(system_data_backup_archive_path(), "w") as backup_file:
pipein_fd, pipeout_fd = os.pipe()
pipein = os.fdopen(pipein_fd)

@@ -1346,7 +1346,7 @@ g_state = None
def load_state():
global g_state
if g_state is None:
g_state = json.load(file(state_path()))
g_state = json.load(open(state_path()))

return g_state

@@ -1053,7 +1053,7 @@ class Measurement(object):

def _get_site_state(self):
self.site_state = subprocess.call(["omd", "status", "--bare"],
stdout=file(os.devnull, "w"),
stdout=open(os.devnull, "w"),
close_fds=True)

def _get_site_stats(self):
@@ -3267,7 +3267,7 @@ def verify_is_site():

def verify_site_is_running():
site_state = subprocess.call(["omd", "status", "--bare"],
stdout=file(os.devnull, "w"),
stdout=open(os.devnull, "w"),
close_fds=True)
if site_state != 0:
raise MKGeneralException("Site needs to be running")
@@ -775,7 +775,7 @@ def _add_general_status(self):
]

def _virtual_memory_size(self):
parts = file('/proc/self/stat').read().split()
parts = open('/proc/self/stat').read().split()
return int(parts[22]) # in Bytes

def _add_replication_status(self):
@@ -3189,7 +3189,7 @@ def handle_command_create(self, arguments):
# self._event_status.lock too. The lock can not be allocated twice.
# TODO: Change the lock type in future?
# process_raw_lines("%s" % ";".join(arguments))
with file(str(self.settings.paths.event_pipe.value), "w") as pipe:
with open(str(self.settings.paths.event_pipe.value), "w") as pipe:
pipe.write(("%s\n" % ";".join(arguments)).encode("utf-8"))

def handle_command_changestate(self, arguments):
@@ -540,7 +540,7 @@ def get_status_from_file(self):
("JobResult", self._result_message_path),
("JobException", self._exceptions_path)]:
if field_path.exists(): # pylint: disable=no-member
data["loginfo"][field_id] = file(str(field_path)).read().splitlines()
data["loginfo"][field_id] = open(str(field_path)).read().splitlines()
else:
data["loginfo"][field_id] = []

@@ -236,7 +236,7 @@ def cleanup(self):

def state(self):
try:
state = json.load(file(self.state_file_path()))
state = json.load(open(self.state_file_path()))
except IOError as e:
if e.errno == errno.ENOENT: # not existant
state = {
@@ -1306,7 +1306,7 @@ def validate_local_directory(cls, value, varprefix):
# Check write access for the site user
try:
test_file_path = os.path.join(value, "write_test_%d" % time.time())
file(test_file_path, "w")
open(test_file_path, "w")
os.unlink(test_file_path)
except IOError:
if is_cma():
@@ -1347,7 +1347,7 @@ def verify_target_is_ready(self):

# TODO: Duplicate code with mkbackup
def _load_backup_info(self, path):
info = json.load(file(path))
info = json.load(open(path))

# Load the backup_id from the second right path component. This is the
# base directory of the mkbackup.info file. The user might have moved
@@ -553,7 +553,7 @@ def has_lock(self):

def __enter__(self):
if not os.path.exists(self._filepath):
file(self._filepath, "a+")
open(self._filepath, "a+")

lock_options = fcntl.LOCK_SH if self._shared else fcntl.LOCK_EX
lock_options = lock_options if self._blocking else (lock_options | fcntl.LOCK_NB)
@@ -591,13 +591,13 @@ def __exit__(self, exception_type, exception_value, tb):


def marshal_save_data(filepath, data):
with file(filepath, "w") as the_file:
with open(filepath, "w") as the_file:
marshal.dump(data, the_file)
os.fsync(the_file.fileno())


def marshal_load_data(filepath):
return marshal.load(file(filepath))
return marshal.load(open(filepath))


# This class allows you to load and save python data
@@ -616,7 +616,7 @@ def __init__(self, **kwargs):
self._filetime = None

try:
file(self._filepath, "a")
open(self._filepath, "a")
except IOError:
pass

@@ -672,7 +672,7 @@ def save(self, data):
def truncate(self):
log("Truncate %s" % self._filepath)
with BILock(self._filepath):
file(self._filepath, "w")
open(self._filepath, "w")
self._cached_data = None
self._filetime = os.stat(self._filepath).st_mtime

@@ -73,7 +73,7 @@ def page_run_cron():
last_run = os.stat(lock_file).st_mtime
if time.time() - last_run < 59:
raise MKGeneralException("Cron called too early. Skipping.")
file(lock_file, "w") # touches the file
open(lock_file, "w") # touches the file
store.aquire_lock(lock_file)

# The cron page is accessed unauthenticated. After leaving the page_run_cron area
@@ -98,7 +98,7 @@ def load_secret():
secret_path = '%s/auth.secret' % os.path.dirname(cmk.utils.paths.htpasswd_file)
secret = ''
if os.path.exists(secret_path):
secret = file(secret_path).read().strip()
secret = open(secret_path).read().strip()

# Create new secret when this installation has no secret
#
@@ -108,7 +108,7 @@ def load_secret():
# renew their login after update.
if secret == '' or len(secret) == 32:
secret = generate_secret()
file(secret_path, 'w').write(secret)
open(secret_path, 'w').write(secret)

return secret

@@ -310,7 +310,7 @@ def check_auth_automation():
html.request.del_var('_secret')
if secret and user_id and "/" not in user_id:
path = cmk.utils.paths.var_dir + "/web/" + user_id.encode("utf-8") + "/automation.secret"
if os.path.isfile(path) and file(path).read().strip() == secret:
if os.path.isfile(path) and open(path).read().strip() == secret:
# Auth with automation secret succeeded - mark transid as unneeded in this case
html.transaction_manager.ignore()
set_auth_type("automation")
@@ -278,7 +278,7 @@ def is_supported(component):
"Unsupported custom snapshot component: %s.") % str(component))

# Simply compute the checksum of the sitespecific.mk
return hashlib.md5(file(
return hashlib.md5(open(
parsed_custom_components.components[0].configured_path).read()).hexdigest()


@@ -83,7 +83,7 @@ def show(self):
ul_started = False
try:
title = None
for line in file(filename).readlines():
for line in open(filename).readlines():
line = line.strip()
if line == "":
if ul_started:
@@ -107,12 +107,12 @@ def create_php_file(callee, users, role_permissions, groups):
# files into php.
tempfile = g_auth_base_dir + '/auth.php.tmp'
lockfile = g_auth_base_dir + '/auth.php.state'
file(lockfile, "a")
open(lockfile, "a")
store.aquire_lock(lockfile)

# First write a temp file and then do a move to prevent syntax errors
# when reading half written files during creating that new file
file(tempfile, 'w').write('''<?php
open(tempfile, 'w').write('''<?php
// Created by Multisite UserDB Hook (%s)
global $mk_users, $mk_roles, $mk_groups;
$mk_users = %s;

0 comments on commit 1b8d68d

Please sign in to comment.
You can’t perform that action at this time.