#!/usr/bin/env python

""" Usage: mkisofs-pkm [-o outputFileISO] <pathSpec>

	Make a iso filesystem, suitable for burning to cdrom, from the passed
	pathSpec, which can be any number of files and directories. This script's
	purpose is to make it easy to burn the type of data cd-rom that most people
	are going to want most of the time. 
	
	If passed a directory name, the entire directory tree will be included in the 
	ISO filesystem.
	
	If -o outputFileISO isn't passed, .iso will be appended to the first file
	or directory in pathSpec to derive the output ISO file.
	
	Requires the mkisofs utility, which likely exists on your Linux system
	already.
	
	Enjoy!   --Paul McNett (p@ulmcnett.com)
"""
import sys, os

# You may want to change the switches for your system. Default is:
# 		-J: Joliet, -r: RockRidge, -v: verbose output. 
# This will make cd's that are readable by Windows and Linux system.
switches = "-J -r -v"

def failure():
	sys.stderr.write(__doc__)
	sys.exit()
		
def main():
	try:

		if sys.argv[1] == "-o":
			pathSpec = sys.argv[3:]
			outputFileISO = sys.argv[2]
		else:
			pathSpec = sys.argv[1:]
			outputFileISO = "%s.iso"

	except IndexError:
		failure()	

	if len(pathSpec) == 0:
		failure()
		
	files = ""
	for file in pathSpec:
		files = ' '.join((files, file))

	os.system("mkisofs -o %s %s %s" % (outputFileISO, switches, files))

if __name__ == "__main__":
	main()
