Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.d/20260302_134629_cz_update_python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Update required Python to ≥3.9
25 changes: 5 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
]
requires-python = ">=3.6"
requires-python = ">=3.9"
dependencies = [
"batou >= 2.3b4",
"batou >= 2.5",
"pyaml",
"setuptools",
"six",
Expand Down Expand Up @@ -56,16 +56,6 @@ zip-safe = false
[tool.setuptools.packages.find]
where = ["src"]

[tool.black]
line-length = 80
target-version = ['py36', 'py37', 'py38']

[tool.isort]
profile = "black"
line_length = 80
multi_line_output = 3
include_trailing_comma = true

[tool.pytest.ini_options]
addopts = "--pyargs batou_ext"

Expand All @@ -79,16 +69,11 @@ new_fragment_template = "- New changelog entry."
insert_marker = "- Nothing changed yet."
categories = []

[flake8]
ignore = [
"E231", # Missing whitespace after ',', ';', or ':' -- enforced by yapf config
"W503", # Line break occurred before a binary operator -- enforced by yapf config
"W504", # Line break occurred after a binary operator -- enforced by yapf config
]
max-line-length = 80

[zest.releaser]
version-levels = 3
history-file = "CHANGES.md"
release = "yes"
history_format = "md"

[tool.ruff]
line-length = 80
8 changes: 6 additions & 2 deletions src/batou_ext/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def configure(self):

self += batou.lib.file.File(
self.expand("{{component.tag}}.sh"),
content=(files(__spec__.parent) / "resources/cron-wrapper.sh").read_bytes(),
content=(
files(__spec__.parent) / "resources/cron-wrapper.sh"
).read_bytes(),
mode=0o755,
)
self.wrapped_command = self._.path
Expand Down Expand Up @@ -145,7 +147,9 @@ class SystemdTimer(batou.component.Component):
additional_service_config = None
run_as = batou.component.Attribute(
str,
default=batou.component.ConfigString("{{component.environment.service_user}}"),
default=batou.component.ConfigString(
"{{component.environment.service_user}}"
),
)

def configure(self):
Expand Down
23 changes: 17 additions & 6 deletions src/batou_ext/fcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def _compute_calls(self):

def _call(self):
api = xmlrpc.client.ServerProxy(
"https://{s.project}:{s.api_key}@api.flyingcircus.io/v1".format(s=self)
"https://{s.project}:{s.api_key}@api.flyingcircus.io/v1".format(
s=self
)
)
api.apply(self.calls)

Expand Down Expand Up @@ -129,7 +131,8 @@ def _check_aliases(self):
error = True
else:
result = ", ".join(
sockaddr[0] for (family, type, proto, canonname, sockaddr) in addrs
sockaddr[0]
for (family, type, proto, canonname, sockaddr) in addrs
)
results.append("{}: {}".format(fqdn, result))
return error, results
Expand All @@ -148,7 +151,9 @@ def create_xmlrpc_client(environment: batou.environment.Environment):
)
raise
api_url = environment.overrides["provision"].get("api_url", API_URL)
api = xmlrpc.client.ServerProxy(api_url.format(project=rg_name, api_key=api_key))
api = xmlrpc.client.ServerProxy(
api_url.format(project=rg_name, api_key=api_key)
)
return api


Expand Down Expand Up @@ -208,7 +213,9 @@ def config(name):
classes = ["role::" + r for r in roles if r]

if d.get("environment", config("vm_environment")) is None:
raise ValueError("'environment' for {} must be set.".format(name))
raise ValueError(
"'environment' for {} must be set.".format(name)
)

call = dict(
__type__="virtualmachine",
Expand Down Expand Up @@ -254,7 +261,9 @@ def alias(interface):
print(vm)
for key, (old, new) in sorted(changes.items()):
if old or new:
print(" {key:20}: {old} → {new}".format(**locals()))
print(
" {key:20}: {old} → {new}".format(**locals())
)
else:
print(" {key}".format(**locals()))
else:
Expand Down Expand Up @@ -383,7 +392,9 @@ def update(self):
)


def change_maintenance_state(xmlrpc, rg_name, desired_state, predict_only=False):
def change_maintenance_state(
xmlrpc, rg_name, desired_state, predict_only=False
):
rg = next(
(rg for rg in xmlrpc.query("resourcegroup") if rg["name"] == rg_name),
None,
Expand Down
4 changes: 3 additions & 1 deletion src/batou_ext/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class SymlinkAndCleanup(batou.component.Component):
systemd_extra_args = None

def configure(self):
self._current_link = f"{self.prefix}-current" if self.prefix else "current"
self._current_link = (
f"{self.prefix}-current" if self.prefix else "current"
)
self._last_link = f"{self.prefix}-last" if self.prefix else "last"

p = Path(self.current)
Expand Down
8 changes: 6 additions & 2 deletions src/batou_ext/geoip.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def configure(self):
self.provide("geoip_database", self)
self += batou.lib.file.File(
"geoip-update.sh",
source=os.path.join(os.path.dirname(__file__), "resources/geoip-update.sh"),
source=os.path.join(
os.path.dirname(__file__), "resources/geoip-update.sh"
),
mode=0o744,
)
self.script = self._.path
Expand All @@ -47,7 +49,9 @@ def configure(self):
checkCritical=30000,
)

self.database_file = self.expand("{{component.workdir}}/GeoLite2-City.mmdb")
self.database_file = self.expand(
"{{component.workdir}}/GeoLite2-City.mmdb"
)

def verify(self):
self.assert_no_changes()
Expand Down
24 changes: 18 additions & 6 deletions src/batou_ext/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ def configure(self):

if self.scan_host:
if not self.git_host:
self.git_host = urllib.parse.urlparse(self.git_clone_url).hostname
self.git_host = urllib.parse.urlparse(
self.git_clone_url
).hostname
if not self.git_port:
self.git_port = urllib.parse.urlparse(self.git_clone_url).port or 22
self.git_port = (
urllib.parse.urlparse(self.git_clone_url).port or 22
)
# Add remote host to known hosts
self += batou_ext.ssh.ScanHost(self.git_host, port=self.git_port)

Expand All @@ -86,10 +90,14 @@ def configure(self):
# add custom files
if self.sync_parent_folder:
self.prepared_path = self.map(
"{}/prepared-{}".format(self.sync_parent_folder, self.git_revision)
"{}/prepared-{}".format(
self.sync_parent_folder, self.git_revision
)
)
else:
self.prepared_path = self.map("prepared-{}".format(self.git_revision))
self.prepared_path = self.map(
"prepared-{}".format(self.git_revision)
)
self += batou.lib.file.Directory(self.prepared_path, leading=True)
self += batou.lib.file.Directory(
self.prepared_path,
Expand Down Expand Up @@ -123,11 +131,15 @@ def update(self):
self.cmd("git config user.email '{{component.author_email}}'")
self.cmd("git config user.name '{{component.author_name}}'")
self.cmd("git add {{component.filename}}")
self.cmd("git commit -m '{{component.message}}' {{component.filename}}")
self.cmd(
"git commit -m '{{component.message}}' {{component.filename}}"
)

def has_changes(self):
with self.chdir(self.workingdir):
stdout, stderr = self.cmd("git status --porcelain {{component.filename}}")
stdout, stderr = self.cmd(
"git status --porcelain {{component.filename}}"
)
return bool(stdout.strip())


Expand Down
12 changes: 9 additions & 3 deletions src/batou_ext/jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@


def git_ls_remote(url, ref):
cmd = subprocess.Popen(["git", "ls-remote", url, ref], stdout=subprocess.PIPE)
cmd = subprocess.Popen(
["git", "ls-remote", url, ref], stdout=subprocess.PIPE
)
stdout, _ = cmd.communicate()
if cmd.returncode != 0:
raise ValueError(
Expand Down Expand Up @@ -84,7 +86,9 @@ def update(self, service, version):
def update_git(self, service, version, extra_args):
resolved = git_resolve(self.config.get(service, "url"), version)
if not resolved:
raise ValueError("%s: Could not resolve version %s." % (service, version))
raise ValueError(
"%s: Could not resolve version %s." % (service, version)
)
log("%s: resolved version %s to: %s", service, version, resolved)
self.config.set(service, "revision", resolved)
self.config.set(service, "version", version)
Expand Down Expand Up @@ -141,7 +145,9 @@ def main():
"versions_file",
help="Name of versions.ini. If exists it will be overwritten.",
)
p.add_argument("version_mapping_json", help="JSON: mapping of service: version")
p.add_argument(
"version_mapping_json", help="JSON: mapping of service: version"
)
p.set_defaults(func=set_versions)

args = parser.parse_args()
Expand Down
4 changes: 3 additions & 1 deletion src/batou_ext/journalbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ class JournalBeatTransport(batou.component.Component):
def configure(self):
self += batou.lib.file.File(
self.nix_file_path,
content=(files(__spec__.parent) / "resources/journalbeat.nix").read_bytes(),
content=(
files(__spec__.parent) / "resources/journalbeat.nix"
).read_bytes(),
)
12 changes: 9 additions & 3 deletions src/batou_ext/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ class Mailhog(batou.component.Component):
mailport = batou.component.Attribute(int, 1025)
uiport = batou.component.Attribute(int, 8025)
apiport = batou.component.Attribute(int, 8025)
purge_old_mailhog_configs = batou.component.Attribute("literal", default=True)
purge_old_mailhog_configs = batou.component.Attribute(
"literal", default=True
)
http_auth_enable = batou.component.Attribute("literal", default=False)
http_basic_auth = None

Expand Down Expand Up @@ -196,7 +198,9 @@ def configure(self):
if not self.public_smtp_name:
self.public_smtp_name = self.host.fqdn

self.address = batou.utils.Address(self.public_smtp_name, self.smtp_port)
self.address = batou.utils.Address(
self.public_smtp_name, self.smtp_port
)

if self.http_basic_auth is None:
self.http_auth = self.require_one("http_basic_auth")
Expand All @@ -205,5 +209,7 @@ def configure(self):

self += batou.lib.file.File(
"/etc/local/nixos/mailpit.nix",
content=(files(__spec__.parent) / "resources/mailpit.nix").read_bytes(),
content=(
files(__spec__.parent) / "resources/mailpit.nix"
).read_bytes(),
)
8 changes: 6 additions & 2 deletions src/batou_ext/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@ def nginx_enable_config(self):
self += self.cert

if self.authstring:
self.htpasswdfile = batou.lib.file.File("htpasswd", content=self.authstring)
self.htpasswdfile = batou.lib.file.File(
"htpasswd", content=self.authstring
)
self += self.htpasswdfile

assert self.nginx_config_path

self += batou.lib.file.File(
"{}/{}.conf".format(self.nginx_config_path, self.public_name),
source=os.path.join(os.path.dirname(__file__), "resources/mirror.conf"),
source=os.path.join(
os.path.dirname(__file__), "resources/mirror.conf"
),
)

self += self.cert.activate_letsencrypt()
Loading
Loading