mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-08 04:57:16 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -153,6 +153,7 @@ import traceback
|
|||
PYCDLIB_IMP_ERR = None
|
||||
try:
|
||||
import pycdlib
|
||||
|
||||
HAS_PYCDLIB = True
|
||||
except ImportError:
|
||||
PYCDLIB_IMP_ERR = traceback.format_exc()
|
||||
|
|
@ -168,7 +169,7 @@ def add_file(module, iso_file=None, src_file=None, file_path=None, rock_ridge=No
|
|||
# In standard ISO interchange level 1, file names have a maximum of 8 characters, followed by a required dot,
|
||||
# followed by a maximum 3 character extension, followed by a semicolon and a version
|
||||
file_name = os.path.basename(file_path)
|
||||
if '.' not in file_name:
|
||||
if "." not in file_name:
|
||||
file_in_iso_path = f"{file_path.upper()}.;1"
|
||||
else:
|
||||
file_in_iso_path = f"{file_path.upper()};1"
|
||||
|
|
@ -179,7 +180,9 @@ def add_file(module, iso_file=None, src_file=None, file_path=None, rock_ridge=No
|
|||
if use_udf:
|
||||
udf_path = file_path
|
||||
try:
|
||||
iso_file.add_file(src_file, iso_path=file_in_iso_path, rr_name=rr_name, joliet_path=joliet_path, udf_path=udf_path)
|
||||
iso_file.add_file(
|
||||
src_file, iso_path=file_in_iso_path, rr_name=rr_name, joliet_path=joliet_path, udf_path=udf_path
|
||||
)
|
||||
except Exception as err:
|
||||
module.fail_json(msg=f"Failed to add file {src_file} to ISO file due to {err}")
|
||||
|
||||
|
|
@ -203,31 +206,31 @@ def add_directory(module, iso_file=None, dir_path=None, rock_ridge=None, use_jol
|
|||
|
||||
def main():
|
||||
argument_spec = dict(
|
||||
src_files=dict(type='list', required=True, elements='path'),
|
||||
dest_iso=dict(type='path', required=True),
|
||||
interchange_level=dict(type='int', choices=[1, 2, 3, 4], default=1),
|
||||
vol_ident=dict(type='str'),
|
||||
rock_ridge=dict(type='str', choices=['1.09', '1.10', '1.12']),
|
||||
joliet=dict(type='int', choices=[1, 2, 3]),
|
||||
udf=dict(type='bool', default=False),
|
||||
src_files=dict(type="list", required=True, elements="path"),
|
||||
dest_iso=dict(type="path", required=True),
|
||||
interchange_level=dict(type="int", choices=[1, 2, 3, 4], default=1),
|
||||
vol_ident=dict(type="str"),
|
||||
rock_ridge=dict(type="str", choices=["1.09", "1.10", "1.12"]),
|
||||
joliet=dict(type="int", choices=[1, 2, 3]),
|
||||
udf=dict(type="bool", default=False),
|
||||
)
|
||||
module = AnsibleModule(
|
||||
argument_spec=argument_spec,
|
||||
supports_check_mode=True,
|
||||
)
|
||||
if not HAS_PYCDLIB:
|
||||
module.fail_json(missing_required_lib('pycdlib'), exception=PYCDLIB_IMP_ERR)
|
||||
module.fail_json(missing_required_lib("pycdlib"), exception=PYCDLIB_IMP_ERR)
|
||||
|
||||
src_file_list = module.params.get('src_files')
|
||||
src_file_list = module.params.get("src_files")
|
||||
if src_file_list and len(src_file_list) == 0:
|
||||
module.fail_json(msg='Please specify source file and/or directory list using src_files parameter.')
|
||||
module.fail_json(msg="Please specify source file and/or directory list using src_files parameter.")
|
||||
for src_file in src_file_list:
|
||||
if not os.path.exists(src_file):
|
||||
module.fail_json(msg=f"Specified source file/directory path does not exist on local machine, {src_file}")
|
||||
|
||||
dest_iso = module.params.get('dest_iso')
|
||||
dest_iso = module.params.get("dest_iso")
|
||||
if dest_iso and len(dest_iso) == 0:
|
||||
module.fail_json(msg='Please specify the absolute path of the new created ISO file using dest_iso parameter.')
|
||||
module.fail_json(msg="Please specify the absolute path of the new created ISO file using dest_iso parameter.")
|
||||
|
||||
dest_iso_dir = os.path.dirname(dest_iso)
|
||||
if dest_iso_dir and not os.path.exists(dest_iso_dir):
|
||||
|
|
@ -235,17 +238,17 @@ def main():
|
|||
try:
|
||||
os.makedirs(dest_iso_dir)
|
||||
except OSError as err:
|
||||
module.fail_json(msg=f'Exception caught when creating folder {dest_iso_dir}, with error {err}')
|
||||
module.fail_json(msg=f"Exception caught when creating folder {dest_iso_dir}, with error {err}")
|
||||
|
||||
volume_id = module.params.get('vol_ident')
|
||||
volume_id = module.params.get("vol_ident")
|
||||
if volume_id is None:
|
||||
volume_id = ''
|
||||
inter_level = module.params.get('interchange_level')
|
||||
rock_ridge = module.params.get('rock_ridge')
|
||||
use_joliet = module.params.get('joliet')
|
||||
volume_id = ""
|
||||
inter_level = module.params.get("interchange_level")
|
||||
rock_ridge = module.params.get("rock_ridge")
|
||||
use_joliet = module.params.get("joliet")
|
||||
use_udf = None
|
||||
if module.params['udf']:
|
||||
use_udf = '2.60'
|
||||
if module.params["udf"]:
|
||||
use_udf = "2.60"
|
||||
|
||||
result = dict(
|
||||
changed=False,
|
||||
|
|
@ -255,21 +258,29 @@ def main():
|
|||
vol_ident=volume_id,
|
||||
rock_ridge=rock_ridge,
|
||||
joliet=use_joliet,
|
||||
udf=use_udf
|
||||
udf=use_udf,
|
||||
)
|
||||
if not module.check_mode:
|
||||
iso_file = pycdlib.PyCdlib(always_consistent=True)
|
||||
iso_file.new(interchange_level=inter_level, vol_ident=volume_id, rock_ridge=rock_ridge, joliet=use_joliet, udf=use_udf)
|
||||
iso_file.new(
|
||||
interchange_level=inter_level, vol_ident=volume_id, rock_ridge=rock_ridge, joliet=use_joliet, udf=use_udf
|
||||
)
|
||||
|
||||
for src_file in src_file_list:
|
||||
# if specify a dir then go through the dir to add files and dirs
|
||||
if os.path.isdir(src_file):
|
||||
dir_list = []
|
||||
file_list = []
|
||||
src_file = src_file.rstrip('/')
|
||||
src_file = src_file.rstrip("/")
|
||||
dir_name = os.path.basename(src_file)
|
||||
add_directory(module, iso_file=iso_file, dir_path=f"/{dir_name}", rock_ridge=rock_ridge,
|
||||
use_joliet=use_joliet, use_udf=use_udf)
|
||||
add_directory(
|
||||
module,
|
||||
iso_file=iso_file,
|
||||
dir_path=f"/{dir_name}",
|
||||
rock_ridge=rock_ridge,
|
||||
use_joliet=use_joliet,
|
||||
use_udf=use_udf,
|
||||
)
|
||||
|
||||
# get dir list and file list
|
||||
for path, dirs, files in os.walk(src_file):
|
||||
|
|
@ -278,23 +289,42 @@ def main():
|
|||
for dir in dirs:
|
||||
dir_list.append(os.path.join(path, dir))
|
||||
for new_dir in dir_list:
|
||||
add_directory(module, iso_file=iso_file, dir_path=new_dir.split(os.path.dirname(src_file))[1],
|
||||
rock_ridge=rock_ridge, use_joliet=use_joliet, use_udf=use_udf)
|
||||
add_directory(
|
||||
module,
|
||||
iso_file=iso_file,
|
||||
dir_path=new_dir.split(os.path.dirname(src_file))[1],
|
||||
rock_ridge=rock_ridge,
|
||||
use_joliet=use_joliet,
|
||||
use_udf=use_udf,
|
||||
)
|
||||
for new_file in file_list:
|
||||
add_file(module, iso_file=iso_file, src_file=new_file,
|
||||
file_path=new_file.split(os.path.dirname(src_file))[1], rock_ridge=rock_ridge,
|
||||
use_joliet=use_joliet, use_udf=use_udf)
|
||||
add_file(
|
||||
module,
|
||||
iso_file=iso_file,
|
||||
src_file=new_file,
|
||||
file_path=new_file.split(os.path.dirname(src_file))[1],
|
||||
rock_ridge=rock_ridge,
|
||||
use_joliet=use_joliet,
|
||||
use_udf=use_udf,
|
||||
)
|
||||
# if specify a file then add this file directly to the '/' path in ISO
|
||||
else:
|
||||
add_file(module, iso_file=iso_file, src_file=src_file, file_path=f"/{os.path.basename(src_file)}",
|
||||
rock_ridge=rock_ridge, use_joliet=use_joliet, use_udf=use_udf)
|
||||
add_file(
|
||||
module,
|
||||
iso_file=iso_file,
|
||||
src_file=src_file,
|
||||
file_path=f"/{os.path.basename(src_file)}",
|
||||
rock_ridge=rock_ridge,
|
||||
use_joliet=use_joliet,
|
||||
use_udf=use_udf,
|
||||
)
|
||||
|
||||
iso_file.write(dest_iso)
|
||||
iso_file.close()
|
||||
|
||||
result['changed'] = True
|
||||
result["changed"] = True
|
||||
module.exit_json(**result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue