³ò
{RLc           @   s  d  Z  d d k Z d d k Z d d k l Z l Z l Z l Z l Z l	 Z	 l
 Z
 d „  Z e d j o¡d d k Z e
 e i ƒ Z e e ƒ d j o d GHe i ƒ  n e d e d	 e i ƒ f d
 e d e i ƒ f d e d e i ƒ f d e d e i ƒ f d e d e i ƒ f d e d e i ƒ f d e d e i ƒ f d e d e i ƒ f d e d e i ƒ f d e d e i ƒ f d e d e i ƒ f d e d e i ƒ f d  e d! e i ƒ f d" e d# e i ƒ f g ƒ Z e d e e ƒ !Z e e e ƒ e i ƒ  n d S($   s£  
#+
# NAME:
#	burndisk
# PURPOSE:
#	Burn CD or DVD from directory tree
# CALLING SEQUENCE:
#	burndisk.py [-tar] directory
# INPUTS:
#	directory	top of directory tree to be burned on CD
# OPTIONAL INPUTS:
#	-tar		create zipped tar file and burn CD/DVD
#	-dvd		needed to burn DVDs
#	-img		only creates the CD image (no burning)
#			(in this case -nosudo and -dvd are ignored)
#	-nosudo		launch cdrecord without using sudo
#			By default cdrecord is called using sudo.
#			This requires that /etc/sudoers is set up
#			correctly (see RESTRICTIONS).
#			If -nosudo is set then cdrecord is called directly.
#			This requires special user privileges. Never seem
#			to get it to work right.
# 	-verbose	produces more informational messages
#	-temp=temp	directory where the CD image file and
#			tar file are created (default: $TUB)
#	-count=count	indicates number of copies to be burned
#			(default:1)
#	-speed=speed	write speed; default: none
#	-mode=mode	burn mode; default: sao.
#			See REMARKS.
#	-dev=dev	scsi dev for writer. Default: none
#	-email=email	comma-separated list of email addresses to which
#			to send an email upon completion.
#	-exe=exe	name of executable to use for burning disk
#	-nojoliet	omits -J on mkisofs
#	-links		adds -f to mkisofs (follows soft links)
#
#	Some of keywords can be stored in env vars (a command line keyword always
#	takes precedence though):
#
#	If make_dvd SET (burning DVDs):
#		keyword -mode:	DVDMODE		write mode
#		keyword -speed	DVDSPEED	write speed
#	If make_dvd NOT set (burning CDs)
#		keyword -mode:	CDMODE		write mode
#		keyword -dev:	CDSPEED		write speed
#
# RESTRICTIONS:
#	Burning the CD requires the program mkisofs to create the ISO file.
#	The CD/DVD is burned using cdrecord, or wodim (should be available
#	since Fedore Core 7).
#
# REMARKS:
#	I think, sao (session at once) is the same as dao (disk at once).
#	This is the default for cdrecord on most (but not all) of our Linux boxes.
#	Some versions use tao (track at once) by default.
#	One version of cdrecord we use does not accept mode sao at all, but when
#	called with dao said it was running in sao mode. Go figure.
#
#	
# RESTRICTIONS:
#	By default sudo is used to execute cdrecord. This requires that
#	/etc/sudoers needs to be set up correctly. Add a line like:
#		username   ALL=(ALL) NOPASSWD: <dir1>/cdrecord,<dir2>/cdrecord-ProDVD
#	(remember to 'chmod u-w /etc/sudoers' after modifying the file or sudo
#	will refuse to access it).
#
# PROCEDURE:
#	The CD image and the tarball (if -tar is set) are created
#	in 'tempdir', and are deleted after processing.
#
#	If called from another Python module:
#		status = burndisk(alldirs, burn_args)
#	then 'alldirs' is a list of directories, and burn_args is a
#	dictionary, set up with:
#	burn_args = dict	#		( [				#		  ( 'make_tar', is_there( '-tar'   , sys.argv ) ),	#		  ( 'make_dvd', is_there( '-dvd'   , sys.argv ) ),	#		  ( 'make_img', is_there( '-img'   , sys.argv ) ),	#		  ( 'nosudo'  , is_there( '-nosudo', sys.argv ) ),	#		  ( 'verbose' , is_there( '-verbose',sys.argv ) ),	#		  ( 'tempdir' , start   ( '-temp=' , sys.argv ) ),	#		  ( 'count'   , start   ( '-count=', sys.argv ) ),	#		  ( 'speed'   , start   ( '-speed=', sys.argv ) ),	#		  ( 'dev'     , start   ( '-dev='  , sys.argv ) ),	#		  ( 'email'   , start   ( '-email=', sys.argv ) ),	#		  ( 'exe'     , start   ( '-exe='  , sys.argv ) ),	#		  ( 'nojoliet', is_there( '-nojoliet',sys.argv) ),	#		  ( 'links'   , is_there( '-links=', sys.argv ) )	] )
# MODIFICATION HISTORY:
#	MAR-2003, Paul Hick (UCSD/CASS)
#	JUL-2003, Paul Hick (UCSD/CASS)
#		Modified to allow for multiple directories on cmd line.
#	OCT-2003, Paul Hick (UCSD/CASS)
#		Fixed bug with -tar keyword
#	JAN-2004, Paul Hick (UCSD/CASS)
#		Merged Austin Duncans burn_a_dvd.py with burn_a_cd.py and
#		renamed it burndisk.py. To burn DVDs set keyword -dvd
#	FEB-2004, Paul Hick (UCSD/CASS)
#		Modified to make callable from other Python modules
#		Added -temp keyword to set directory where tar ball and
#		CD image are created.
#		Added -count keyword to set # copies to be burned
#	MAR-2004, Paul Hick (UCSD/CASS)
#		Added -speed, -verbose and -dev keywords.
#		Changed to dictionary for list of args
#		Added a return value to burndisk. Status=0 is supposed
#		to indicate a succesful creation of a CD/DVD. ... Right.
#		For multiple directories the -graft-points option on mkisofs is
#		now used. The name of the subdirectory is used as the graft point.
#	JUL-2004, Paul Hick (UCSD/CASS)
#		Added check for env vars CDSPEED, CDWR, CDMODE (-dvd not set)
#		or DVDSPEED, DVDWR, DVDMODE (-dvd set) after checking for command
#		line arguments.
#	AUG-2004, Paul Hick (UCSD/CASS)
#		Replaced -sudo by -nosudo. Set default mode to sao.
#		Modified selection of program to burn CD/DVD.
#	AUG-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#		Added -exe, -nojoliet and -links keyword
#	OCT-2005, Paul Hick (UCSD/CASS)
#		Modified selection of CD/DVD burning program. The default now
#		is cdrecord (which comes with the Linux distribution, usually
#		in /usr/bin). If this is not found then cdrecord-ProDVD is used,
#		if available. Remember that for burning DVDs this last program
#		requires cdrecord-wrapper.sh and a valid license key.
#	NOV-2005, Paul Hick (UCSD/CASS)
#		Added -dev=auto option to detect device name of CD/DVD device.
#		Currently this will select the first device returned by
#		cdrecord -scanbus (so it may not have the desired effect if
#		more than one CD/DVD device is present).
#	DEC-2007, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#		Removed references to cdrecord-ProDVD. Now the scripts first
#		looks for wodim (available since FC7) or cdrecord.
#		Env vars CDWR and DVDWR are not used anymore. To add the 'dev'
#		switch the -dev keyword must now be explicitly set.
#-
iÿÿÿÿN(   t   startt   is_theret
   dict_entryt   run_cmdt   tombt   hide_envt   argsc   &      C   s<  d } t  | d t i d ƒ } t  | d d ƒ } t  | d d ƒ } t  | d d ƒ } t  | d d ƒ } t  | d	 d ƒ } t  | d
 d ƒ }	 t  | d d ƒ }
 t  | d d ƒ } t  | d d ƒ } t  | d d ƒ } t  | d d ƒ } t  | d d ƒ } t  | d d ƒ } t | ƒ } d d g | } | d j ot d d ƒ } | d j o t d d ƒ } n | d j o d } | d GH| Sn | i d ƒ d } d } xf t | d d ƒ i d ƒ D]H } | d d !d j o. | i d ƒ \ } } } d | j o Pqq»q»W| d j o d } | d | d  GH| Sn | d! | d" | GHn | d j o t  t i | d# d ƒ } n | d j o t  t i | d$ d% ƒ } n | d j o d& | } n d } d } | or d' i |  ƒ } t i i | d( ƒ } t d) | d' | | ƒ d* t i | ƒ i	 } | G| Gd+ Gt
 | ƒ Gd, GHnÆ t |  ƒ d j o  |  d } t i i | ƒ } n“ d- } d } xp |  D]h } | t | ƒ d d. j o | d t | ƒ d !} n | } | d' t i i | ƒ d d/ | 7} q†W| d t | ƒ !} | o d } | } nt t i i | d0 ƒ } | d1 GHd2 } |
 p | d3 7} n |	 o | d4 7} n t d5 | | d6 | d' | | ƒ | o t i | ƒ n t i i | ƒ p d } | d7 t | ƒ } n"| o d } | d8 t | ƒ } nýd* t i | ƒ i	 }  d } | d j oP t d d ƒ } | d j o t d d ƒ } n | d j o d } d } q·nB | | d9 GHt d: | d ƒ } | d j o d; | } d } n | i d ƒ d } | d j od< | g | }! g  }" | p |" i d< ƒ n |" i | d= d> g ƒ | d j o |" i d? | ƒ n | d j o |" i d@ | ƒ n | d j o |" i | ƒ n |" i | ƒ t i t i |! |" ƒ } | d j oô | dA } xñ t | d ƒ D]Ñ }# | | GHd }$ x¹ |$ o± t dB | dC |# dD ƒ }% t i t i |! |" ƒ } | d j o d }$ | dE |# dD } qâ| dF | GHt dG |# dD ƒ }$ |$ i ƒ  d dH j }$ |$ p dI |# dD } qâqâWqÊWn dF | } | d j o | p t i | ƒ qÖqÚn d | G|  Gd+ Gt
 |  ƒ Gd, GH| | GH| d j o) t dJ | dK | dL | dM d ƒ n | S(N   Ns
   burndisk, t   tempdirt   TUBt   make_tari    t   make_dvdt   make_imgt   nosudot   verboset   linkst   nojoliett   speedt    t   devt   modet   emailt   exet   countt   1t   CDt   DVDt   autos   which wodim 2> /dev/nulls   which cdrecord 2> /dev/nulli   s    unable to find wodim or cdrecords   
s    -scanbus 2> /dev/nulls   	t   *s   unable to determine s    writers   with s    = t   SPEEDt   MODEt   saot   -t    s   burndisk.tar.gzs
   tar -czvf s   %ds   bytes (s   MB)
s   -graft-pointst   /s   /=s   burndisk.imgs   mkisofs ...s    -Rt   Js    -fs   mkisofs s    -quiet -o s    image does not exist: s
    image is s    ...s   which s   unable to find t   sudos   -ejects   -datas   dev=s   speed=s    burn finished OKs   insert blank s    for disk %d and hit any keyi   s    burn of disk %d finished OKs"   something wrong? Return status: %ds!   try disk %d again (yes/no) ? [no]t   ys   disk %d discontinueds   echo "s	   " | mail s    -s"t   "(   R   t   ost   environt   intR   t   splitt   joint   patht   statt   st_sizeR   t   lent   isfilet   removet   existsR   t   appendt   extendt   spawnvpt   P_WAITt   ranget	   raw_inputt   lower(&   t   alldirst	   burn_argst   sayR   R	   R
   R   R   R   R   R   R   R   R   R   R   R   t   diskt   burncmdt   statust   tmpt   blankt   namet   graftt   is_imaget   top_dirt   archivet   sizet   subdirt   cd_imgt   optionst   messaget   cd_sizet   cmdR   t   nt	   try_againt   dummy(    (    s   ./burndisk.pyt   burndisk   s   	 **
 *
	%

""
 	

	)t   __main__i   s5   Syntax: burndisk [-dvd] <directory1 <directory2 ..> >R	   s   -tarR
   s   -dvdR   s   -imgR   s   -nosudoR   s   -verboseR   s   -temp=R   s   -count=R   s   -speed=R   s   -dev=R   s   -mode=R   s   -email=R   s   -exe=R   s	   -nojolietR   s   -links(   t   __doc__R&   t   syst   tinyR    R   R   R   R   R   R   RP   t   __name__t   argvR9   R.   t   exitt   dictR:   (    (    (    s   ./burndisk.pys   <module>‹   s6   4	Û