*: pylint: Explicitly specify encoding when open a file

This is recommended by PEP-0597: https://peps.python.org/pep-0597/

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2022-07-04 19:45:57 -04:00
1 parent 05815bc992
commit 3c7bc4a192
49 files changed
+165 -138

No files matched your search

+15 -11
View File
@@ -197,14 +197,14 @@ def subcommand_check_auto(_):
def subcommand_enable_auto(_):
"""Enable automatic upgrades"""
with open(AUTO_CONF_FILE, 'w') as conffile:
with open(AUTO_CONF_FILE, 'w', encoding='utf-8') as conffile:
conffile.write('APT::Periodic::Update-Package-Lists "1";\n')
conffile.write('APT::Periodic::Unattended-Upgrade "1";\n')
def subcommand_disable_auto(_):
"""Disable automatic upgrades"""
with open(AUTO_CONF_FILE, 'w') as conffile:
with open(AUTO_CONF_FILE, 'w', encoding='utf-8') as conffile:
conffile.write('APT::Periodic::Update-Package-Lists "0";\n')
conffile.write('APT::Periodic::Unattended-Upgrade "0";\n')
@@ -213,14 +213,14 @@ def subcommand_get_log(_):
"""Print the automatic upgrades log."""
try:
print('==> ' + os.path.basename(LOG_FILE))
with open(LOG_FILE, 'r') as file_handle:
with open(LOG_FILE, 'r', encoding='utf-8') as file_handle:
print(file_handle.read())
except IOError:
pass
try:
print('==> ' + os.path.basename(DPKG_LOG_FILE))
with open(DPKG_LOG_FILE, 'r') as file_handle:
with open(DPKG_LOG_FILE, 'r', encoding='utf-8') as file_handle:
print(file_handle.read())
except IOError:
pass
@@ -261,7 +261,7 @@ deb {protocol}://deb.debian.org/debian {dist}-backports main
deb-src {protocol}://deb.debian.org/debian {dist}-backports main
'''
sources = sources.format(protocol=protocol, dist=dist)
with open(sources_list, 'w') as file_handle:
with open(sources_list, 'w', encoding='utf-8') as file_handle:
file_handle.write(sources)
@@ -276,7 +276,8 @@ def _check_and_backports_sources(develop=False):
return
try:
with open('/etc/dpkg/origins/default', 'r') as default_origin:
with open('/etc/dpkg/origins/default', 'r',
encoding='utf-8') as default_origin:
matches = [
re.match(r'Vendor:\s+Debian', line, flags=re.IGNORECASE)
for line in default_origin.readlines()
@@ -326,9 +327,11 @@ def _add_apt_preferences():
'for backports.')
else:
print(f'Setting apt preferences for {dist}-backports.')
with open(base_path / '50freedombox4.pref', 'w') as file_handle:
with open(base_path / '50freedombox4.pref', 'w',
encoding='utf-8') as file_handle:
file_handle.write(APT_PREFERENCES_FREEDOMBOX.format(dist))
with open(base_path / '51freedombox-apps.pref', 'w') as file_handle:
with open(base_path / '51freedombox-apps.pref', 'w',
encoding='utf-8') as file_handle:
file_handle.write(APT_PREFERENCES_APPS)
@@ -394,10 +397,10 @@ def _check_dist_upgrade(test_upgrade=False) -> Tuple[bool, str]:
return (False, 'not-enough-free-space')
logging.info('Upgrading from %s to %s...', dist, codename)
with open(SOURCES_LIST, 'r') as sources_list:
with open(SOURCES_LIST, 'r', encoding='utf-8') as sources_list:
lines = sources_list.readlines()
with open(SOURCES_LIST, 'w') as sources_list:
with open(SOURCES_LIST, 'w', encoding='utf-8') as sources_list:
for line in lines:
# E.g. replace 'buster' with 'bullseye'.
new_line = line.replace(dist, codename)
@@ -571,7 +574,8 @@ def subcommand_activate_backports(arguments):
def _start_dist_upgrade_service():
"""Create dist upgrade service and start it."""
with open(DIST_UPGRADE_SERVICE_PATH, 'w') as service_file:
with open(DIST_UPGRADE_SERVICE_PATH, 'w',
encoding='utf-8') as service_file:
service_file.write(DIST_UPGRADE_SERVICE)
service_daemon_reload()