
oUNc           @   s   d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l	 m
 Z
 m Z d Z d Z d e
 j f d     YZ i d d	 6d
 d
 6d d 6d d 6Z d   Z d   Z d d  Z d S(   iN(   t   StringIO(   t   usaget   logs  #!/bin/sh
#
#  Startup script for a Twisted service.
#
#  chkconfig: - 85 15
#  description: Start-up script for the Twisted service "%(tap_file)s".

PATH=/usr/bin:/bin:/usr/sbin:/sbin

pidfile=/var/run/%(rpm_file)s.pid
rundir=/var/lib/twisted-taps/%(rpm_file)s/
file=/etc/twisted-taps/%(tap_file)s
logfile=/var/log/%(rpm_file)s.log

#  load init function library
. /etc/init.d/functions

[ -r /etc/default/%(rpm_file)s ] && . /etc/default/%(rpm_file)s

#  check for required files
if [ ! -x /usr/bin/twistd ]
then
	echo "$0: Aborting, no /usr/bin/twistd found"
	exit 0
fi
if [ ! -r "$file" ]
then
	echo "$0: Aborting, no file $file found."
	exit 0
fi

#  set up run directory if necessary
if [ ! -d "${rundir}" ]
then
	mkdir -p "${rundir}"
fi


case "$1" in
	start)
		echo -n "Starting %(rpm_file)s: twistd"
		daemon twistd  \
				--pidfile=$pidfile \
				--rundir=$rundir \
				--%(twistd_option)s=$file \
				--logfile=$logfile
		status %(rpm_file)s
		;;

	stop)
		echo -n "Stopping %(rpm_file)s: twistd"
		kill `cat "${pidfile}"`
		status %(rpm_file)s
		;;

	restart)
		"${0}" stop
		"${0}" start
		;;

    *)
		echo "Usage: ${0} {start|stop|restart|}" >&2
		exit 1
		;;
esac

exit 0
s  Summary:    %(description)s
Name:       %(rpm_file)s
Version:    %(version)s
Release:    1
License:    Unknown
Group:      Networking/Daemons
Source:     %(tarfile_basename)s
BuildRoot:  %%{_tmppath}/%%{name}-%%{version}-root
Requires:   /usr/bin/twistd
BuildArch:  noarch

%%description
%(long_description)s

%%prep
%%setup
%%build

%%install
[ ! -z "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != '/' ] 		&& rm -rf "$RPM_BUILD_ROOT"
mkdir -p "$RPM_BUILD_ROOT"/etc/twisted-taps
mkdir -p "$RPM_BUILD_ROOT"/etc/init.d
mkdir -p "$RPM_BUILD_ROOT"/var/lib/twisted-taps
cp "%(tap_file)s" "$RPM_BUILD_ROOT"/etc/twisted-taps/
cp "%(rpm_file)s.init" "$RPM_BUILD_ROOT"/etc/init.d/"%(rpm_file)s"

%%clean
[ ! -z "$RPM_BUILD_ROOT" -a "$RPM_BUILD_ROOT" != '/' ] 		&& rm -rf "$RPM_BUILD_ROOT"

%%post
/sbin/chkconfig --add %(rpm_file)s
/sbin/chkconfig --level 35 %(rpm_file)s
/etc/init.d/%(rpm_file)s start

%%preun
/etc/init.d/%(rpm_file)s stop
/sbin/chkconfig --del %(rpm_file)s

%%files
%%defattr(-,root,root)
%%attr(0755,root,root) /etc/init.d/%(rpm_file)s
%%attr(0660,root,root) /etc/twisted-taps/%(tap_file)s

%%changelog
* %(date)s %(maintainer)s
- Created by tap2rpm: %(rpm_file)s (%(version)s)
t	   MyOptionsc           B   s   e  Z d  d g d d g g Z d d d g d d d	 g d
 d d  g d d d  g d d d g d d d g d d d  g d d d d g g Z e j d i e j d d d d g  d 6e j d  d 6 Z	 d   Z
 RS(!   t   unsignedt   ut   quiett   qt   tapfilet   ts
   twistd.tapt
   maintainert   mt   tap2rpmt   protocolt   pt   descriptiont   et   long_descriptiont   ls    Automatically created by tap2rpms   set-versiont   Vs   1.0t   rpmfilet   rt   typet   yt   taps8   type of configuration: 'tap', 'xml, 'source' or 'python't
   optActionst   xmlt   sourcet   pythons   *.rpmc         C   s   |  d d k rC t j j |  d  } t j j |  d |  d <n  |  d d k rk d |  d f |  d <n  |  d d k r d |  d f |  d <n  t |  d |  d	 <d
 |  d |  d f |  d <d S(   sP   
        Calculate the default values for certain command-line options.
        R   R   i    R   s   A TCP server for %sR   s
   twisted-%sR   t   twistd_options   %s-%ss   set-versions   release-nameN(   t   Nonet   ost   patht   basenamet   splitextt	   type_dict(   t   selft   base_tapfile(    (    s;   /usr/lib/python2.7/dist-packages/twisted/scripts/tap2rpm.pyt   postOptions   s    N(   t   __name__t
   __module__t   optFlagsR   t   optParametersR   t   Completionst   CompleteListt   CompleteFilest   compDataR&   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/scripts/tap2rpm.pyR      s   	t   fileR   R   R   R   c          C   s   t  j   }  t j t j j |  d d   t j t j j |  d   t j t j j |  d   t j t j j |  d   t j t j j |  d   t j d d d	 |   |  S(
   s}   
    Set up the temporary directory for building RPMs.

    Returns: buildDir, a randomly-named subdirectory of baseDir.
    t   RPMSt   noarcht   SPECSt   BUILDt   SOURCESt   SRPMSt   formats'   Created RPM build structure in %(path)rR    (   t   tempfilet   mkdtempR   t   makedirsR    t   joinR   t   msg(   t   tmpDir(    (    s;   /usr/lib/python2.7/dist-packages/twisted/scripts/tap2rpm.pyt   makeBuildDir   s    c         C   sb  d | d f } t  j j |  d |  } t j | d  } t j | d  } t j | _ d | _ | j	 |  t  j j
 | d  } t j t  j j | d d | d   } t j | _ d | _ t i | d	 6| d d
 6| d d 6} t |  | _ | j	 | t |   t | d d  }	 | j d t  j j | d |  d |	  }
 d |
 _ | j	 |
 |	  | j   t j d d d |  d | d f } t  j j |  d |  } t | d  } t i | d d 6| d d
 6| d d 6| d 6| d	 6t j d t j t j     d 6| d d 6| d d 6} | j |  | j   t j d d d |  | S(   sG   
    Create files required to build an RPM in the build directory.
    s   %s.tars   release-nameR4   t   wi  R   s   %s.initR   t   tap_filet   rpm_fileR   t   rbt   arcnamet   fileobji  R6   s,   Created dummy source tarball %(tarballPath)rt   tarballPaths   %s.specR2   R   s   set-versiont   versiont   tarfile_basenames   %a %b %d %Yt   dateR
   R   s"   Created RPM spec file %(specPath)rt   specPath(   R   R    R:   t   tarfilet   opent   TarInfot   DIRTYPER   t   modet   addfileR!   t   REGTYPEt   initFileDatat   lent   sizeR    t
   gettarinfot   closeR   R;   t   specFileDatat   timet   strftimet	   localtimet   write(   t   buildDirt   configt   tarballNameRD   t   tarballHandlet   sourceDirInfot   tapFileBaset   initFileInfot   initFileRealDatat   tapFileHandlet   tapFileInfot   specNameRH   t
   specHandlet   specFileRealData(    (    s;   /usr/lib/python2.7/dist-packages/twisted/scripts/tap2rpm.pyt   setupBuildFiles   s\    						
"
c   
      C   s  y t    } | j |   Wn4 t j k
 rP } t j d t j d | f  n Xt   } t | |  } t	 j
 d d d d | f d | g d t	 j d	 t	 j } | j   \ } } | j d k r | GHn  t j t j j | d
 d d   d } t j t j j | d d   d }	 | d s;d t j j |  GHn  t j | d  | d smd t j j |	  GHn  t j |	 d  t j |  t j j |  t j j |	  g S(   Ns   %s: %si    t   rpmbuilds   -vvs   --defines
   _topdir %ss   -bat   stdoutt   stderrR0   R1   t   *R5   R   s   Writing "%s"...t   .(   R   t   parseOptionsR   t   errort   syst   exitt   argvR=   Rg   t
   subprocesst   Popent   PIPEt   STDOUTt   communicatet
   returncodet   globR   R    R:   R!   t   shutilt   copyt   rmtree(
   t   optionsR[   t   ueR<   RH   t   jobRi   t   _t   rpmPatht   srpmPath(    (    s;   /usr/lib/python2.7/dist-packages/twisted/scripts/tap2rpm.pyt   run  s4    	"	(%

(   Ro   R   Ry   RV   Rx   Rr   R7   RI   R    t   twisted.pythonR   R   RP   RU   t   OptionsR   R#   R=   Rg   R   R   (    (    (    s;   /usr/lib/python2.7/dist-packages/twisted/scripts/tap2rpm.pyt   <module>   s    <I5)
		E