fix pylint

This commit is contained in:
Muayyad alsadi 2023-04-09 12:47:15 +03:00
parent 5e518c7ca7
commit 990f774659

View File

@ -95,21 +95,25 @@ PODMAN_CMDS = (
"volume", "volume",
) )
t_re=re.compile('^(?:(\d+)[m:])?(?:(\d+(?:\.\d+)?)s?)?$') t_re = re.compile(r"^(?:(\d+)[m:])?(?:(\d+(?:\.\d+)?)s?)?$")
STOP_GRACE_PERIOD = "10" STOP_GRACE_PERIOD = "10"
def str_to_seconds(txt): def str_to_seconds(txt):
if not txt: return None if not txt:
if isinstance(txt, int) or isinstance(txt, float): return None
return txt if isinstance(txt, (int, float)):
ma = t_re.match(txt.strip()) return txt
if not ma: return None match = t_re.match(txt.strip())
m, s = ma[1], ma[2] if not match:
m = int(m) if m else 0 return None
s = float(s) if s else 0 mins, sec = match[1], match[2]
# "podman stop" takes only int mins = int(mins) if mins else 0
# Error: invalid argument "3.0" for "-t, --time" flag: strconv.ParseUint: parsing "3.0": invalid syntax sec = float(sec) if sec else 0
return int(m*60.0 + s) # "podman stop" takes only int
# Error: invalid argument "3.0" for "-t, --time" flag: strconv.ParseUint: parsing "3.0": invalid syntax
return int(mins * 60.0 + sec)
def ver_as_list(a): def ver_as_list(a):
return [try_int(i, i) for i in num_split_re.findall(a)] return [try_int(i, i) for i in num_split_re.findall(a)]
@ -802,12 +806,17 @@ def get_net_args(compose, cnt):
if not ip6: if not ip6:
ip6 = net_value.get("ipv6_address", None) ip6 = net_value.get("ipv6_address", None)
net_priority = net_value.get("priority", 0) net_priority = net_value.get("priority", 0)
prioritized_cnt_nets.append((net_priority, net_key,)) prioritized_cnt_nets.append(
(
net_priority,
net_key,
)
)
# sort dict by priority # sort dict by priority
prioritized_cnt_nets.sort(reverse=True) prioritized_cnt_nets.sort(reverse=True)
cnt_nets = [ net_key for _, net_key in prioritized_cnt_nets ] cnt_nets = [net_key for _, net_key in prioritized_cnt_nets]
cnt_nets = norm_as_list(cnt_nets or default_net) cnt_nets = norm_as_list(cnt_nets or default_net)
net_names = list() net_names = []
for net in cnt_nets: for net in cnt_nets:
net_desc = nets[net] or {} net_desc = nets[net] or {}
is_ext = net_desc.get("external", None) is_ext = net_desc.get("external", None)
@ -2067,7 +2076,7 @@ def compose_up(compose, args):
max_service_length = ( max_service_length = (
curr_length if curr_length > max_service_length else max_service_length curr_length if curr_length > max_service_length else max_service_length
) )
has_sed = os.path.isfile('/bin/sed') has_sed = os.path.isfile("/bin/sed")
for i, cnt in enumerate(compose.containers): for i, cnt in enumerate(compose.containers):
# Add colored service prefix to output by piping output through sed # Add colored service prefix to output by piping output through sed
color_idx = i % len(compose.console_colors) color_idx = i % len(compose.console_colors)
@ -2186,7 +2195,6 @@ def compose_down(compose, args):
compose.podman.run([], "pod", ["rm", pod["name"]], sleep=0) compose.podman.run([], "pod", ["rm", pod["name"]], sleep=0)
@cmd_run(podman_compose, "ps", "show status of containers") @cmd_run(podman_compose, "ps", "show status of containers")
def compose_ps(compose, args): def compose_ps(compose, args):
proj_name = compose.project_name proj_name = compose.project_name
@ -2328,7 +2336,10 @@ def transfer_service_status(compose, args, action):
if action != "start": if action != "start":
timeout = timeout_global timeout = timeout_global
if timeout is None: if timeout is None:
timeout_str = compose.container_by_name[target].get("stop_grace_period", None) or STOP_GRACE_PERIOD timeout_str = (
compose.container_by_name[target].get("stop_grace_period", None)
or STOP_GRACE_PERIOD
)
timeout = str_to_seconds(timeout_str) timeout = str_to_seconds(timeout_str)
if timeout is not None: if timeout is not None:
podman_args.extend(["-t", str(timeout)]) podman_args.extend(["-t", str(timeout)])