00001 ############################################################################## 00002 # 00003 # Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. 00004 # Fabien Pinckaers <fp@tiny.Be> 00005 # Copyright (c) 2007-2008 Albert Cervera i Areny <albert@nan-tic.com> 00006 # 00007 # WARNING: This program as such is intended to be used by professional 00008 # programmers who take the whole responsability of assessing all potential 00009 # consequences resulting from its eventual inadequacies and bugs 00010 # End users who are looking for a ready-to-use solution with commercial 00011 # garantees and support are strongly adviced to contract a Free Software 00012 # Service Company 00013 # 00014 # This program is Free Software; you can redistribute it and/or 00015 # modify it under the terms of the GNU General Public License 00016 # as published by the Free Software Foundation; either version 2 00017 # of the License, or (at your option) any later version. 00018 # 00019 # This program is distributed in the hope that it will be useful, 00020 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 # GNU General Public License for more details. 00023 # 00024 # You should have received a copy of the GNU General Public License 00025 # along with this program; if not, write to the Free Software 00026 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00027 # 00028 ############################################################################## 00029 00030 import os 00031 import sys 00032 00033 ## @brief This functions searches the given file (optionally adding a subdirectory) 00034 # in the possible directories it could be found. 00035 # 00036 # This should hide different installation and operating system directories. Making 00037 # it easier to find resource files. 00038 def searchFile(file, subdir=None): 00039 tests = [] 00040 if subdir: 00041 tests += [os.path.join( x, subdir ) for x in sys.path] 00042 tests += [os.path.join( x, 'Koo', subdir ) for x in sys.path] 00043 # The following line is needed for Koo to work properly 00044 # under windows. Mainly we say attach 'share/koo/subdir' to 00045 # sys.path, which by default has 'c:\python25' (among others). 00046 # This will give 'c:\python25\share\koo\ui' for example, which is 00047 # where '.ui' files are stored under the Windows platform. 00048 tests += [os.path.join( x, 'share', 'Koo', subdir ) for x in sys.path] 00049 tests += ['%s/share/Koo/%s' % ( sys.prefix, subdir)] 00050 else: 00051 tests += [os.path.join( x, 'Koo' ) for x in sys.path] 00052 tests += sys.path 00053 00054 for p in tests: 00055 x = os.path.join(p, file) 00056 if os.path.exists(x): 00057 return x 00058 # Previously we returned False but None is more appropiate 00059 # and even some functions (such as initializeTranslations using 00060 # gettext.translation() will depend on it). 00061 return None 00062 00063 uiPath = lambda x: searchFile(x, 'ui') 00064