Skip to content

Commit

Permalink
fixing lint
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgreenaway committed Aug 2, 2023
1 parent d17d0a0 commit 3d61bca
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 81 deletions.
44 changes: 20 additions & 24 deletions src/saltext/saltext_apache/modules/apache.py
Expand Up @@ -7,8 +7,6 @@
deb_apache.py, but will still load under the ``apache`` namespace when a
Debian-based system is detected.
"""


import io
import logging
import re
Expand Down Expand Up @@ -61,7 +59,7 @@ def version():
salt '*' apache.version
"""
cmd = "{} -v".format(_detect_os())
cmd = f"{_detect_os()} -v"
out = __salt__["cmd.run"](cmd).splitlines()
ret = out[0].split(": ")
return ret[1]
Expand All @@ -77,7 +75,7 @@ def fullversion():
salt '*' apache.fullversion
"""
cmd = "{} -V".format(_detect_os())
cmd = f"{_detect_os()} -V"
ret = {}
ret["compiled_with"] = []
out = __salt__["cmd.run"](cmd).splitlines()
Expand Down Expand Up @@ -106,7 +104,7 @@ def modules():
salt '*' apache.modules
"""
cmd = "{} -M".format(_detect_os())
cmd = f"{_detect_os()} -M"
ret = {}
ret["static"] = []
ret["shared"] = []
Expand All @@ -132,7 +130,7 @@ def servermods():
salt '*' apache.servermods
"""
cmd = "{} -l".format(_detect_os())
cmd = f"{_detect_os()} -l"
ret = []
out = __salt__["cmd.run"](cmd).splitlines()
for line in out:
Expand All @@ -154,7 +152,7 @@ def directives():
salt '*' apache.directives
"""
cmd = "{} -L".format(_detect_os())
cmd = f"{_detect_os()} -L"
ret = {}
out = __salt__["cmd.run"](cmd)
out = out.replace("\n\t", "\t")
Expand All @@ -181,7 +179,7 @@ def vhosts():
salt -t 10 '*' apache.vhosts
"""
cmd = "{} -S".format(_detect_os())
cmd = f"{_detect_os()} -S"
ret = {}
namevhost = ""
out = __salt__["cmd.run"](cmd)
Expand Down Expand Up @@ -222,9 +220,9 @@ def signal(signal=None):
return
# Make sure you use the right arguments
if signal in valid_signals:
arguments = " -k {}".format(signal)
arguments = f" -k {signal}"
else:
arguments = " {}".format(signal)
arguments = f" {signal}"
cmd = _detect_os() + arguments
out = __salt__["cmd.run_all"](cmd)

Expand All @@ -238,7 +236,7 @@ def signal(signal=None):
ret = out["stdout"].strip()
# No output for something like: apachectl graceful
else:
ret = 'Command: "{}" completed successfully!'.format(cmd)
ret = f'Command: "{cmd}" completed successfully!'
return ret


Expand Down Expand Up @@ -327,14 +325,12 @@ def server_status(profile="default"):

# Get configuration from pillar
url = __salt__["config.get"](
"apache.server-status:{}:url".format(profile), "http://localhost/server-status"
)
user = __salt__["config.get"]("apache.server-status:{}:user".format(profile), "")
passwd = __salt__["config.get"]("apache.server-status:{}:pass".format(profile), "")
realm = __salt__["config.get"]("apache.server-status:{}:realm".format(profile), "")
timeout = __salt__["config.get"](
"apache.server-status:{}:timeout".format(profile), 5
f"apache.server-status:{profile}:url", "http://localhost/server-status"
)
user = __salt__["config.get"](f"apache.server-status:{profile}:user", "")
passwd = __salt__["config.get"](f"apache.server-status:{profile}:pass", "")
realm = __salt__["config.get"](f"apache.server-status:{profile}:realm", "")
timeout = __salt__["config.get"](f"apache.server-status:{profile}:timeout", 5)

# create authentication handler if configuration exists
if user and passwd:
Expand Down Expand Up @@ -380,22 +376,22 @@ def _parse_config(conf, slot=None):
ret = io.StringIO()
if isinstance(conf, str):
if slot:
print("{} {}".format(slot, conf), file=ret, end="")
print(f"{slot} {conf}", file=ret, end="")
else:
print("{}".format(conf), file=ret, end="")
print(f"{conf}", file=ret, end="")
elif isinstance(conf, list):
is_section = False
for item in conf:
if "this" in item:
is_section = True
slot_this = str(item["this"])
if is_section:
print("<{} {}>".format(slot, slot_this), file=ret)
print(f"<{slot} {slot_this}>", file=ret)
for item in conf:
for key, val in item.items():
if key != "this":
print(_parse_config(val, str(key)), file=ret)
print("</{}>".format(slot), file=ret)
print(f"</{slot}>", file=ret)
else:
for value in conf:
print(_parse_config(value, str(slot)), file=ret)
Expand All @@ -410,12 +406,12 @@ def _parse_config(conf, slot=None):
for key, value in conf.items():
if key != "this":
if isinstance(value, str):
print("{} {}".format(key, value), file=ret)
print(f"{key} {value}", file=ret)
elif isinstance(value, list):
print(_parse_config(value, key), file=ret)
elif isinstance(value, dict):
print(_parse_config(value, key), file=ret)
print("</{}>".format(slot), file=ret)
print(f"</{slot}>", file=ret)

ret.seek(0)
return ret.read()
Expand Down
41 changes: 19 additions & 22 deletions src/saltext/saltext_apache/modules/deb_apache.py
Expand Up @@ -5,7 +5,6 @@
separate file will allow them to load only on Debian-based systems, while still
loading under the ``apache`` namespace.
"""

import logging
import os

Expand Down Expand Up @@ -59,12 +58,10 @@ def check_site_enabled(site):
if site.endswith(".conf"):
site_file = site
else:
site_file = "{}.conf".format(site)
if os.path.islink("{}/{}".format(SITE_ENABLED_DIR, site_file)):
site_file = f"{site}.conf"
if os.path.islink(f"{SITE_ENABLED_DIR}/{site_file}"):
return True
elif site == "default" and os.path.islink(
"{}/000-{}".format(SITE_ENABLED_DIR, site_file)
):
elif site == "default" and os.path.islink(f"{SITE_ENABLED_DIR}/000-{site_file}"):
return True
else:
return False
Expand Down Expand Up @@ -95,9 +92,9 @@ def a2ensite(site):
ret["Site"] = site

if status == 1:
ret["Status"] = "Site {} Not found".format(site)
ret["Status"] = f"Site {site} Not found"
elif status == 0:
ret["Status"] = "Site {} enabled".format(site)
ret["Status"] = f"Site {site} enabled"
else:
ret["Status"] = status

Expand Down Expand Up @@ -129,9 +126,9 @@ def a2dissite(site):
ret["Site"] = site

if status == 256:
ret["Status"] = "Site {} Not found".format(site)
ret["Status"] = f"Site {site} Not found"
elif status == 0:
ret["Status"] = "Site {} disabled".format(site)
ret["Status"] = f"Site {site} disabled"
else:
ret["Status"] = status

Expand All @@ -156,8 +153,8 @@ def check_mod_enabled(mod):
if mod.endswith(".load") or mod.endswith(".conf"):
mod_file = mod
else:
mod_file = "{}.load".format(mod)
return os.path.islink("/etc/apache2/mods-enabled/{}".format(mod_file))
mod_file = f"{mod}.load"
return os.path.islink(f"/etc/apache2/mods-enabled/{mod_file}")


def a2enmod(mod):
Expand Down Expand Up @@ -185,9 +182,9 @@ def a2enmod(mod):
ret["Mod"] = mod

if status == 1:
ret["Status"] = "Mod {} Not found".format(mod)
ret["Status"] = f"Mod {mod} Not found"
elif status == 0:
ret["Status"] = "Mod {} enabled".format(mod)
ret["Status"] = f"Mod {mod} enabled"
else:
ret["Status"] = status

Expand Down Expand Up @@ -219,9 +216,9 @@ def a2dismod(mod):
ret["Mod"] = mod

if status == 256:
ret["Status"] = "Mod {} Not found".format(mod)
ret["Status"] = f"Mod {mod} Not found"
elif status == 0:
ret["Status"] = "Mod {} disabled".format(mod)
ret["Status"] = f"Mod {mod} disabled"
else:
ret["Status"] = status

Expand All @@ -247,8 +244,8 @@ def check_conf_enabled(conf):
if conf.endswith(".conf"):
conf_file = conf
else:
conf_file = "{}.conf".format(conf)
return os.path.islink("/etc/apache2/conf-enabled/{}".format(conf_file))
conf_file = f"{conf}.conf"
return os.path.islink(f"/etc/apache2/conf-enabled/{conf_file}")


@salt.utils.decorators.path.which("a2enconf")
Expand Down Expand Up @@ -279,9 +276,9 @@ def a2enconf(conf):
ret["Conf"] = conf

if status == 1:
ret["Status"] = "Conf {} Not found".format(conf)
ret["Status"] = f"Conf {conf} Not found"
elif status == 0:
ret["Status"] = "Conf {} enabled".format(conf)
ret["Status"] = f"Conf {conf} enabled"
else:
ret["Status"] = status

Expand Down Expand Up @@ -316,9 +313,9 @@ def a2disconf(conf):
ret["Conf"] = conf

if status == 256:
ret["Status"] = "Conf {} Not found".format(conf)
ret["Status"] = f"Conf {conf} Not found"
elif status == 0:
ret["Status"] = "Conf {} disabled".format(conf)
ret["Status"] = f"Conf {conf} disabled"
else:
ret["Status"] = status

Expand Down
9 changes: 4 additions & 5 deletions src/saltext/saltext_apache/modules/suse_apache.py
Expand Up @@ -5,7 +5,6 @@
separate file will allow them to load only on SUSE systems, while still
loading under the ``apache`` namespace.
"""

import logging

import salt.utils.path
Expand Down Expand Up @@ -73,9 +72,9 @@ def a2enmod(mod):
ret["Mod"] = mod

if status == 1:
ret["Status"] = "Mod {} Not found".format(mod)
ret["Status"] = f"Mod {mod} Not found"
elif status == 0:
ret["Status"] = "Mod {} enabled".format(mod)
ret["Status"] = f"Mod {mod} enabled"
else:
ret["Status"] = status

Expand Down Expand Up @@ -104,9 +103,9 @@ def a2dismod(mod):
ret["Mod"] = mod

if status == 256:
ret["Status"] = "Mod {} Not found".format(mod)
ret["Status"] = f"Mod {mod} Not found"
elif status == 0:
ret["Status"] = "Mod {} disabled".format(mod)
ret["Status"] = f"Mod {mod} disabled"
else:
ret["Status"] = status

Expand Down
2 changes: 0 additions & 2 deletions src/saltext/saltext_apache/states/apache.py
Expand Up @@ -83,8 +83,6 @@
this: "\b"
do: another thing
"""


import os

import salt.utils.files
Expand Down
17 changes: 8 additions & 9 deletions src/saltext/saltext_apache/states/apache_conf.py
Expand Up @@ -15,7 +15,6 @@
apache_conf.disabled:
- name: security
"""

import salt.utils.path


Expand All @@ -40,7 +39,7 @@ def enabled(name):
is_enabled = __salt__["apache.check_conf_enabled"](name)
if not is_enabled:
if __opts__["test"]:
msg = "Apache conf {} is set to be enabled.".format(name)
msg = f"Apache conf {name} is set to be enabled."
ret["comment"] = msg
ret["changes"]["old"] = None
ret["changes"]["new"] = name
Expand All @@ -53,12 +52,12 @@ def enabled(name):
ret["changes"]["new"] = name
else:
ret["result"] = False
ret["comment"] = "Failed to enable {} Apache conf".format(name)
ret["comment"] = f"Failed to enable {name} Apache conf"
if isinstance(status, str):
ret["comment"] = ret["comment"] + " ({})".format(status)
ret["comment"] = ret["comment"] + f" ({status})"
return ret
else:
ret["comment"] = "{} already enabled.".format(name)
ret["comment"] = f"{name} already enabled."
return ret


Expand All @@ -74,7 +73,7 @@ def disabled(name):
is_enabled = __salt__["apache.check_conf_enabled"](name)
if is_enabled:
if __opts__["test"]:
msg = "Apache conf {} is set to be disabled.".format(name)
msg = f"Apache conf {name} is set to be disabled."
ret["comment"] = msg
ret["changes"]["old"] = name
ret["changes"]["new"] = None
Expand All @@ -87,10 +86,10 @@ def disabled(name):
ret["changes"]["new"] = None
else:
ret["result"] = False
ret["comment"] = "Failed to disable {} Apache conf".format(name)
ret["comment"] = f"Failed to disable {name} Apache conf"
if isinstance(status, str):
ret["comment"] = ret["comment"] + " ({})".format(status)
ret["comment"] = ret["comment"] + f" ({status})"
return ret
else:
ret["comment"] = "{} already disabled.".format(name)
ret["comment"] = f"{name} already disabled."
return ret

0 comments on commit 3d61bca

Please sign in to comment.