³ò
»\<Kc           @   sç  d  Z  d d k Z d d k Z d d k Z d d k Z e i d e _ d d k l Z l	 Z	 l
 Z
 l Z l Z l Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z e d j oe i i e i d ƒ d Z e d Z e i i d ƒ o e d GHe i ƒ  n e	 d e i ƒ oÅ e i i e i i  e i d d ƒ ƒ o& e i i e i i  e i d d ƒ ƒ o e d GHnY e d GHe
 d e i ƒ Z! e! d j o0 d e! d e i d d  Z" e e" d ƒ Z# n e i ƒ  n e
 d! e i ƒ a$ t$ d j o e d" GHe i ƒ  n e i i% t$ ƒ o! e d# Ge t$ ƒ GHe i ƒ  n e
 d$ e i ƒ Z& e& d j o
 d% Z& n e	 d& e i ƒ Z' e' oW e( Z) e	 d' e i ƒ Z* e* o3 e d( e i d) d ƒ d j o e i ƒ  n n n¦ e e i ƒ Z e+ e ƒ d j Z) e	 d' e i ƒ Z* e) o0 e d* e d d ƒ d j o e i ƒ  n n< e* o3 e d( e i d) d ƒ d j o e i ƒ  n n e
 d+ e i ƒ Z, e, d j o e i d, Z, n e, d- j o9 e i i e, ƒ o! e d. e e, ƒ GHe i ƒ  n n e
 d/ e i ƒ Z- e- d j o e- g  j n e- i d0 ƒ Z- e	 d1 e i ƒ Z. e	 d2 e i ƒ Z/ e	 d3 e i ƒ Z0 e	 d' e i ƒ Z* e) o4 e e i e& e- e/ e, e* ƒ Z1 e e1 e& g  ƒ Z1 næ e' o. e e i e& e- e/ ƒ Z1 e e1 e& g  ƒ Z1 n± e. o e e i2 e& ƒ e& e- ƒ Z1 n‹ g  Z1 x e i2 e& ƒ D]p Z3 e i i4 e3 ƒ d d4 j oM e+ e- ƒ d j p e- i5 e3 ƒ d j o  e1 i6 e i i  e& e3 ƒ ƒ n n qKWe/ o% e g  ƒ Z7 e d e1 e7 d ƒ Z1 n e+ e1 ƒ d j o e d5 e& GHn´ e e1 ƒ Z7 e0 o‡ e
 d6 e i ƒ Z8 e8 d j od e i i e8 ƒ oD x= e1 D]5 Z3 e i9 e3 e i i  e8 e i i e3 ƒ d ƒ ƒ q\Wn
 d7 Ge8 GHn n e e i e i: e1 e, ƒ e d8 GHe i e+ e1 ƒ ƒ n d S(9   s  
#+
# NAME:
#	l1a
# PURPOSE:
#	Script for processing the SMEI L1A data
# CATEGORY:
#	smei/gen/python
# CALLING SEQUENCE:
#	l1a.py <site> <rdir> <user> <password>
# INPUTS:
#	If a remote server is specified an attempt at downloading by (s)ftp is made:
#
#	<site>		remote server
#	<rdir>		directory on remote site with L1A files
#	<user>		remote user
#	<password>	password
# OPTIONAL INPUT PARAMETERS:
#	-source=source	default: /mnt/cdrom
#			source directory to look for *.buf or *.buf.gz files.
#			For ftp this is also the directory where downloaded
#			*.buf.gz are put (write access to the source directory
#			is needed)
#			If L1A files are retrieved from a local L1A mirror
#			(-mirror is set) then this is the directory where the
#			L1A files taken from the mirror are copied to.
#	-destination=destination
#			destination directory for CCD frames:
#			default: $SMEIDB
#
#	-gunzip		look for gzipped *.buf.gz files and unzip them,
#			instead of looking for *.buf files
#	-maxftp=maxftp	maximum number of l1a*.buf.gz files downloaded by ftp,
#			or copied from local L1A mirror (if -mirror is set)
#
#	-nounpack	only download and unzip L1A files. Don't unpack them.
#			The names of successfully downloaded and unzipped files are
#			WILL BE ADDED to the list of locally processed L1A files.
#	-detach		only used for ftp downloads.
#			If set then an L1A file is unpacked immediately after
#			download is complete, in parallel with the download of the
#			next L1A file. If not set, all L1A files are downloaded
#			first, and are then unpacked in a single operation.
#
#	-l1a=l1a	name of specific L1A file to be processed
#	-all_l1a	by default only L1A files are processed that are not yet
#			listed in file 'file_list' (under the assumption that
#			these have already been dealt with). Set this keyword to
#			unconditionally process L1A files.
#	-file_list=file_list
#			fully-qualified name of file with names of already processed
#			L1A files. The file must exist already, so if necessary
#			create an empty one before running this script.
#	-nowrite	suppress writing of CCD frames (useful for testing only)
#	-overwrite	force ovewriting of existing CCD frames.
#			By default frames are not written to drive if a file for the
#			frame already exists. This is currently the primary control
#			for picking up either the first or second telemetry dump
#			(setting -overwrite speeds up processing by a factor 2).
#	-nodups		if set then an attempt is made to remove duplicate frames
#			before starting to write individual frames.
#	-zipdir		zip CCD frames when leaving subdirectory
#	-remove		delete *.buf files after processing
#	-move=move	move *.buf files to directory 'move' after processing
#	-noclones	skip clone frames (see href=smei_buf_prep=)
#	-unblock	skips test for running instances of l1a.py in ftp mode.
#	-nic		write .nic files instead of .fts files (OBSOLETE)
#	-kblob		buffer size for reading remote L1A files for sftp.
#			default is 64 kB. If set to zero the file is downloaded
#			with a single read (this is very slow for some reason).
#	-sftp		download using sftp instead of ftp.
#	-mirror		looks for L1A files in locally maintained mirror of
#			remote L1A files (instead of downloading by ftp or sftp)
# OUTPUTS:
#	Updated data in <destination>
#	Exit code is number of L1A files processed
# CALLS:
#	l1a_near, l1a_ftp, l1a_idl, l1a_redo, l1a_gunzip
# SEE ALSO:
#	smei_buf
# PROCEDURE:
# >	Only one instance of the script is allowed to run.
# >	The list of L1A files found locally or (when using ftp) on the remote site
#	are compared against the list of l1a file names in file 'file_list'
#	Only files not on this local list will be downloaded. Override this
#	behaviour using keyword all_l1a.
# MODIFICATION HISTORY:
#	MAR-2003, Paul Hick (UCSD/CASS)
#	APR-2003, Paul Hick (UCSD/CASS)
#		Added -overwrite, -nodups, -zipdir, -remove keywords.
#	OCT-2003, Paul Hick (UCSD/CASS)
#		Added -alive keyword.
#	FEB-2004, Paul Hick (UCSD/CASS)
#		Added -nounpack keyword.
#		Added -noclones keyword to l1a_idl
#		Added -move keyword
#	MAR-2004, Paul Hick (UCSD/CASS)
#		Added keyword 'file_list' instead of hardcoding file name $HOME/l1a_files.txt.
#	FEB-2005, Paul Hick (UCSD/CASS)
#		Removed -sparseftp option (never used it).
#		Added -sftp switch to use sftp instead of plain ftp (requires
#		packages paramiko and pycrypto).
#		Removed all references to the module string.
#	SEP-2005, Paul Hick (UCSD/CASS)
#		After installing Paramiko 1.4 on 64-bit AMD (running Fedora Core)
#		download would fail for every other file (first downloaded OK,
#		second failed, third OK, etc.). Modified code to open a new
#		ssh session for each download. Also introduced kblob keyword.
#	DEC-2005, Paul Hick (UCSD/CASS)
#		Added keyword -mirror to be able to process L1A files from a
#		locally-maintained mirror of the L1A data base.
#	FEB-2008, Paul Hick (UCSD/CASS)
#		Added check for existence of env var $L1A.
#		Added check to prevent two copies of l1a.py to run at the
#		same time.
#	DEC-2009, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#		Exit code now is number of L1A files processed (was always zero)
#-
iÿÿÿÿNt   TUB(   t   hide_envt   is_theret   startt   run_cmdt   argst   count_instancesc         C   s[  d } t  i i t ƒ o% t t d ƒ i ƒ  } | i ƒ  } n g  } t |  ƒ d j o | d t | ƒ GHnê xh |  D]` } t  i i | ƒ \ } } | d j o
 | } n t  i i | ƒ \ } } | i	 | i
 ƒ  ƒ qu W| i ƒ  g  } xB | D]: } | i | ƒ d j o | i	 | ƒ qð | d | GHqð W| } t t d ƒ i d i | ƒ d ƒ | S(	   sC  
#+
# NAME:
#	l1a_near
# PURPOSE:
#	Function to update / retrieve list of already processed L1A files
# CALLING SEQUENCE:
#	near_list = l1a_near( buf_files )
# INPUTS:
#	buf_files		list of file names to be added to the list of already
#					processed L1A files stored in file 'file_list'
#					(this may be an empty list)
# OUTPUTS:
#	near_list		list of processed L1A files currently
# PROCEDURE:
#	The file names (name and type only) of all processed files are stored
#	in the ascii file 'file_list
# MODIFICATION HISTORY:
#	APR-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#-
	s
   l1a_near, t   ri    s   %d local L1A filess   .gzs
   duplicate t   ws   
(   t   ost   patht   existst	   file_listt   opent   readt   splitt   lent   splitextt   appendt   lowert   sortt   countt   writet   join(   t	   buf_filest   sayt	   near_listt   buf_filet   tmp_filet   dropt	   new_files(    (    s   ./l1a.pyt   l1a_near~   s.     
 #c   
      C   s  d } g  } xÏ | D]Ç } |  o3 t  i i | ƒ \ } } | d j o
 | } qk n t  i i | ƒ \ } } | i ƒ  } | i | ƒ }	 | o" |	 d j o | i | ƒ qÚ q |	 d j o | | d GHq | i | ƒ q W|  o | d t | ƒ GHn | d t | ƒ GH| S(   s¯  
#+
# NAME:
#	l1a_redo
# PURPOSE:
#	Check list of available files against list of files to be reprocessed.
# CALLING SEQUENCE:
#	list = l1a_redo( byftp, buf_files, redo_list, negate )
# INPUTS:
#	byftp	if set, then buf_files is a list of *.buf.gz files (obtained from ftp nlist cmd)
#		if not set, then buf_files is a list of *.buf files available locally.
#
#	buf_files
#		byftp set: list of *.buf.gz files (file names, plus extension only)
#		byftp not set: list of *.buf files (fully-qualified file names)
#
#	redo_list
#		list of *.buf files (only file name, plus extension)
#
#	negate	negate set: return subset of buf_files NOT present in redo_list
#		negate NOT set: return subset of buf_files also present in redo_list
# OUTPUTS:
#	list	list of files will be a subset of buf_files.
# PROCEDURE:
#	Compares entries in buf_files against entries in redo_list.
# MODIFICATION HISTORY:
#	APR-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#-
	s
   l1a_redo, s   .gzi    s    skippeds   %d remote L1A files to processs   %d local L1A files to process(   R	   R
   R   R   R   R   R   R   (
   t   byftpR   t	   redo_listt   negateR   t
   redo_filesR   R   R   R   (    (    s   ./l1a.pyt   l1a_redoÂ   s(     c   
      C   s/  d } g  } x|  D]} t  i i | ƒ \ } } | d j } | o t  i i | ƒ \ } } n | d j oº t | ƒ d j p | i | ƒ d j o t  i i | | ƒ } | t | ƒ GH| o: t  i t  i d d d | ƒ }	 t  i i | ƒ \ } } n t  i i	 | ƒ o | i
 | ƒ q#q'q q W| S(   sÔ  
#+
# NAME:
#	l1a_gunzip
# PURPOSE:
#	Unzip list of *.buf.gz files (usually files downloaded from Hanscom)
# CALLING SEQUENCE:
#	buf_files = l1a_gunzip(gz_list, ldir, redo_list)
# INPUTS:
#	gz_list		list of *.buf.gz files (only file name, plus extension)
#	ldir		directory where *.buf.gz files are located
#	redo_list	only entries in gz_list also on redo_list are processed
#			(if redo_list is empty all files in gz_list are processed)
# OUTPUTS:
#	buf_files	list of successfully unzipped *.buf files
#			(fully-qualified file names, located in ldir)
# PROCEDURE:
#	Loops over all files in far_list, spawning gunzip for each file individually.
# MODIFICATION HISTORY:
#	APR-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#-
	s   l1a_gunzip, s   .gzs   .bufi    t   gunzips   -f(   R	   R
   R   R   R   R   R   t   spawnlpt   P_WAITt   isfileR   (
   t   gz_listt   ldirR!   R   R   t   gz_fileR   t   extR%   t   sts(    (    s   ./l1a.pyt
   l1a_gunzip	  s"     #)c         C   sò   t  i i t  i d d ƒ } t  i i | ƒ } | o¹ t | d ƒ i ƒ  } | i d ƒ } t | d ƒ d } d t	 ƒ  } t
 i d ƒ } t | d	 ƒ i d
 | d d | d d ƒ t  i |  d d d | ƒ t | d	 ƒ i | d ƒ n | S(   sÒ   
#+
# NAME:
#	l1a_summary
# PURPOSE:
# CALLING SEQUENCE:
#	status = l1a_summary( wait )
# INPUTS:
# OUTPUTS:
#	(none)
# PROCEDURE:
# MODIFICATION HISTORY:
#	JUL-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#-
	t   HOMEs   l1a_doy_summary.txtR   s   
i    i   s   %(doy)ds   .proR   s   smei_frm_summary, timeset(doy=s)   ,hr=[0,24]), dest=getenv("TUB"), /silent
s   tmp = do_file(/delete, "s   ", /silent)
s   exit
t   idls   -quiet(   R	   R
   R   t   environR   R   R   R   t   intt   varst   tempfilet   mktempR   R&   (   t   waitt   doy_summaryt   statust   doyt   main_pro(    (    s   ./l1a.pyt   l1a_summary9  s    c         C   s^   t  i |  ƒ d } t  i | ƒ d } | | j o
 d } n | | j o
 d } n d } | S(   Ni   i   i    iÿÿÿÿ(   R	   t   stat(   t   f1t   f2t   p1t   p2R-   (    (    s   ./l1a.pyt	   l1a_mtimeh  s    

c         C   s  d } t  d |  ƒ } t  d |  ƒ o
 d } n t  d |  ƒ } t  d |  ƒ } t  d |  ƒ } t  d |  ƒ }	 t  d	 |  ƒ }
 t  d
 |  ƒ } t  d t i ƒ } t  d t i ƒ } t d t i ƒ } | d j o* t i i | ƒ p d G| GHd } qö n t d |  ƒ } | d j o
 d } n t i d ƒ } t i d ƒ } t	 | d ƒ i
 d | d d | d d | d d ƒ t	 | d ƒ } | i
 | d ƒ | i
 | d ƒ | i
 d d g | d ƒ | i
 d d d g | d ƒ | i
 d  d! g | d ƒ | d j o | i
 d d g | d ƒ n | i
 | d ƒ | i
 d d g |	 d ƒ | i
 d" d# g |
 d ƒ | i
 d$ d% g | d ƒ | i
 d& d' g | d ƒ | o | i t ƒ n | i ƒ  | i
 d i | ƒ d ƒ | i ƒ  t i | d( d( d) | ƒ d* S(+   s.  
#+
# NAME:
#	l1a_idl
# PURPOSE:
#	Unpack *.buf files writing separate files for each frame
# CALLING SEQUENCE:
#	l1a_idl( sys_argv, wait, buf_files, ddir)
# INPUTS:
#	buf_files	list of *.buf files or *.buf.gz (fully-qualified names)
#			Must have at least one element.
#	ddir		destination directory
# OUTPUTS:
#	(none)
# PROCEDURE:
# >	Creates main program for starting up the IDL procedure smei_buf
# >	Writes ascii file with input information for smei_buf,
# >	Then spawns the main IDL program
# >	Both the IDL main program and the ascii file will be deleted by smei_buf
# MODIFICATION HISTORY:
#	APR-2003, Paul Hick (UCSD/CASS)
#	FEB-2004, Paul Hick (UCSD/CASS)
#		Added -noclones keyword
#	MAR-2005, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#		Added -nic keyword. By default Fits files are written to disk.
#-
	s	   l1a_idl, s   -nodupss   -nowritei   s
   -overwrites   -zipdirs   -removes	   -nocloness   -silents   -mtimes   -nics   -statuss   -move=t    s   non-existent directory:s   -email=t   no_emails   .pros   .txtR   s   smei_buf, "s   "
s   tmp = do_file(/delete, "s   ", /silent)
s   exit
s   
t   keept   removes   skip existings   overwrite existings   do not writet   rawt   gzipt   loudt   silents   .ftss   .nict   blindR8   R0   s   -quietN(   R   t   syst   argvR   R	   R
   t   isdirR4   R5   R   R   R   RA   R   t   closeR&   (   t   sys_argvR6   R   t   ddirR   t   nodupst	   overwritet   zipdirRE   t   noclonesRI   t   mtimet   nicR8   t   movetot   emailR:   t   tmp_listt   iu(    (    s   ./l1a.pyt   l1a_idlv  sZ    
	
#

c   	   
   C   s~  t  i d ƒ } t | d ƒ } | i d | d ƒ x# | D] } | i d | d ƒ q: W| i d ƒ | i ƒ  t d | d |  d	 ƒ } t i | ƒ | i d ƒ } g  } x˜ | D] } | i	 d
 ƒ d j ot | i d ƒ } | i
 ƒ  | d d d !d | d d d !d | d d d !| d d d !| d <| i | ƒ q´ q´ W| i ƒ  g  } x | D] } | i | d	 ƒ q_W| S(   Ns   .ftpR   s   cd s   
s   modtime s   quit
s   cat s    | ftp i   t   L1A_i    s   	i   i
   t   /i   i   i   i   (   R4   R5   R   R   RN   R   R	   RE   R   t   findt   reverseR   R   (	   t   sitet   foldert   far_listt
   ftp_scriptRZ   t   xt   lstt   gmtt   y(    (    s   ./l1a.pyt   l1a_ftp_modtimeí  s0     
 	
J
 c   -      C   ss	  d } t  d t i ƒ } | o6 t d |  ƒ } | d j o
 d } qU t | ƒ } n t |  ƒ }	 g  }
 t i i t i	 d d ƒ } d } t i i
 | ƒ ow t | d ƒ i ƒ  } | i d	 ƒ } xP | D]D } | i ƒ  } | i |	 d
 ƒ d j o | d } | d } qÇ qÇ Wn | d j o< t |	 ƒ d j o | d GH|
 Sn |	 d } |	 d } n | d | d |	 d
 d |	 d GH| pH t t i i |	 d ƒ d
 d |	 d
 d ƒ d j o t i ƒ  qÐn | oœd d k } d d k } t i i t i	 d d d ƒ } t | d ƒ } xŠ | D]] } | i d ƒ } t | ƒ d j o q$n | \ } } } | i |	 d
 ƒ d j o Pq$q$W| d |	 d
 GH| i ƒ  t i ƒ  | i ƒ  | i d t i | ƒ ƒ } | i |	 d
 ƒ } | i d | d | d | ƒ | i ƒ  } | i d |	 d d ƒ | i ƒ  i ƒ  } | i ƒ  | i ƒ  | i d	 ƒ } | d t | ƒ d
 !} nN d d  k l } | |	 d
 | | ƒ } | i  |	 d ƒ | i! ƒ  } | i ƒ  g  } xÄ | D]¼ } t i i" | ƒ \ }  }! |! d! j o& t i i" |  ƒ \ }  }! |! d! }! n |! d" j o$ t | ƒ d# j o | i# | ƒ qÍ|! d$ j o$ t | ƒ d% j o | i# | ƒ qÍd& | GHqÍW| } t | ƒ d j o t$ d
 | | d ƒ } n | p% t% g  ƒ } t$ d
 | | d
 ƒ } n t | ƒ d j o | d' GHnet  d( |  ƒ }" t d) |  ƒ }# |# d j o
 d* }# n t& |# ƒ }# | i' ƒ  t | ƒ |# j o | d |# !} n t  d+ |  ƒ }$ |$ o t( |	 d
 |	 d | ƒ } n | p+ | |	 d
 | | ƒ } | i  |	 d ƒ n xc| D][} | i ƒ  }% t i i | | i) ƒ  ƒ }& y| oÏ| i |	 d
 ƒ } | i d | d | d | ƒ | i* ƒ  } | i t i i |	 d | ƒ d d ƒ } | i+ ƒ  i, }' | | d, t- | ƒ d- |' GH| d j oF | i ƒ  }( | i ƒ  | i ƒ  t |( ƒ }) t |& d. ƒ i. |( ƒ n” | d/ }* d }) t |& d. ƒ }+ | i |* ƒ }( xD t |( ƒ d j o0 |+ i. |( ƒ |) t |( ƒ }) | i |* ƒ }( q3W|+ i ƒ  | i ƒ  | i ƒ  |) |' j o= | i ƒ  |% }% |) d0 }) d1 |) d0 |% d2 |) |% f }, q&d3 | }, n: | | d, t- | ƒ GH| i/ d4 | t |& d. ƒ i. ƒ }, Wnf | o | i ƒ  n d5 | GHt i0 |& ƒ t% |& g ƒ } d6 d7 |& d	 d8 d9 t1 d	 d: GHqçX| |, GH| o |, i d; ƒ d j p" | ow |, d< j p |, d= j o] |" o/ |& g }& t% |& ƒ } t2 |  t i3 |& | ƒ qB	t i i |& ƒ d
 }& |
 i# |& ƒ qçt i0 |& ƒ qçW| p | i ƒ  n |" o | d> GHn |
 S(?   sÚ  
#+
# NAME:
#	l1a_ftp
# PURPOSE:
#	Download .buf.gz files
# CALLING SEQUENCE:
#	buf_files = l1a_ftp( sys_argv, ldir, redo_list, all_l1a, ddir, unblock )
# INPUTS:
#	sys_argv	command line list sys.argv
#			contains the info to log into the ftp site
#	ldir		local directory where to put the downloaded files
#	redo_list	list of l1a files to process
#			Only used if len(redo_list) != 0
#	all_l1a		if set, process all *.buf files
#			if not set, only *.buf files not processed locally yet will be
#			downloaded.
# OUTPUTS:
#	buf_files	list *.buf.gz to be processed further
#			if detach is set then the return value buf_files is an empty list.
# CALLS:
#	l1a_near, l1a_redo, l1a_idl
# PROCEDURE:
# > The presence of ftp-specific keywords -detach, -sparseft and -maxftp is tested
#	for inside this routine.
# MODIFICATION HISTORY:
#	APR-2003, Paul Hick (UCSD/CASS)
#	FEB-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#		Local L1A file names are now in lower case (l1a* instead of L1A*)
#-
	s	   l1a_ftp, s   -sftps   -kblob=RB   i@   R/   s   .netrcR   s   
i   i    i   i   s5   specify remote info (site, dir [, user and password])i   s   remote site: s   <*****>@t   :i   t    iÿÿÿÿNs   .ssht   known_hostss   no key for t   datat   hostkeyt   usernamet   passwords   cd s
   ; ls *.buf(   t   FTPs   .gzs   .buf.gzi!   s   .bufi   s   not downloading s$   no remote L1A files left to downloads   -detachs   -maxftp=t   5s   -mtimes    -> s    (%d bytes)t   wbi   g      @s,   sftp complete %.2f MB, %.2f hours, %.2f kB/sg      ¬@s$   local and remote size do not match, s   RETR s   exception on s   


s.   =================== WARNING =================
s0   Download interrupted. To force another download
s   remove entry from s0   =============================================


s   sftp completes   226 Transfer complete.s   226 File send OK.s   detached unpack finished(4   R   RK   RL   R   R2   R   R	   R
   R   R1   R   R   R   R   R   R   R   t   exitt   paramikot   timeR^   RN   t   RSAKeyt   base64t   decodestringt	   Transportt   connectt   open_sessiont   exec_commandt   makefilet   ftplibRp   t   cwdt   nlstR   R   R$   R   t   evalR   Rh   R   t   open_sftp_clientR<   t   st_sizeR   R   t
   retrbinaryRE   R   R[   t   P_NOWAIT(-   RO   R*   R!   t   all_l1aRP   t   unblockR   t   use_sftpt   kblobRL   R   t   netrcRn   t   machinest   mt   partRo   Rt   Ru   t   keyfileRZ   t   linet   keylistt   hostst   keytypet   keyt   ftpt   sftpRb   Rp   R   t   far_gzipt   bufR,   t   detacht   maxftpRU   t   ttt	   near_gzipt   sz_farRl   t   sz_neart   blobt   juR-   (    (    s   ./l1a.pyt   l1a_ftp  s:   "
 
	
%6 	





   	
 (






 &	
		c      	   C   sA  d } t  |  ƒ } g  } t i | d ƒ } g  } xÄ | D]¼ }	 t i i |	 ƒ \ }
 } | d j o& t i i |
 ƒ \ }
 } | d } n | d j o$ t |	 ƒ d j o | i |	 ƒ q8 | d j o$ t |	 ƒ d j o | i |	 ƒ q8 d |	 GHq8 W| } t | ƒ d	 j o t d
 | | d	 ƒ } n | p% t g  ƒ } t d
 | | d
 ƒ } n t | ƒ d	 j o | d GHnÈ t	 d |  ƒ } | d j o
 d } n t
 | ƒ } | i ƒ  t | ƒ | j o | d	 | !} n xd | D]\ }	 |	 i ƒ  } t d t i i | d |	 ƒ d t i i | | ƒ d	 ƒ } | i | ƒ qÝW| S(   Ns   l1a_mirror, i   s   .gzs   .buf.gzi!   s   .bufi   s   not processing i    i   s   no L1A files left to processs   -maxftp=RB   Rq   s   cp -vp Rj   (   R   R	   t   listdirR
   R   R   R   R$   R   R   R   R   R   R   R   (   RO   R*   R!   R†   R   RL   R   Rb   R   R–   R—   R,   R™   R›   t   tmp(    (    s   ./l1a.pyt
   l1a_mirrorZ  sH       
 =t   __main__i    i   s   , t   L1As   env var L1A not defineds   -alivet   SMEIDB1t   2003_033t   SMEIDB2t   2003_180s"   SMEI drives available; all is wells)   SMEI drives not found; cold boot requireds   -email=RB   s#   echo "Cold reboot required" | mail s    -s"SMEI drives on t   HOSTNAMEs    apparently off-line"s   -file_list=s0   no list of already-processed l1a files availables   file does not exist:s   -source=s
   /mnt/cdroms   -mirrors   -unblocks   l1a.py -source=t   L1A_GETs   l1a.py s   -destination=t   SMEIDBs   SMEIDB?s   non-existent directory, s   -l1a=t   ,s   -gunzips   -all_l1as	   -nounpacks   .bufs   no *.buf files in s   -move=s   non-existent directory:s   ========== ALL DONE ==========(;   t   __doc__R	   RK   R4   Rw   R1   t   tempdirt   tinyR   R   R   R   R   R   R   R$   R.   R;   RA   R[   Rh   R    R£   t   __name__R
   R   RL   t   nameR   t   has_keyRs   RM   R   RX   t   cmdR8   R   R   R*   t   bymirrort   FalseR    R‡   R   RP   R!   R%   R†   t   nounpackR   R¡   R   R   R   R   R   RW   t   renameR'   (    (    (    s   ./l1a.pys   <module>x   sÌ   0.	D	G	0	/		w	+	ÿ C	A
	))		
!! )( 7	