+def BuildInstallOrPreinstallPath(DirName, FileName):
+ # Builds a path to the DirName directory. This should work both when:
+ # - the package is properly installed in which case DirName is a subdir
+ # of the package,
+ # - when in pre-installation mode (basically inside a CVS hierarchy)
+ # in which case DirName and the package itself lie at the same
+ # filesystem level.
+ # In both cases we need to express the full path to DirName relatively
+ # to the path to this __init__.py. For this we rely on __path__ variable.
+ # In order to make sure we got the correct Path, we check for the
+ # existence of FileName.
+ InstallModePath = os.path.join(__path__[0], DirName + "/")
+ if os.path.isfile(os.path.join(InstallModePath, FileName)):
+ return InstallModePath
+ PreInstallModePath = os.path.join(__path__[0], "..", DirName + "/")
+ if os.path.isfile(os.path.join(PreInstallModePath, FileName)):
+ return PreInstallModePath
+ return None
+