mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-04-13 04:45:00 +00:00
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
# Copyright (c) 2020 Red Hat
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
__metaclass__ = type
|
|
|
|
import os
|
|
import shutil
|
|
|
|
|
|
def run_podman_command(module, executable='podman', args=None, expected_rc=0, ignore_errors=False):
|
|
if not isinstance(executable, list):
|
|
command = [executable]
|
|
if args is not None:
|
|
command.extend(args)
|
|
rc, out, err = module.run_command(command)
|
|
if not ignore_errors and rc != expected_rc:
|
|
module.fail_json(
|
|
msg='Failed to run {command} {args}: {err}'.format(
|
|
command=command, args=args, err=err))
|
|
return rc, out, err
|
|
|
|
|
|
def lower_keys(x):
|
|
if isinstance(x, list):
|
|
return [lower_keys(v) for v in x]
|
|
elif isinstance(x, dict):
|
|
return dict((k.lower(), lower_keys(v)) for k, v in x.items())
|
|
else:
|
|
return x
|
|
|
|
|
|
def remove_file_or_dir(path):
|
|
if os.path.isfile(path):
|
|
os.unlink(path)
|
|
elif os.path.isdir(path):
|
|
shutil.rmtree(path)
|
|
else:
|
|
raise ValueError("file %s is not a file or dir." % path)
|