Run pyupgrade against the files changed on the merge forward

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2023-07-08 21:32:10 +01:00
parent 7d6f51f871
commit 261e3e825d
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF
2 changed files with 46 additions and 56 deletions

View file

@ -490,14 +490,14 @@ def _get_reg_software(include_components=True, include_updates=True):
return False return False
if __utils__["reg.value_exists"]( if __utils__["reg.value_exists"](
hive=hive, hive=hive,
key="{}\\{}".format(key, sub_key), key=f"{key}\\{sub_key}",
vname="SystemComponent", vname="SystemComponent",
use_32bit_registry=use_32bit_registry, use_32bit_registry=use_32bit_registry,
): ):
if ( if (
__utils__["reg.read_value"]( __utils__["reg.read_value"](
hive=hive, hive=hive,
key="{}\\{}".format(key, sub_key), key=f"{key}\\{sub_key}",
vname="SystemComponent", vname="SystemComponent",
use_32bit_registry=use_32bit_registry, use_32bit_registry=use_32bit_registry,
)["vdata"] )["vdata"]
@ -519,14 +519,14 @@ def _get_reg_software(include_components=True, include_updates=True):
products_key = "Software\\Classes\\Installer\\Products\\{0}" products_key = "Software\\Classes\\Installer\\Products\\{0}"
if __utils__["reg.value_exists"]( if __utils__["reg.value_exists"](
hive=hive, hive=hive,
key="{}\\{}".format(key, sub_key), key=f"{key}\\{sub_key}",
vname="WindowsInstaller", vname="WindowsInstaller",
use_32bit_registry=use_32bit_registry, use_32bit_registry=use_32bit_registry,
): ):
if ( if (
__utils__["reg.read_value"]( __utils__["reg.read_value"](
hive=hive, hive=hive,
key="{}\\{}".format(key, sub_key), key=f"{key}\\{sub_key}",
vname="WindowsInstaller", vname="WindowsInstaller",
use_32bit_registry=use_32bit_registry, use_32bit_registry=use_32bit_registry,
)["vdata"] )["vdata"]
@ -557,14 +557,14 @@ def _get_reg_software(include_components=True, include_updates=True):
# https://docs.microsoft.com/en-us/windows/win32/msi/arpnoremove # https://docs.microsoft.com/en-us/windows/win32/msi/arpnoremove
if __utils__["reg.value_exists"]( if __utils__["reg.value_exists"](
hive=hive, hive=hive,
key="{}\\{}".format(key, sub_key), key=f"{key}\\{sub_key}",
vname="NoRemove", vname="NoRemove",
use_32bit_registry=use_32bit_registry, use_32bit_registry=use_32bit_registry,
): ):
if ( if (
__utils__["reg.read_value"]( __utils__["reg.read_value"](
hive=hive, hive=hive,
key="{}\\{}".format(key, sub_key), key=f"{key}\\{sub_key}",
vname="NoRemove", vname="NoRemove",
use_32bit_registry=use_32bit_registry, use_32bit_registry=use_32bit_registry,
)["vdata"] )["vdata"]
@ -573,7 +573,7 @@ def _get_reg_software(include_components=True, include_updates=True):
return False return False
if not __utils__["reg.value_exists"]( if not __utils__["reg.value_exists"](
hive=hive, hive=hive,
key="{}\\{}".format(key, sub_key), key=f"{key}\\{sub_key}",
vname="UninstallString", vname="UninstallString",
use_32bit_registry=use_32bit_registry, use_32bit_registry=use_32bit_registry,
): ):
@ -594,14 +594,14 @@ def _get_reg_software(include_components=True, include_updates=True):
skip_types = ["Hotfix", "Security Update", "Update Rollup"] skip_types = ["Hotfix", "Security Update", "Update Rollup"]
if __utils__["reg.value_exists"]( if __utils__["reg.value_exists"](
hive=hive, hive=hive,
key="{}\\{}".format(key, sub_key), key=f"{key}\\{sub_key}",
vname="ReleaseType", vname="ReleaseType",
use_32bit_registry=use_32bit_registry, use_32bit_registry=use_32bit_registry,
): ):
if ( if (
__utils__["reg.read_value"]( __utils__["reg.read_value"](
hive=hive, hive=hive,
key="{}\\{}".format(key, sub_key), key=f"{key}\\{sub_key}",
vname="ReleaseType", vname="ReleaseType",
use_32bit_registry=use_32bit_registry, use_32bit_registry=use_32bit_registry,
)["vdata"] )["vdata"]
@ -620,7 +620,7 @@ def _get_reg_software(include_components=True, include_updates=True):
""" """
if __utils__["reg.value_exists"]( if __utils__["reg.value_exists"](
hive=hive, hive=hive,
key="{}\\{}".format(key, sub_key), key=f"{key}\\{sub_key}",
vname="ParentKeyName", vname="ParentKeyName",
use_32bit_registry=use_32bit_registry, use_32bit_registry=use_32bit_registry,
): ):
@ -637,7 +637,7 @@ def _get_reg_software(include_components=True, include_updates=True):
""" """
d_name_regdata = __utils__["reg.read_value"]( d_name_regdata = __utils__["reg.read_value"](
hive=hive, hive=hive,
key="{}\\{}".format(key, sub_key), key=f"{key}\\{sub_key}",
vname="DisplayName", vname="DisplayName",
use_32bit_registry=use_32bit_registry, use_32bit_registry=use_32bit_registry,
) )
@ -656,7 +656,7 @@ def _get_reg_software(include_components=True, include_updates=True):
d_vers_regdata = __utils__["reg.read_value"]( d_vers_regdata = __utils__["reg.read_value"](
hive=hive, hive=hive,
key="{}\\{}".format(key, sub_key), key=f"{key}\\{sub_key}",
vname="DisplayVersion", vname="DisplayVersion",
use_32bit_registry=use_32bit_registry, use_32bit_registry=use_32bit_registry,
) )
@ -727,7 +727,7 @@ def _get_reg_software(include_components=True, include_updates=True):
for sub_key in __utils__["reg.list_keys"](**kwargs): for sub_key in __utils__["reg.list_keys"](**kwargs):
# If the key does not exist in userdata, skip it # If the key does not exist in userdata, skip it
if not __utils__["reg.key_exists"]( if not __utils__["reg.key_exists"](
hive=kwargs["hive"], key="{}\\{}".format(userdata_key, sub_key) hive=kwargs["hive"], key=f"{userdata_key}\\{sub_key}"
): ):
continue continue
kwargs["sub_key"] = sub_key kwargs["sub_key"] = sub_key
@ -1041,7 +1041,7 @@ def _get_repo_details(saltenv):
""" """
Return repo details for the specified saltenv as a namedtuple Return repo details for the specified saltenv as a namedtuple
""" """
contextkey = "winrepo._get_repo_details.{}".format(saltenv) contextkey = f"winrepo._get_repo_details.{saltenv}"
if contextkey in __context__: if contextkey in __context__:
(winrepo_source_dir, local_dest, winrepo_file) = __context__[contextkey] (winrepo_source_dir, local_dest, winrepo_file) = __context__[contextkey]
@ -1086,9 +1086,7 @@ def _get_repo_details(saltenv):
os.makedirs(local_dest) os.makedirs(local_dest)
except OSError as exc: except OSError as exc:
if exc.errno != errno.EEXIST: if exc.errno != errno.EEXIST:
raise CommandExecutionError( raise CommandExecutionError(f"Failed to create {local_dest}: {exc}")
"Failed to create {}: {}".format(local_dest, exc)
)
winrepo_age = -1 winrepo_age = -1
try: try:
@ -1097,9 +1095,7 @@ def _get_repo_details(saltenv):
winrepo_age = time.time() - mtime winrepo_age = time.time() - mtime
except OSError as exc: except OSError as exc:
if exc.errno != errno.ENOENT: if exc.errno != errno.ENOENT:
raise CommandExecutionError( raise CommandExecutionError(f"Failed to get age of {winrepo_file}: {exc}")
"Failed to get age of {}: {}".format(winrepo_file, exc)
)
except AttributeError: except AttributeError:
# Shouldn't happen but log if it does # Shouldn't happen but log if it does
log.warning("st_mtime missing from stat result %s", stat_result) log.warning("st_mtime missing from stat result %s", stat_result)
@ -1222,9 +1218,7 @@ def _repo_process_pkg_sls(filename, short_path_name, ret, successful_verbose):
def _failed_compile(prefix_msg, error_msg): def _failed_compile(prefix_msg, error_msg):
log.error("%s '%s': %s", prefix_msg, short_path_name, error_msg) log.error("%s '%s': %s", prefix_msg, short_path_name, error_msg)
ret.setdefault("errors", {})[short_path_name] = [ ret.setdefault("errors", {})[short_path_name] = [f"{prefix_msg}, {error_msg} "]
"{}, {} ".format(prefix_msg, error_msg)
]
return False return False
try: try:
@ -1250,7 +1244,7 @@ def _repo_process_pkg_sls(filename, short_path_name, ret, successful_verbose):
pkgname, pkgname,
short_path_name, short_path_name,
) )
errors.append("package '{}' already defined".format(pkgname)) errors.append(f"package '{pkgname}' already defined")
break break
for version_str, repodata in version_list.items(): for version_str, repodata in version_list.items():
# Ensure version is a string/unicode # Ensure version is a string/unicode
@ -1322,9 +1316,7 @@ def _get_source_sum(source_hash, file_path, saltenv, verify_ssl=True):
raise raise
if not cached_hash_file: if not cached_hash_file:
raise CommandExecutionError( raise CommandExecutionError(f"Source hash file {source_hash} not found")
"Source hash file {} not found".format(source_hash)
)
ret = __salt__["file.extract_hash"](cached_hash_file, "", file_path) ret = __salt__["file.extract_hash"](cached_hash_file, "", file_path)
if ret is None: if ret is None:
@ -1582,7 +1574,7 @@ def install(name=None, refresh=False, pkgs=None, **kwargs):
# Make sure pkginfo was found # Make sure pkginfo was found
if not pkginfo: if not pkginfo:
log.error("Unable to locate package %s", pkg_name) log.error("Unable to locate package %s", pkg_name)
ret[pkg_name] = "Unable to locate package {}".format(pkg_name) ret[pkg_name] = f"Unable to locate package {pkg_name}"
continue continue
version_num = options.get("version") version_num = options.get("version")
@ -1666,9 +1658,9 @@ def install(name=None, refresh=False, pkgs=None, **kwargs):
exclude_pat="E@init.sls$", exclude_pat="E@init.sls$",
) )
except MinionError as exc: except MinionError as exc:
msg = "Failed to cache {}".format(path) msg = f"Failed to cache {path}"
log.exception(msg, exc_info=exc) log.exception(msg, exc_info=exc)
return "{}\n{}".format(msg, exc) return f"{msg}\n{exc}"
# Check to see if the cache_file is cached... if passed # Check to see if the cache_file is cached... if passed
if cache_file and cache_file.startswith("salt:"): if cache_file and cache_file.startswith("salt:"):
@ -1682,9 +1674,9 @@ def install(name=None, refresh=False, pkgs=None, **kwargs):
verify_ssl=kwargs.get("verify_ssl", True), verify_ssl=kwargs.get("verify_ssl", True),
) )
except MinionError as exc: except MinionError as exc:
msg = "Failed to cache {}".format(cache_file) msg = f"Failed to cache {cache_file}"
log.exception(msg, exc_info=exc) log.exception(msg, exc_info=exc)
return "{}\n{}".format(msg, exc) return f"{msg}\n{exc}"
# Check if the cache_file was cached successfully # Check if the cache_file was cached successfully
if not cached_file: if not cached_file:
@ -1713,9 +1705,9 @@ def install(name=None, refresh=False, pkgs=None, **kwargs):
use_etag=True, use_etag=True,
) )
except MinionError as exc: except MinionError as exc:
msg = "Failed to cache {}".format(installer) msg = f"Failed to cache {installer}"
log.exception(msg, exc_info=exc) log.exception(msg, exc_info=exc)
return "{}\n{}".format(msg, exc) return f"{msg}\n{exc}"
# Check if the installer was cached successfully # Check if the installer was cached successfully
if not cached_pkg: if not cached_pkg:
@ -1780,14 +1772,14 @@ def install(name=None, refresh=False, pkgs=None, **kwargs):
"ComSpec", "{}\\system32\\cmd.exe".format(os.getenv("WINDIR")) "ComSpec", "{}\\system32\\cmd.exe".format(os.getenv("WINDIR"))
) )
if use_msiexec: if use_msiexec:
arguments = '"{}" /I "{}"'.format(msiexec, cached_pkg) arguments = f'"{msiexec}" /I "{cached_pkg}"'
if pkginfo[version_num].get("allusers", True): if pkginfo[version_num].get("allusers", True):
arguments = "{} ALLUSERS=1".format(arguments) arguments = f"{arguments} ALLUSERS=1"
else: else:
arguments = '"{}"'.format(cached_pkg) arguments = f'"{cached_pkg}"'
if install_flags: if install_flags:
arguments = "{} {}".format(arguments, install_flags) arguments = f"{arguments} {install_flags}"
# Install the software # Install the software
# Check Use Scheduler Option # Check Use Scheduler Option
@ -1801,7 +1793,7 @@ def install(name=None, refresh=False, pkgs=None, **kwargs):
force=True, force=True,
action_type="Execute", action_type="Execute",
cmd=cmd_shell, cmd=cmd_shell,
arguments='/c "{}"'.format(arguments), arguments=f'/c "{arguments}"',
start_in=cache_path, start_in=cache_path,
trigger_type="Once", trigger_type="Once",
start_date="1975-01-01", start_date="1975-01-01",
@ -1853,7 +1845,7 @@ def install(name=None, refresh=False, pkgs=None, **kwargs):
else: else:
# Launch the command # Launch the command
result = __salt__["cmd.run_all"]( result = __salt__["cmd.run_all"](
'"{}" /c "{}"'.format(cmd_shell, arguments), f'"{cmd_shell}" /c "{arguments}"',
cache_path, cache_path,
output_loglevel="trace", output_loglevel="trace",
python_shell=False, python_shell=False,
@ -2006,7 +1998,7 @@ def remove(name=None, pkgs=None, **kwargs):
# Make sure pkginfo was found # Make sure pkginfo was found
if not pkginfo: if not pkginfo:
msg = "Unable to locate package {}".format(pkgname) msg = f"Unable to locate package {pkgname}"
log.error(msg) log.error(msg)
ret[pkgname] = msg ret[pkgname] = msg
continue continue
@ -2046,7 +2038,7 @@ def remove(name=None, pkgs=None, **kwargs):
removal_targets.append(version_num) removal_targets.append(version_num)
else: else:
log.debug("%s %s not installed", pkgname, version_num) log.debug("%s %s not installed", pkgname, version_num)
ret[pkgname] = {"current": "{} not installed".format(version_num)} ret[pkgname] = {"current": f"{version_num} not installed"}
continue continue
elif "latest" in pkginfo: elif "latest" in pkginfo:
# we do not have version entry, assume software can self upgrade and use latest # we do not have version entry, assume software can self upgrade and use latest
@ -2061,9 +2053,7 @@ def remove(name=None, pkgs=None, **kwargs):
log.error( log.error(
"%s %s no definition to remove this version", pkgname, version_num "%s %s no definition to remove this version", pkgname, version_num
) )
ret[pkgname] = { ret[pkgname] = {"current": f"{version_num} no definition, cannot removed"}
"current": "{} no definition, cannot removed".format(version_num)
}
continue continue
for target in removal_targets: for target in removal_targets:
@ -2112,9 +2102,9 @@ def remove(name=None, pkgs=None, **kwargs):
exclude_pat="E@init.sls$", exclude_pat="E@init.sls$",
) )
except MinionError as exc: except MinionError as exc:
msg = "Failed to cache {}".format(path) msg = f"Failed to cache {path}"
log.exception(msg, exc_info=exc) log.exception(msg, exc_info=exc)
return "{}\n{}".format(msg, exc) return f"{msg}\n{exc}"
# Check to see if the uninstaller is cached. We don't want to # Check to see if the uninstaller is cached. We don't want to
# check for latest here like we do for "pkg.install" because we # check for latest here like we do for "pkg.install" because we
@ -2136,9 +2126,9 @@ def remove(name=None, pkgs=None, **kwargs):
use_etag=True, use_etag=True,
) )
except MinionError as exc: except MinionError as exc:
msg = "Failed to cache {}".format(uninstaller) msg = f"Failed to cache {uninstaller}"
log.exception(msg, exc_info=exc) log.exception(msg, exc_info=exc)
return "{}\n{}".format(msg, exc) return f"{msg}\n{exc}"
# Check if the uninstaller was cached successfully # Check if the uninstaller was cached successfully
if not cached_pkg: if not cached_pkg:
@ -2172,12 +2162,12 @@ def remove(name=None, pkgs=None, **kwargs):
if use_msiexec: if use_msiexec:
# Check if uninstaller is set to {guid}, if not we assume its a remote msi file. # Check if uninstaller is set to {guid}, if not we assume its a remote msi file.
# which has already been downloaded. # which has already been downloaded.
arguments = '"{}" /X "{}"'.format(msiexec, cached_pkg) arguments = f'"{msiexec}" /X "{cached_pkg}"'
else: else:
arguments = '"{}"'.format(cached_pkg) arguments = f'"{cached_pkg}"'
if uninstall_flags: if uninstall_flags:
arguments = "{} {}".format(arguments, uninstall_flags) arguments = f"{arguments} {uninstall_flags}"
# Uninstall the software # Uninstall the software
changed.append(pkgname) changed.append(pkgname)
@ -2192,7 +2182,7 @@ def remove(name=None, pkgs=None, **kwargs):
force=True, force=True,
action_type="Execute", action_type="Execute",
cmd=cmd_shell, cmd=cmd_shell,
arguments='/c "{}"'.format(arguments), arguments=f'/c "{arguments}"',
start_in=cache_path, start_in=cache_path,
trigger_type="Once", trigger_type="Once",
start_date="1975-01-01", start_date="1975-01-01",
@ -2209,7 +2199,7 @@ def remove(name=None, pkgs=None, **kwargs):
else: else:
# Launch the command # Launch the command
result = __salt__["cmd.run_all"]( result = __salt__["cmd.run_all"](
'"{}" /c "{}"'.format(cmd_shell, arguments), f'"{cmd_shell}" /c "{arguments}"',
output_loglevel="trace", output_loglevel="trace",
python_shell=False, python_shell=False,
redirect_stderr=True, redirect_stderr=True,

View file

@ -92,7 +92,7 @@ def test_pkg__get_reg_software():
def test_pkg__get_reg_software_noremove(): def test_pkg__get_reg_software_noremove():
search = "test_pkg_noremove" search = "test_pkg_noremove"
key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{}".format(search) key = f"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{search}"
win_reg.set_value(hive="HKLM", key=key, vname="DisplayName", vdata=search) win_reg.set_value(hive="HKLM", key=key, vname="DisplayName", vdata=search)
win_reg.set_value(hive="HKLM", key=key, vname="DisplayVersion", vdata="1.0.0") win_reg.set_value(hive="HKLM", key=key, vname="DisplayVersion", vdata="1.0.0")
win_reg.set_value( win_reg.set_value(
@ -114,7 +114,7 @@ def test_pkg__get_reg_software_noremove():
def test_pkg__get_reg_software_noremove_not_present(): def test_pkg__get_reg_software_noremove_not_present():
search = "test_pkg_noremove_not_present" search = "test_pkg_noremove_not_present"
key = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{}".format(search) key = f"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{search}"
win_reg.set_value(hive="HKLM", key=key, vname="DisplayName", vdata=search) win_reg.set_value(hive="HKLM", key=key, vname="DisplayName", vdata=search)
win_reg.set_value(hive="HKLM", key=key, vname="DisplayVersion", vdata="1.0.0") win_reg.set_value(hive="HKLM", key=key, vname="DisplayVersion", vdata="1.0.0")
try: try: