ó
ÉÝ{Tc           @   sŽ   d  Z  d d l Td d l m Z m Z d e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e j	 f d	 „  ƒ  YZ
 d
 e j f d „  ƒ  YZ d S(   s–  
     qtgui/JobControl.py: CCP4MG Molecular Graphics Program
     Copyright (C) 2001-2008 University of York, CCLRC
     Copyright (C) 2009-2010 University of York
     Copyright (C) 2012 STFC

     This library is free software: you can redistribute it and/or
     modify it under the terms of the GNU Lesser General Public License
     version 3, modified in accordance with the provisions of the 
     license to address the requirements of UK law.
 
     You should have received a copy of the modified GNU Lesser General 
     Public License along with this library.  If not, copies may be 
     downloaded from http://www.ccp4.ac.uk/ccp4license.php
 
     This program is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU Lesser General Public License for more details.
iÿÿÿÿ(   t   *(   t   QtCoret   QtGuit
   JobControlc        
   B   sà   e  Z d d  „ Z d „  Z d „  Z d „  Z i  d „ Z d d d „ Z d d d g  g  g  i  d d „ Z	 d „  Z
 d d d g  g  i  d d	 g  d
 „	 Z d „  Z d d d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sŸ   t  j j |  | ƒ d d  l } d d  l } | j j | j ƒ  d ƒ |  _ i  |  _	 g  |  _
 d |  _ d  |  _ t ƒ  j d i d d 6d d 6|  j d	 6d
 ƒ d  S(   Niÿÿÿÿt   logsi    t   job_controls   Review jobst   texts%   Show details of external program runst   tipt   slott   Tools(   R   t   QObjectt   __init__t   ost   utilst   patht   joint
   get_CCP4MGt   log_dirt   pending_jobst   pending_jobs_listt   last_job_idt   Nonet   reviewWindowt
   MAINWINDOWt   addMenuDefinitiont
   openReview(   t   selft   parentR   R   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR      s    				
c         C   s4   g  } x' |  j  D] } | j |  j | ƒ ƒ q W| S(   N(   R   t   appendt   formatted_job(   R   t   job_listt   root(    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt   get_jobs_list+   s    c         C   sþ   d d  l  } t | ƒ d d d !} |  j | d d d d !} | d | d	 } |  j | d
 rÏ |  j | d r¡ | d | j | j |  j | d
 ƒ ƒ } qú | d | j | j |  j | d
 ƒ ƒ } n+ | d | j | j |  j | d ƒ ƒ } | S(   Niÿÿÿÿs       i    i   t   names                       i   s     t    t   finish_timet   statuss     FAILED   s     FINISHED s     STARTED  t
   start_time(   t   timet   strR   t   asctimet	   localtime(   R   R   R&   t   numberR!   R   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR   4   s    ..+c         C   s4   i  } x' d d g D] } t  |  | ƒ | | <q W| S(   NR   R   (   t   getattr(   R   t   parst   item(    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt	   getparamsD   s    c         C   s/   x( | j  ƒ  D] } t |  | | | ƒ q Wd  S(   N(   t   keyst   setattr(   R   t   paramst   key(    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt	   setparamsL   s    t    c         C   sÈ  d d  l  } | r; | j j | j j | ƒ d ƒ d } nB | r} |  j j | ƒ r} |  j | j d ƒ r} |  j | d } n  i d d 6d d 6d d 6d d 6} | j j | ƒ rÃ t | d	 ƒ } n d  } | rÄ| j	 ƒ  } | j
 ƒ  d d  l } xÐ | j | d
 ƒ D]¹ } | j | ƒ }	 |	 r|	 d d k r@|	 d | d <n  |	 d d k rxd d  l }
 |
 j d d | ƒ | d <q½|	 d d k r™|	 d | d <q½|	 d d k r½|	 d | d <q½qqWn  | S(   Niÿÿÿÿi    t   logfileR4   R$   t   reportt   taskt   job_idt   rs   
s   #TERMINATIONi   s   #REPORTs   #SCRIPTs   #JOB_IDi   (   R   R   t   splitextt   splitR   t   has_keyt   existst   openR   t   readt   closet   stringt   ret   sub(   R   R   t   fileR   R,   t   ft   contentRA   t   linet   wordsRB   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt   read_log_fileT   s<    ).

c	      
   C   s¨  d d  l  }	 d d  l }
 d d  l } d d  l } d d  l } |  j d |  _ |	 j j | j ƒ  d | d t	 |  j ƒ d ƒ } | râ | d k rî |
 j
 d k r» |	 j j |
 j d ƒ } n d	 G|
 j GHd
 } | j | ƒ } qî n | } d } t | | j ƒ r"x- | D] } | d | } qWn | d | } | d t	 |  j ƒ d | } |
 j
 d k r½d G| Gd G| GHy |	 j |	 j | d | ƒ Wqd G| Gd G| GHd d | d | g SXnK y |	 j | d | d ƒ Wn+ d G| Gd G| GHd d | d | g SX| d t	 |  j ƒ } i  |  j | <t | j ƒ  ƒ |  j | d <| |  j | d <| r›t d | d d d d | d  d! | d" ƒ |  j | d# <n  d$ |  j g S(%   Niÿÿÿÿi   R   t   _s   .logt   pythont   win32s
   python.exet   prefixs   /usr/bin/pythonR4   R"   s	    -job_id s    -task s   Starting processt	   argstrings   --s   ERROR spawning:s
   arguments:s   ERROR spawning: s    arguments: s    &s   ERROR running:s   ERROR running: R%   t   handlert	   labelTextt   LABELt   cancelButtonTextt   Cancelt   titlet   TITLEt   helpt   HELPt   guii    (   R   t   syst   typesR   R&   R   R   R   R   R'   t   platformRM   t
   msvcescapet
   isinstancet   ListTypet   spawnlt   P_NOWAITt   systemR   t   intt   mgProgressDialog(   R   R!   t   interpretert   commandt   argst   registry_infoRO   t   progresst   logR   RY   RZ   R   R&   R5   t   cmdRN   R-   R   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt	   start_jobz   sP    3;c         K   s   d  S(   N(    (   R   t   keywords(    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt   handle_progress_guiÁ   s    i    c
         K   sÝ  d d l  } d d l } d d l } d d l } d d l } d d l m } d d l } |  j d |  _ | j	 j
 | j ƒ  d | d t |  j ƒ d ƒ } | rF| d k r:| j d	 k r× | j	 j
 | j d
 ƒ } q:| j d k r| j	 j
 | j d d d ƒ } q:d G| Gd G| j GH| j	 j
 | j d d ƒ } n  | g } n | } g  } t | | j ƒ r…x@ | D] } | j | ƒ qkWn" d d l } | j | j | ƒ ƒ g  } x- | D]% } | j | j t | d ƒ ƒ ƒ q´W| r,| j | j d ƒ | j t |  j ƒ ƒ | j d ƒ | j | ƒ g ƒ n  |  j } | j |  ƒ } | j | ƒ |	 rut |	 d | g |	 d ƒ n  |  j | | j d ƒ | j |  j | ƒ ƒ t ƒ  r½d G| G| G| GHn  | d k rè| j d	 k rè|  j  | ƒ n  | j! | | j" | ƒ ƒ |  j# j | ƒ i
 | d 6| d 6| d 6d d 6d d 6d d 6t$ | j ƒ  ƒ d 6| d 6| d  6| d! 6|  j% | <| r¨t& | d" d# | d$ d% | d& ƒ|  j% | d' <n  |  j' rÐ|  j' j( | |  j) | ƒ ƒ n  d |  j g S((   s-   
    Use Qt QProcess to run external job
    iÿÿÿÿN(   R   i   R   RJ   s   .logRK   RL   s
   python.exet   darwint   CCP4MGt   bint   QtMGt   Runnings   using python froms   utf-8s   -job_ids   -taski    s   finished(int)s   JobControl process.startR!   Re   t   arglistR4   t   errort   outputR#   R%   RO   t   processR5   RQ   RT   RU   RV   RW   RX   (*   R   RY   RZ   R&   R   t   PyQt4R   t   guiUtilsR   R   R   R   R'   R[   RM   t   environR]   R^   R   RA   t   extendR;   t   QStringt   unicodet   QProcesst   setObjectNamet   applyt   connectt   SIGNALt   partialt   end_processt	   DEVELOPERt   set_process_environmentt   startt   QStringListR   Rb   R   t
   mgProgressR   t   updateSelectJobR   (   R   R!   Rd   Re   Rf   RO   Rh   Ri   t
   add_job_idt   process_modifiert   kwR   RY   RZ   R&   R   R   Rx   R5   Rj   Rs   R-   RA   t   lR   Rv   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt   start_processÈ   sr    03"  #	+	 
2	 c         K   s«  d d  l  } |  j j | ƒ rv|  j | d j ƒ  |  j | d <t | j  ƒ  ƒ |  j | d <t |  j | d j ƒ  ƒ |  j | d <t |  j | d j ƒ  ƒ |  j | d <t | j  ƒ  ƒ |  j | d <|  j | j d ƒ rø |  j | d j ƒ  n  |  j | j	 d g  ƒ } | rt
 ƒ  r>t | d	 | g | d
 ƒ qsy t | d	 | g | d
 ƒ Wqsd G| GHqsXqn	 d G| GH|  j r§|  j j | |  j | ƒ ƒ n  d  S(   NiÿÿÿÿRv   R$   R#   Rt   Ru   RX   RO   i    i   s<   ERROR in JobControl.end_process - failed to run handler for s9   ERROR in JobControl.end_process - process id unrecognised(   R&   R   R<   t
   exitStatusRb   R'   t   readAllStandardErrort   readAllStandardOutputR@   t   getR„   R   R   R‰   R   (   R   R   RŒ   R&   RO   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyRƒ     s(    "((			 c         C   s*   |  j  j | ƒ r& | |  j  | | <n  d  S(   N(   R   R<   (   R   t   idt	   attributet   value(    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt
   setJobData<  s    Rt   c         C   s   |  j  j | i  ƒ j | d ƒ S(   NR4   (   R   R’   (   R   R“   R”   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt
   getJobDataA  s    c         C   s#   |  j  j | ƒ r |  j  | =n  d  S(   N(   R   R<   (   R   R“   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt	   deleteJobD  s    c   	      K   s|   d d  l  } d d  l } | j ƒ  } | j } | d } x  | d D] } | d | } qB W| j d | ƒ | j | ƒ d S(   Niÿÿÿÿi    i   t   ;s   PYTHONPATH=(   R   RY   t   systemEnvironmentR   R   t   setEnvironment(	   R   Rv   RŒ   R   RY   t   envt   pypath_listt   pypathR-   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR…   I  s    	
 c         C   sj   d d  l  } |  j sL t t ƒ  ƒ |  _ |  j |  j t j d ƒ |  j ƒ n  |  j j ƒ  |  j j	 ƒ  d  S(   Niÿÿÿÿt   show(
   t   MGSimpleDialogR   t   jobReviewGuiR   R€   R   R�   t
   showStatusRŸ   t   raise_(   R   R    (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR   X  s    	%c         C   sã  |  j  j ƒ  } |  j j | ƒ s% d  S|  j | d d } xS |  j | d D]@ } t | ƒ t k r~ | d t | d ƒ } qL | d | } qL Wd | d } d } d } t |  d ƒ rÆ|  j j d	 ƒ rÆ|  j | j d
 ƒ rõ |  j | d
 } n  |  j | j d ƒ r|  j | d } n  |  j | j d ƒ r[| d t |  j | d ƒ d } n  |  j | j d ƒ r‘| d |  j | d d } n  |  j | j d ƒ rÆ| d |  j | d } qÆn  |  j  j | | | | ƒ d  S(   NRe   u    Rs   s   utf-8s   Run command: s   

R4   R   R   R!   R5   R$   s   Finish status: Rt   s   Standard error:
Ru   s   Standard out:
(	   R   t   selectedJobR   R<   t   typeR'   R|   t   hasattrt   loadText(   R   R   Rj   R-   Ru   R!   R5   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR¢   b  s2     !& N(   t   __name__t
   __module__R   R   R    R   R.   R3   RI   Rk   Rm   RŽ   Rƒ   R–   R—   R˜   R…   R   R¢   (    (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR      s$   				&F	S	 			
Rˆ   c           B   s2   e  Z d  d d „ Z d „  Z d „  Z d „  Z RS(   t   ProgressR4   c         C   s%  t  j j |  t ƒ  ƒ d |  _ |  j | ƒ |  j t j j	 ƒ t  j
 ƒ  } d d  l } x9 | j | d ƒ D]% } t  j | |  ƒ } | j | ƒ qj Wt  j |  ƒ } | j d d ƒ | j d ƒ | j | ƒ t  j d |  ƒ } |  j | t j d ƒ |  j ƒ | j | ƒ |  j | ƒ |  j ƒ  d  S(   NR4   iÿÿÿÿs   
i    Rh   s
   Cancel jobs	   clicked()(   R   t   QDialogR   R   t
   cancelCallt   setWindowTitlet   setAttributeR   t   Qtt   WA_DeleteOnCloset   QVBoxLayoutRA   R;   t   QLabelt	   addWidgett   QProgressBart   setRangeR~   t   QPushButtonR€   R�   t   cancelProgresst	   setLayoutRŸ   (   R   R   RT   RV   t   layoutRA   RG   t   widget(    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR   ˆ  s$    	c         C   s   | |  _  d  S(   N(   R¬   (   R   R¬   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt	   setCancel¨  s    c         C   s/   |  j  t j d ƒ } | r+ | j | ƒ n  d  S(   NRh   (   t	   findChildR   R´   t   setValue(   R   R•   Rº   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt   setProgress­  s     c         C   s$   |  j  r |  j  ƒ  n  |  j ƒ  d  S(   N(   R¬   R@   (   R   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR·   ³  s    	 (   R¨   R©   R   R»   R¾   R·   (    (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyRˆ   ‚  s    		Rc   c           B   s&   e  Z d  d  d d d d  d  d „ Z RS(   R4   i   id   c         C   sU   | s t  ƒ  } n  t j j |  | | | | | ƒ |  j t j j ƒ |  j | ƒ d  S(   N(	   R   R   t   QProgressDialogR   R®   R   R¯   R°   R­   (   R   RP   RR   t   minimumt   maximumR   RT   RV   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR   ¿  s
     N(   R¨   R©   R   R   (    (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyRc   »  s   R¡   c           B   sJ   e  Z d  „  Z d „  Z d „  Z d „  Z d d d d d „ Z d „  Z RS(   c   	      C   sz  t  j j |  | ƒ |  j d ƒ t  j ƒ  } d } t  j d |  ƒ |  _ t  j ƒ  } | j | | | | ƒ | j | ƒ t  j	 |  ƒ |  _
 |  j
 j t  j j ƒ |  j
 j d ƒ |  j
 j ƒ  j } d d  l } |  j |  j
 t j d ƒ | j |  j t j d ƒ ƒ ƒ | j |  j
 ƒ |  j j | ƒ t  j d |  ƒ |  _ t  j ƒ  } | j | | | | ƒ | j | ƒ t  j |  ƒ |  _ |  j j d ƒ |  j j d	 ƒ |  j j d
 ƒ |  j j d ƒ | j |  j ƒ |  j j | ƒ t  j d |  ƒ |  _ t  j ƒ  } | j | | | | ƒ | j | ƒ t  j |  ƒ |  _  |  j  j d ƒ |  j  j d ƒ | j |  j  ƒ |  j j | ƒ t  j! t j" j# |  ƒ |  _$ | j |  j$ ƒ |  j$ j |  j ƒ |  j$ j |  j ƒ |  j$ j |  j ƒ |  j$ j% d d ƒ |  j$ j& d d d g ƒ t  j' |  ƒ } | j( d t  j' j) ƒ } |  j | t j d ƒ |  j* ƒ | j | ƒ |  j+ ƒ  |  j
 j, ƒ  |  j | ƒ d  S(   Ns   CCP4mg: Review jobsi   s   Select job to reviewi   iÿÿÿÿs   currentRowChanged(int)RŸ   s   Program outputiX  id   t   Couriers   Log filei   i   t   Closes	   clicked()(-   R   R«   R   R­   R±   t	   QGroupBoxt   select_framet   setContentsMarginst
   setSpacingt   QListWidgett	   selectJobt   setSelectionModet   QAbstractItemViewt   SingleSelectiont   setMinimumHeightt   viewOptionst   fontRx   R€   R   R�   R‚   t   emitR³   R¸   t   error_framet	   QTextEditRt   t   setReadOnlyt   setMinimumWidtht   setFontFamilyt	   log_frameR5   t	   QSplitterR¯   t   Verticalt   splittert   setStretchFactort   setSizest   QDialogButtonBoxt	   addButtont
   RejectRoleR@   t   loadSelectJobRŸ   (	   R   R   R¹   t   frame_margint   frame_layoutRÏ   Rx   t   dialog_buttonst   cancel_button(    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR   Î  sd    7
c         C   s]   |  j  j t ƒ |  j  j ƒ  x) t ƒ  j ƒ  D] } |  j  j | ƒ } q- W|  j  j t ƒ d  S(   N(   RÉ   t   blockSignalst   Truet   cleart
   JOBCONTROLR    t   addItemt   False(   R   R-   Rº   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyRß     s
    c         C   s4   |  j  j t ƒ |  j  j | ƒ |  j  j t ƒ d  S(   N(   RÉ   Rä   Rå   Rè   Ré   (   R   R-   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt   addJob  s    c         C   sQ   |  j  j ƒ  } | d k  r d St |  j  j | ƒ j ƒ  ƒ } t | j ƒ  d ƒ S(   Ni    R4   (   RÉ   t
   currentRowR'   R-   R   Rb   R;   (   R   t   irowR   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR¤     s
     iÿÿÿÿR4   c         C   sJ  |  j  j d t | ƒ d | ƒ |  j j | ƒ d } d d  l } | rË |  j j d | ƒ | j j | ƒ s} | d } qÛ y7 t	 | d ƒ } | j
 ƒ  } | j ƒ  | d | } WqÛ | d	 } qÛ Xn |  j j d
 ƒ |  j j | ƒ |  j j ƒ  }	 |	 d d k rF|  j j ƒ  }
 t | j d ƒ ƒ } t | j d ƒ ƒ } n  d  S(   Ns   Output from job number R"   R4   iÿÿÿÿs
   Log file: s    Error - log file does not existsR9   s   
s   Error reading log files   No log filei    gÍÌÌÌÌÌì?(   RÑ   t   setTitleR'   Rt   t   setTextR   RÖ   R   R=   R>   R?   R@   R5   RÙ   t   sizesRÉ   t   countt   lenR;   (   R   R   R!   Rt   R5   t   log_textR   RE   R   Rï   t   l_selt   l_logt   l_err(    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR§   !  s,    "
c         C   s~   | d } |  j  j t ƒ | |  j  j ƒ  k  rZ |  j  j | ƒ } | rj | j | ƒ qj n |  j  j | ƒ |  j  j t ƒ d  S(   Ni   (   RÉ   Rä   Rå   Rð   R-   Rî   Rè   Ré   (   R   R   t	   item_textt   rowR-   (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR‰   <  s    
 (   R¨   R©   R   Rß   Rê   R¤   R§   R‰   (    (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyR¡   É  s   	A			N(   t   __doc__t   global_definitionsRw   R   R   R
   R   R«   Rˆ   R¿   Rc   R¡   (    (    (    s=   /opt/xtal/ccp4-6.5-linux32/lib/py2/ccp4mg/qtgui/JobControl.pyt   <module>   s   
ÿ k9