This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/intern/python/modules/mcf/utils/findourfile.py
Hans Lambermont 12315f4d0e Initial revision
2002-10-12 11:37:38 +00:00

31 lines
1.1 KiB
Python

'''
This utility allows a python system to find a file in it's
directory. To do this, you need to pass it a function object from
a module in the correct directory. I know there must be a better
way to do this, but I haven't seen it yet. Incidentally, the
current directory should be _different_ from the module in which
the function is contained, otherwise this function will go off into
the root directory.
Currently this has to be called with the current directory a directory
other than the directory we're trying to find... need a better solution
for this kind of thing... a python registry would be great :)
NOTE: as of Python 1.5, this module should be obsolete! As soon as I
have verified that all of my code is fixed, it will be moved to the unused
directories.
'''
import os,sys
def findourfile(function, filename):
'''
Given the function, return a path to the a file in the
same directory with 'filename'. We also let the caller
know if the file already exists.
'''
ourfilename = os.path.split(function.func_code.co_filename)[0]+os.sep+filename
exists = os.path.exists(ourfilename)
return (exists,ourfilename)