Skip to content

Commit

Permalink
switch to % string lazy formatting
Browse files Browse the repository at this point in the history
* fix black and pylint issues

Signed-off-by: Florian Maurer <[email protected]>
  • Loading branch information
maurerle committed Mar 9, 2024
1 parent 1e9e2ee commit da520e2
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ async def assert_volume(compose, mount_dict):
proj_name = compose.project_name
vol_name = vol["name"]
is_ext = vol.get("external", None)
log.debug(f"podman volume inspect {vol_name} || podman volume create {vol_name}")
log.debug("podman volume inspect %s || podman volume create %s", vol_name, vol_name)
# TODO: might move to using "volume list"
# podman volume list --format '{{.Name}}\t{{.MountPoint}}' \
# -f 'label=io.podman.compose.project=HERE'
Expand Down Expand Up @@ -555,9 +555,11 @@ def get_secret_args(compose, cnt, secret):
volume_ref = ["--volume", f"{source_file}:{dest_file}:ro,rprivate,rbind"]
if uid or gid or mode:
sec = target if target else secret_name
log.warn(
f'WARNING: Service {cnt["_service"]} uses secret "{sec}" with uid, gid, or mode.'
+ " These fields are not supported by this implementation of the Compose file"
log.warning(
"WARNING: Service %s uses secret %s with uid, gid, or mode."
+ " These fields are not supported by this implementation of the Compose file",
cnt["_service"],
sec,
)
return volume_ref
# v3.5 and up added external flag, earlier the spec
Expand Down Expand Up @@ -586,11 +588,12 @@ def get_secret_args(compose, cnt, secret):
if target and target != secret_name:
raise ValueError(err_str.format(target, secret_name))
if target:
log.warn(
'WARNING: Service "{}" uses target: "{}" for secret: "{}".'.format(
cnt["_service"], target, secret_name
)
+ " That is un-supported and a no-op and is ignored."
log.warning(
'WARNING: Service "%s" uses target: "%s" for secret: "%s".'
+ " That is un-supported and a no-op and is ignored.",
cnt["_service"],
target,
secret_name,
)
return ["--secret", "{}{}".format(secret_name, secret_opts)]

Expand Down Expand Up @@ -770,7 +773,7 @@ def get_net_args(compose, cnt):
elif net.startswith("bridge"):
is_bridge = True
else:
log.fatal(f"unknown network_mode [{net}]")
log.fatal("unknown network_mode [%s]", net)
sys.exit(1)
else:
is_bridge = True
Expand Down Expand Up @@ -913,10 +916,10 @@ async def container_to_args(compose, cnt, detached=True):
await assert_cnt_nets(compose, cnt)
podman_args.extend(get_net_args(compose, cnt))

logging = cnt.get("logging", None)
if logging is not None:
podman_args.append(f'--log-driver={logging.get("driver", "k8s-file")}')
log_opts = logging.get("options") or {}
log_config = cnt.get("logging", None)
if log_config is not None:
podman_args.append(f'--log-driver={log_config.get("driver", "k8s-file")}')
log_opts = log_config.get("options") or {}
podman_args += [f"--log-opt={name}={value}" for name, value in log_opts.items()]
for secret in cnt.get("secrets", []):
podman_args.extend(get_secret_args(compose, cnt, secret))
Expand Down Expand Up @@ -1226,7 +1229,7 @@ async def format_out(stdout):
p.kill()
exit_code = await p.wait()

log.info(f"exit code: {exit_code}")
log.info("exit code: %s", exit_code)
return exit_code

async def volume_ls(self, proj=None):
Expand Down Expand Up @@ -1474,7 +1477,7 @@ def assert_services(self, services):
missing = given - self.all_services
if missing:
missing_csv = ",".join(missing)
log.warn(f"missing services [{missing_csv}]")
log.warning("missing services [%s]", missing_csv)
sys.exit(1)

def get_podman_args(self, cmd):
Expand All @@ -1488,7 +1491,7 @@ def get_podman_args(self, cmd):
return xargs

async def run(self):
log.info("podman-compose version: " + __version__)
log.info("podman-compose version: %s", __version__)
args = self._parse_args()
podman_path = args.podman_path
if podman_path != "podman":
Expand All @@ -1497,7 +1500,7 @@ async def run(self):
else:
# this also works if podman hasn't been installed now
if args.dry_run is False:
log.fatal(f"Binary {podman_path} has not been found.")
log.fatal("Binary %s has not been found.", podman_path)
sys.exit(1)
self.podman = Podman(self, podman_path, args.dry_run, asyncio.Semaphore(args.parallel))

Expand All @@ -1513,7 +1516,7 @@ async def run(self):
if not self.podman_version:
log.fatal("it seems that you do not have `podman` installed")
sys.exit(1)
log.info("using podman version: " + self.podman_version)
log.info("using podman version: %s", self.podman_version)
cmd_name = args.command
compose_required = cmd_name != "version" and (
cmd_name != "systemd" or args.action != "create-unit"
Expand Down Expand Up @@ -1648,7 +1651,7 @@ def _parse_compose_file(self):
services = compose.get("services", None)
if services is None:
services = {}
log.warn("WARNING: No services defined")
log.warning("WARNING: No services defined")
# include services with no profile defined or the selected profiles
services = self._resolve_profiles(services, set(args.profile))

Expand Down Expand Up @@ -1681,7 +1684,7 @@ def _parse_compose_file(self):
unused_nets = given_nets - allnets - set(["default"])
if len(unused_nets):
unused_nets_str = ",".join(unused_nets)
log.warn(f"WARNING: unused networks: {unused_nets_str}")
log.warning("WARNING: unused networks: %s", unused_nets_str)
if len(missing_nets):
missing_nets_str = ",".join(missing_nets)
raise RuntimeError(f"missing networks: {missing_nets_str}")
Expand Down Expand Up @@ -1793,7 +1796,7 @@ def _parse_args(self):
parser.print_help()
sys.exit(-1)

logging.basicConfig(level=('DEBUG' if self.global_args.verbose else 'WARN'))
logging.basicConfig(level=("DEBUG" if self.global_args.verbose else "WARN"))
return self.global_args

@staticmethod
Expand Down Expand Up @@ -1981,12 +1984,12 @@ async def compose_systemd(compose, args):
proj_name = compose.project_name
fn = os.path.expanduser(f"~/{stacks_dir}/{proj_name}.env")
os.makedirs(os.path.dirname(fn), exist_ok=True)
log.debug(f"writing [{fn}]: ...")
log.debug("writing [%s]: ...", fn)
with open(fn, "w", encoding="utf-8") as f:
for k, v in compose.environ.items():
if k.startswith("COMPOSE_") or k.startswith("PODMAN_"):
f.write(f"{k}={v}\n")
log.debug(f"writing [{fn}]: done.")
log.debug("writing [%s]: done.", fn)
log.info("\n\ncreating the pod without starting it: ...\n\n")
process = await asyncio.subprocess.create_subprocess_exec(script, ["up", "--no-start"])
log.info("\nfinal exit code is ", process)
Expand Down Expand Up @@ -2036,18 +2039,18 @@ async def compose_systemd(compose, args):
WantedBy=default.target
"""
if os.access(os.path.dirname(fn), os.W_OK):
log.debug(f"writing [{fn}]: ...")
log.debug("writing [%s]: ...", fn)
with open(fn, "w", encoding="utf-8") as f:
f.write(out)
log.debug(f"writing [{fn}]: done.")
log.debug("writing [%s]: done.", fn)
print(
"""
while in your project type `podman-compose systemd -a register`
"""
)
else:
print(out)
log.warn(f"Could not write to [{fn}], use 'sudo'")
log.warning("Could not write to [%s], use 'sudo'", fn)


@cmd_run(podman_compose, "pull", "pull stack images")
Expand Down Expand Up @@ -2367,7 +2370,7 @@ async def compose_down(compose, args):
if cnt["_service"] not in excluded:
continue
vol_names_to_keep.update(get_volume_names(compose, cnt))
log.debug("keep", vol_names_to_keep)
log.debug("keep %s", vol_names_to_keep)
for volume_name in await compose.podman.volume_ls():
if volume_name in vol_names_to_keep:
continue
Expand Down

0 comments on commit da520e2

Please sign in to comment.