@@ -79,3 +79,36 @@ def create_iso(vol_ident, sys_ident, files=None, files_raw=None,
7979 iso .close ()
8080
8181 return outiso
82+
83+
84+ def modify_iso (iso_path , output_iso_path , new_directories , new_files ):
85+ """
86+ https://clalancette.github.io/pycdlib/pycdlib-api.html
87+ :param new_directories: a list of dicts with new directories in format
88+ [
89+ {'iso_path': path,
90+ 'rr_name': rr_name if rocky ridge iso (optional)
91+ 'joliet_path': path only for joliet iso, (optional)
92+ 'file_mode': only for rocky ridge iso (optional)
93+ 'udf_path': path only for udf iso (optional)
94+ ]
95+ :param new_files: a list of dicts with new directories in format
96+ [
97+ {'iso_path': path,
98+ 'file_context': context of new file
99+ 'rr_name': rr_name if rocky ridge iso (optional)
100+ 'joliet_path': path only for joliet iso, (optional)
101+ 'file_mode': only for rocky ridge iso (optional)
102+ 'udf_path': path only for udf iso (optional)
103+ ]
104+ """
105+ iso = pycdlib .PyCdlib ()
106+ iso .open (iso_path )
107+ for new_dir in new_directories :
108+ iso .add_directory (** new_dir )
109+ for new_file in new_files :
110+ context = new_file .pop ('file_context' )
111+ context = bytes (context , 'utf-8' )
112+ iso .add_fp (BytesIO (context ), len (context ), ** new_file )
113+ iso .write (output_iso_path )
114+ iso .close ()
0 commit comments