³ò
KáýIc           @   sr	  d  Z  d d k Z d d k Z d d k Z d d k Z d d k l Z d d k l Z l Z l	 Z	 l
 Z
 l Z l Z d d k l Z e i ƒ  d „  Z d „  Z d „  Z e d	 j o¸e e i ƒ Z e e ƒ Z e
 d
 e i ƒ Z e
 d e i ƒ Z e
 d e i ƒ Z e
 d e i ƒ Z e
 d e i ƒ Z e
 d e i ƒ Z e	 d e i ƒ Z e	 d e i ƒ Z e	 d e i ƒ Z e
 d e i ƒ Z  e  p( e d d ƒ d j o e i! ƒ  q´n e d j Z" e" o* d d k# Z# e# i# ƒ  e$ e ƒ d Z% n e	 d e i ƒ Z& e& d j o
 d Z& n e
 d e i ƒ Z' e
 d e i ƒ Z( e
 d e i ƒ Z) e
 d e i ƒ Z* 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	 d0 e i ƒ f d1 e	 d2 e i ƒ f g ƒ Z, e	 d3 e i ƒ Z- e	 d4 e i ƒ Z. e	 d5 e i ƒ Z/ e d j oi e d Z0 e0 d6 j o e i1 ƒ  Z0 n e d7 j o+ e d7 Z2 e2 d6 j o e i1 ƒ  Z2 qq:e0 Z2 n% e3 d8 ƒ Z0 e i4 i5 e0 ƒ Z0 e0 Z2 e i4 i6 e0 ƒ p d9 Ge0 GHe i! d ƒ n e i4 i6 e2 ƒ p d: Ge2 GHe i! d ƒ n e- d j o e' o
 d; Z- q¼d< Z- n e. d j o e' o
 d= Z. qäd> Z. n e/ d j o
 d? Z/ n e e- ƒ Z- e e. ƒ Z. e e/ ƒ Z/ e i4 i7 e0 e& ƒ Z& e i e& ƒ Z8 e e8 ƒ d@ j o dA Ge& GHe i! ƒ  n e o e8 i ƒ  n e0 e _9 e i: ƒ  Z; dB Z< d@ Z= e pð e i> e; ƒ e d j oW e i4 i? e ƒ o@ e i@ e iA dC dC e e; ƒ e< e dD e iB e ƒ iC ƒ Z< qn e d j on e i e ƒ oZ xW e i e ƒ D]B ZD e i@ e iA dC dC eD e; ƒ e< e dD e iB eD ƒ iC ƒ Z< qHWq–qšn x)e8 D]!ZD e" oR e iB eD ƒ iE e% j o5 dE Ge eD ƒ GHdF Ge iB eD ƒ iE e% dG GdH GHPq n e dD e iB eD ƒ iC ƒ ZF e< eF ZG eG e- j o e o Pn d Z= q¡e= p eF e/ j od dI Ge eD ƒ GeH eF dJ ƒ GdK GHe p3 e iI eD e i4 i7 e; e i4 iJ eD ƒ d ƒ ƒ n eG Z< q¡q¡We p dL Ge e; ƒ GHn e< e. j  oP dM GeH e< dN ƒ GdO Ge- GdP GdQ Ge. GdP GdR GHe p e e; e0 e) d@ ƒ q`	n$e o" dM GeH e< dN ƒ GdO Ge- GdP GHnû dM GeH e< dN ƒ GdO Ge- GdP GHy e e; g e, ƒ ZK Wn% e e; e0 e) d@ ƒ dS GHd ZK nŸ Xe( o5 e o e e; e2 e) e ƒ q`	e e; e0 e) d@ ƒ nc eK d@ j o e e; e0 e) d@ ƒ n? e e e; e) e* ƒ e o e e; e) ƒ n e e; e2 e) e ƒ e i! ƒ  n d S(T   sð  
#+
# NAME:
#	burnfiles
# PURPOSE:
#	Burn DVD from L1A files
# CATEGORY:
#	gen/python
# CALLING SEQUENCE:
#	burnfiles <source> [<destination>]
# INPUTS:
#	<source>		fully-qualified directory
#				source directory with files to be put on CD/DVD
#	<destination>		fully-qualified directory
#				directory where files are moved after
#				the CD/DVD has been burned.
#				If omitted then this is the same as <source>.
#				Files are moved to <destination> only if the CD/DVD
#				burned succesfully. If -test is set then files
#				stay in <source>; if burning fails or -img is set
#				then files are moved back to <source>.
# OPTIONAL INPUTS:
#	-pattern=pattern	file name wildcard
#				default: *
#	-sort			sort files before selecting files
#	-dvd			burn a DVD (instead of a CD)
#	-img			make the CD image file, but don't burn CD/DVD
#	-nosudo			launch cdrecord without using sudo
#	-remove			remove the files after burning the CD/DVD
#				(ignored if -test or -img is set)
#	-verbose		display messages
#	-temp=temp		location where CD image is created
#				default: $TUB
#	-count=count		number of CD/DVD copies
#	-speed=speed		write speed (default is different for CD and DVD
#				and is set in burndisk.py)
#	-dev=dev		SCSI dev id for the CD/DVD writer; default: 0,0,0
#	-email=email		comma-separated list of email addresses to which
#				to send an email upon completion.
#	-test			test run
#	-before			number of days
#				if a file is found with a modification time
#				more than 'before' days before the current time
#				than file selection is terminated.
#
#	Size can be specified with postfix G or GB for gigabyte, M or MB for
#	megabyte, k or kB for kilobyte or just bytes with no postfix.
#
#	-max_disk_size=max_disk_size
#				files are selected until the combined
#				file size is upto max_disk_size bytes.
#				DVD default: 4500MB
#				CD  default:  650MB
#				(these values still need tuning)
#	-min_disk_size=min_disk_size
#				the combined file size must be at least
#				this many bytes or no disk is burned.
#				DVD default: 4200MB
#				CD  default:  600MB
#	-min_file_size=min_file_size
#				default: 500kB
#				see PROCEDURE
#	-logfile=logfile	log file where content of CD/DVD is logged.
#				A list of file names is appened to <logfile>
#				only if burning of CD/DVD was succesfull.
#	-checksum=checksumfile	checksum filename or filename wildcard to copy to the CD/DVD.
#	-timestamp		add timestamp to file name in logfile
#	-unblock		skips test for running instances of l1a.py in ftp mode.
# OUTPUTS:
#	CD/DVD (maybe)
# CALLS:
#	burndisk
# SEE ALSO:
# EXAMPLE:
#	burnfiles.py -dvd -count=2 /storage/temp
# PROCEDURE:
#	Selected files are moved to a temporary subdirectory of
#	<directory>
#
#	If -remove IS set then the temporary directory and its content are
#	deleted after burning the CD/DVD.
#	If -remove is NOT set then the files are moved back
#
#	The CD img file is created in $temp and is also deleted after
#	processing (see href=burndisk=).
# MODIFICATION HISTORY:
#	FEB-2004, Paul Hick (UCSD/CASS)
#	MAR-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#		Added -speed, -verbose, -dev, -clean keywords.
#		Changed to dictionary for list of args for burndisk
#		Lowered max_disk_size for DVDs.
#		Fixed bug for non-existent log file.
#	APR-2004, Paul Hick (UCSD/CASS)
#		Changed min_file_size default from 100kB to 500kB.
#	MAY-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#		Added -before keyword
#	JUN-2004, Paul Hick (UCSD/CASS)
#		Added -noblock keyword
#	AUG-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#		Replace -sudo by -nosudo.
#-
iÿÿÿÿN(   t   datetime(   t   hide_envt   argst   startt   is_theret   count_instancest   tomb(   t   burndiskc         C   s   xS t  i |  ƒ D]B } t  i i |  | ƒ } | o d Gt | ƒ GHn t  i | ƒ q Wt  i |  ƒ | o d Gt |  ƒ GHn d  S(   Nt   remove(   t   ost   listdirt   patht   joinR   R   t   rmdir(   t   burndirt   verboset   filet   tmp(    (    s   burnfiles.pyt   burnfiles_removep   s     c         C   sê   | o	 d GHn x’ t  i |  ƒ D] } t  i i |  | ƒ } t  i i | | ƒ } | o d Gt | ƒ GHn | o  t  i t  i d d | | ƒ q  t  i | | ƒ q  W| o d Gt | ƒ GHn t  i |  ƒ | o d Gt |  ƒ GHn d  S(   Ns   hard move across devices
s      t   mvs   -->R   (	   R	   R
   R   R   R   t   spawnlpt   P_WAITt   renameR   (   R   t   sourceR   t   hardmoveR   t   srcet   dest(    (    s   burnfiles.pyt   burnfiles_move€   s"    	  c   
   
   C   sü  t  i ƒ  } d | i d | i d | i d | i d | i d | i } |  d j o›t i	 i
 |  ƒ o( t |  d ƒ i ƒ  } | i d ƒ } n g  } d } x; | D]3 } | i d	 ƒ d
 j o | i d ƒ d } q« q« Wt | ƒ d } d G| Gd G| GHd d | d | d g } t i | ƒ } | oV xS t t | ƒ ƒ D]; }	 | |	 d t i t i	 i | | |	 ƒ ƒ i | |	 <qGWn | i | ƒ t i	 i
 |  ƒ o' t |  d ƒ i d i | ƒ d ƒ qøt |  d ƒ i d i | ƒ d ƒ n d  S(   Ns   %ds   /%02ds    %02ds   :%02dt    t   rs   
i    t   /iÿÿÿÿt    i   t   IDs    Times    %dt   at   w(   R    t   nowt   yeart   montht   dayt   hourt   minutet   secondR	   R   t   existst   opent   readt   splitt   findt   intR
   t   ranget   lent   statR   t   st_mtimet   extendt   write(
   t   logfileR   R   t	   timestampt   tt   contentt   ndvdR   t   lstt   i(    (    s   burnfiles.pyt   burnfiles_log˜   s2    D  =''t   __main__s   -sorts   -moves   -removes	   -hardmoves   -tests   -cleans	   -logfile=s   -before=s
   -checksum=s   -unblocks   l1a.py coreftp.plh.af.mili   R   i€Q s	   -pattern=t   *s   -dvds   -imgs   -verboses
   -timestampt   make_tars   -tart   make_dvdt   make_imgt   nosudos   -nosudoR   t   tempdirs   -temp=t   counts   -count=t   speeds   -speed=t   devs   -dev=t   modes   -mode=t   emails   -email=t   exes   -exe=s   -max_disk_size=s   -min_disk_size=s   -min_file_size=t   .i   s   Directory: s   source is not a directory: s    destination is not a directory: t   4489MBt   650MBt   4200MBt   600MBt   500kBi    s   no files found matchingg        t   cps   %ds       Too recent:s       Release in:i  t   hourss      i   t   MBs   -->s   
Total size isi   R   s   MB
s   Total size is less thans:   No disk was burned. Override with -min_disk_size=<value>.
s8   burnfiles, problem in burndisk. cdrecord key expired ???(L   t   __doc__t   sysR	   t   tempfilet   globR    t   tinyR   R   R   R   R   R   R   R#   R   R   R=   t   __name__t   argvt   argR1   t   nargt   sortt   moveR   R   t   testt   cleanR6   t   beforet   checksumt   unblockt   exitt
   check_timet   timeR/   t   cutoff_timet   patternRA   RB   R   R7   t   dictt	   burn_argst   max_disk_sizet   min_disk_sizet   min_file_sizeR   t   getcwdt   destinationt	   raw_inputR   t
   expandvarst   isdirR   t	   file_listRD   t   mktempR   t   sizet   max_flagt   mkdirR*   R   R   R2   t   st_sizeR   R3   t	   file_sizet   new_sizet   roundR   R-   t   status(    (    (    s   burnfiles.pys   <module>g   s,  0.
			,


		




		( 0 !	

 3"
