I have an ISO image that I would like to distribute. However, to make setup easier for the user, I would like add a unique .config file to each .iso file.
Is there a way to use python to modify the iso file?
There are known ways of browsing or parsing ISO files with Python libraries (see this question), but adding a file to the ISO will require filesystem modification - which is definitely far from trivial.
You could instead try to mount the ISO on your filesystem, modify it from Python, then unmount it again. A very quick example that would work under Ubuntu:
ISO_PATH = "your_iso_path_here"
# Mount the ISO in your OS
os.system("mkdir /media/tmp_iso")
os.system("mount -o rw,loop %s /media/tmp_iso" % ISO_PATH)
# Do your Pythonic manipulation here:
new_file = open("/media/tmp_iso/.config", 'w')
new_file.write(data)
new_file.close()
# Unmount
os.system("umount /media/tmp_iso")
os.system("rmdir /media/tmp_iso")
You'll want to use subprocess
instead of os.system
, among other things, but this is a start.