ó
ŕxTc           @   sm   d  d l  m Z d  d l Z d  d l Z d Z d   Z d   Z d   Z e d k ri e e j	 d  n  d S(	   i˙˙˙˙(   t   divisionNi@B c         C   sZ   |  d t  IJ| d  k r? |  d | IJ|  d IJ|  d IJn  |  d IJ|  j d  d  S(   Nsî  #! /usr/bin/env perl
#
# This is a self-extracting tar.gz file.
# Usage:
#   perl name_of_this_file
#
# The perl header of this file is
#
# Copyright (c) 2003 The Regents of the University of California
# through E.O. Lawrence Berkeley National Laboratory, subject to
# approval by the U.S. Department of Energy.
#
# and was written in May 2003 by Ralf W. Grosse-Kunstleve.
# See also:
#   http://cctbx.svn.sourceforge.net/viewvc/*checkout*/cctbx/trunk/libtbx/LICENSE_2_0.txt
#
# The above copyright notice does *not* apply to the attached tar.gz file.
#
print "Unpacking self-extracting archive\n";
$my_size = -s $0;
open(SELF,"<$0") or die "ERROR: Cannot read self-extracting archive!\n";
binmode SELF;
$last_seven = "0000000";
$n_end = 0;
$n_header = 0;
while ($n_header < $my_size && $n_end < 2) {
  $n_header++;
  $ch = getc(SELF);
  $last_seven = substr($last_seven, 1, 6) . $ch;
  if ($last_seven eq "__END__") {
    $n_end += 1;
  }
}
while ($n_header < $my_size && $ch ne "@") {
  $n_header++;
  $ch = getc(SELF);
}
if ($n_header == $my_size) {
  die "ERROR: Corrupt self-extracting archive!\n";
}
open(TAR_PIPE, "|gunzip -c | tar xf -");
binmode TAR_PIPE;
while (read(SELF, $buf, %d) != 0) {
  syswrite(TAR_PIPE, $buf, length($buf));
}
close(TAR_PIPE);s    $cmd = join(" ", ("%s", @ARGV));s    print "Running command: $cmd\n";s   system("$cmd");t   __END__t   @(   t   buf_sizet   Nonet   write(   t   selfxt   command(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/create_selfx.pyt   perl_header   s    .


c         C   s  |  j  d  s$ |  j  d  s$ t  | d  k sE t | t  sE t  | j d  sZ t  t |  d  } t j j	 |   d } | j  d  r | d  } n
 | d  } | d 7} t | d	  } t
 | |  x/ | j t  } | d
 k rí Pn  | j |  qÎ | j   | j   d  S(   Ns   .tar.gzs   .tgzs   ./t   rbi˙˙˙˙iů˙˙˙iü˙˙˙s   .selfxt   wbt    (   t   endswitht   AssertionErrorR   t
   isinstancet   strt
   startswitht   opent   ost   patht   splitR   t   readR   R   t   close(   t   tar_file_nameR   t   tar_filet   selfx_file_nameR   t   buf(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/create_selfx.pyt   create=   s$    $!

 
c         C   sv   t  |   d k s* d |  k s* d |  k r6 t j GHd S|  d } d } t  |   d k re |  d } n  t | |  d S(   s2   usage: libtbx.create_selfx tar_file_name [command]i   i   s   -hs   --helpNi    (   i   i   (   t   lent   runt   __doc__R   R   (   t   argsR   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/create_selfx.pyR   Q   s    *
t   __main__i   (
   t
   __future__R    t   sysR   R   R   R   R   t   __name__t   argv(    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/command_line/create_selfx.pyt   <module>   s   	7		