ó
æNXc           @   sÃ   d  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
 m Z d „  Z d „  Z d „  Z e	 j d „  ƒ Z d	 „  Z d
 „  Z d „  Z d „  Z d S(   sQ   
Utilities for getting information about IPython and the system it's running in.
iÿÿÿÿN(   t   release(   t	   py3compatt   _sysinfot   encodingc      
   C   sx   t  j r d t  j f St j d d t j d t j d |  d t ƒ} | j ƒ  \ } } | rt d | j ƒ  j d ƒ f Sd S(   s  Get short form of commit hash given directory `pkg_path`

    We get the commit hash from (in order of preference):

    * IPython.utils._sysinfo.commit
    * git output, if we are in a git repository

    If these fail, we return a not-found placeholder tuple

    Parameters
    ----------
    pkg_path : str
       directory containing package
       only used for getting commit from active repo

    Returns
    -------
    hash_from : str
       Where we got the hash from - description
    hash_str : str
       short form of hash
    t   installations   git rev-parse --short HEADt   stdoutt   stderrt   cwdt   shellt
   repositoryt   asciis   (none found)u   <not found>(   s   (none found)u   <not found>(	   R   t   committ
   subprocesst   Popent   PIPEt   Truet   communicatet   stript   decode(   t   pkg_patht   proct   repo_committ   _(    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/sysinfo.pyt   pkg_commit_hash   s    			c         C   sm   t  |  ƒ \ } } t d t j d |  d | d | d t j d t j d t j d t j ƒ  d	 t j d
 t	 j
 ƒ 
S(   sí   Return dict describing the context of this package

    Parameters
    ----------
    pkg_path : str
       path containing __init__.py for package

    Returns
    -------
    context : dict
       with named parameters of interest
    t   ipython_versiont   ipython_patht   commit_sourcet   commit_hasht   sys_versiont   sys_executablet   sys_platformt   platformt   os_namet   default_encoding(   R   t   dictR    t   versiont   syst
   executableR   t   ost   nameR   t   DEFAULT_ENCODING(   R   t   srct   hsh(    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/sysinfo.pyt   pkg_infoD   s    					c          C   s@   t  j }  |  j |  j |  j |  j t d ƒ ƒ ƒ ƒ } t | ƒ S(   sB   Return useful information about IPython and the system, as a dict.s   ..(   R&   t   patht   realpatht   dirnamet   abspatht   joint   __file__R+   (   t   pR,   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/sysinfo.pyt   get_sys_info_   s    	-c           C   s   t  j t ƒ  ƒ S(   st  Return useful information about IPython and the system, as a string.

    Examples
    --------
    ::
    
        In [2]: print sys_info()
        {'commit_hash': '144fdae',      # random
         'commit_source': 'repository',
         'ipython_path': '/home/fperez/usr/lib/python2.6/site-packages/IPython',
         'ipython_version': '0.11.dev',
         'os_name': 'posix',
         'platform': 'Linux-2.6.35-22-generic-i686-with-Ubuntu-10.10-maverick',
         'sys_executable': '/usr/bin/python',
         'sys_platform': 'linux2',
         'sys_version': '2.6.6 (r266:84292, Sep 15 2010, 15:52:39) \n[GCC 4.4.5]'}
    (   t   pprintt   pformatR3   (    (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/sysinfo.pyt   sys_infoe   s    c           C   s   t  j d ƒ S(   s2   Return the number of active CPUs on a Unix system.t   SC_NPROCESSORS_ONLN(   R&   t   sysconf(    (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/sysinfo.pyt   _num_cpus_unixz   s    c          C   s.   t  j d d d g d t  j ƒ}  |  j j ƒ  S(   s4   Return the number of active CPUs on a Darwin system.t   sysctls   -ns   hw.ncpuR   (   R   R   R   R   t   read(   R2   (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/sysinfo.pyt   _num_cpus_darwin   s    !c           C   s   t  j j d ƒ S(   s5   Return the number of active CPUs on a Windows system.t   NUMBER_OF_PROCESSORS(   R&   t   environt   get(    (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/sysinfo.pyt   _num_cpus_windows…   s    c          C   sc   i t  d 6t d 6t d 6}  |  j t j ƒ  t  ƒ } y t d t | ƒ  ƒ ƒ } Wn d } n X| S(   s†  Return the effective number of CPUs in the system as an integer.

   This cross-platform function makes an attempt at finding the total number of
   available CPUs in the system, as returned by various underlying system and
   python calls.

   If it can't find a sensible answer, it returns 1 (though an error *may* make
   it return a large positive number that's actually incorrect).
   t   Linuxt   Darwint   Windowsi   (   R9   R<   R@   R?   R   t   systemt   maxt   int(   t	   ncpufuncst   ncpufunct   ncpus(    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/sysinfo.pyt   num_cpusŠ   s    

	
(   t   __doc__R&   R   R4   R$   R   t   IPython.coreR    t   IPython.utilsR   R   R   R   R+   R3   t   doctest_refactor_printR6   R9   R<   R@   RJ   (    (    (    sM   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/utils/sysinfo.pyt   <module>   s   	&					