Package pycv :: Module system_info
[hide private]
[frames] | no frames]

Source Code for Module pycv.system_info

  1  # PyCV - A Computer Vision Package for Python Incorporating Fast Training of Face Detection 
  2   
  3  # Copyright 2007 Nanyang Technological University, Singapore. 
  4  # Authors: Minh-Tri Pham, Viet-Dung D. Hoang, and Tat-Jen Cham. 
  5   
  6  # This file is part of PyCV. 
  7   
  8  # PyCV is free software: you can redistribute it and/or modify 
  9  # it under the terms of the GNU General Public  
 10  # License as published by the Free Software Foundation, either version  
 11  # 3 of the License, or (at your option) any later version. 
 12   
 13  # PyCV is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  # GNU General Public License for more details. 
 17   
 18  # You should have received a copy of the GNU General Public License 
 19  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 20   
 21  # --------------------------------------------------------------------- 
 22  #!/usr/bin/env python 
 23   
 24  """ 
 25  This file defines a set of system_info classes for getting 
 26  information about various resources (libraries, library directories, 
 27  include directories, etc.) in the system. It is an extension of 
 28  numpy's system_info.py. Currently, the following classes are  
 29  available: 
 30   
 31    numpy_blas 
 32    <all other classes supported by numpy> 
 33   
 34  Usage: 
 35      info_dict = get_info(<name>) 
 36    where <name> is a string 'numpy_blas', etc.  
 37    For a complete list of allowed names, see the definition of get_info()  
 38    function below. 
 39   
 40    Returned info_dict is a dictionary which is compatible with 
 41    distutils.setup keyword arguments. If info_dict == {}, then the 
 42    asked resource is not available (system_info could not find it). 
 43   
 44    Several *_info classes specify an environment variable to specify 
 45    the locations of software. When setting the corresponding environment 
 46    variable to 'None' then the software will be ignored, even when it 
 47    is available in system. 
 48   
 49  Modified from numpy's original system_info.py by: 
 50    Minh-Tri Pham <mtpham@ntu.edu.sg>, July 2007 
 51  """ 
 52   
 53  __all__ = ['get_info', 'default_dir'] 
 54   
 55  import os 
 56  import re 
 57   
 58  from numpy.distutils import system_info as npsi 
 59  from numpy.distutils.ccompiler import get_default_compiler 
 60  from numpy.distutils.cpuinfo import cpu 
 61  from distutils.version import StrictVersion 
 62  from scipy.weave import catalog 
 63   
 64   
65 -def get_gcc_version():
66 out = os.popen('gcc -dumpversion','r') 67 out_string = out.read() 68 out.close() 69 result = re.search('(\d+\.\d+)',out_string) 70 if result: 71 return StrictVersion(result.group(1)) 72 return None
73 74 75
76 -def get_info(name,notfound_action=0):
77 """ 78 notfound_action: 79 0 - do nothing 80 1 - display warning message 81 2 - raise error 82 """ 83 cl = { 84 'numpy_blas':numpy_blas_info, 85 }.get(name.lower()) 86 if cl is None: 87 return npsi.get_info(name,notfound_action) 88 return cl().get_info(notfound_action)
89
90 -class numpy_blas_info(npsi.system_info):
91 - def get_info(self,notfound_action=0):
92 """ Return a dictonary with items that are compatible 93 with numpy.distutils.setup keyword arguments. 94 """ 95 # get info about numpy's blas 96 info = npsi.get_info('blas_opt') 97 for x in ['define_macros', 'include_dirs', 'libraries', 'library_dirs', \ 98 'extra_compiler_args']: 99 if not info.has_key(x): 100 info[x] = [] 101 if len(npsi.get_info('atlas')): 102 info['define_macros'].append(('HAS_ATLAS', None)) 103 104 # add compiling args to optimize source codes 105 extra_args = [] 106 dcomp = get_default_compiler() 107 if cpu._has_sse2() and (dcomp == 'mingw32' or dcomp == 'gcc'): 108 extra_args = ['-O3', '-msse2', '-mfpmath=sse', '-malign-double'] 109 if get_gcc_version() >= '4.2': 110 extra_args.append('-mtune=generic') 111 else: 112 extra_args.append('-march=pentium4') 113 extra_args.append('-mtune=pentium4') 114 info['extra_compiler_args'].extend(extra_args) 115 116 return info
117 118
119 -def default_dir():
120 """ 121 Return a default location to store wisdom files and catalogs. 122 123 The default location is a sub-folder called '.pycv_wisdom' of 124 SciPy's default location in Weave 125 126 :Remarks: 127 I admit I use SciPy's default directory to avoid all the troubles 128 of locating a default folder to store intermediate results. 129 I hope the community will forgive me. 130 """ 131 132 # Use a cached value for fast return if possible 133 if hasattr(default_dir,"cached_path") and \ 134 os.path.exists(default_dir.cached_path): 135 return default_dir.cached_path 136 137 # get SciPy's default directory 138 def_dir = catalog.default_dir() 139 140 # change to pycv_wisdom 141 path = os.path.join(os.path.split(def_dir)[0], '.pycv_wisdom') 142 143 if not os.path.exists(path): 144 catalog.create_dir(path) 145 os.chmod(path,0700) # make it only accessible by this user. 146 if not catalog.is_writable(path): 147 print 'warning: default directory is not write accessible.' 148 print 'default:', path 149 150 # Cache the default dir path so that this function returns quickly after 151 # being called once (nothing in it should change after the first call) 152 default_dir.cached_path = path 153 154 return path
155 156 157 #-------------------------------------------------------------------- 158 159 if __name__ == "__main__": 160 npsi.show_all() 161