From: Fernando P. <Fer...@co...> - 2005-06-22 21:48:32
|
Stephen Walton wrote: > Fernando Perez wrote: > > >>It may be simpler than that: > > > So os.environ does change the environment under Python and its > children. The remaining question is what should TEXMFOUTPUT be? > /home/user/.tex.cache will not work across all platforms. Well, it could be something like $HOME/.tex.cache, where $HOME can be determined via a routine like the below (this is what ipython uses to try and guess a sensible value for $HOME): #---------------------------------------------------------------------------- class HomeDirError(Error): pass def get_home_dir(): """Return the closest possible equivalent to a 'home' directory. We first try $HOME. Absent that, on NT it's $HOMEDRIVE\$HOMEPATH. Currently only Posix and NT are implemented, a HomeDirError exception is raised for all other OSes. """ #' try: return os.environ['HOME'] except KeyError: if os.name == 'posix': raise HomeDirError,'undefined $HOME, IPython can not proceed.' elif os.name == 'nt': # For some strange reason, win9x returns 'nt' for os.name. try: return os.path.join(os.environ['HOMEDRIVE'],os.environ['HOMEPATH']) except: try: # Use the registry to get the 'My Documents' folder. import _winreg as wreg key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") homedir = wreg.QueryValueEx(key,'Personal')[0] key.Close() return homedir except: return 'C:\\' elif os.name == 'dos': # Desperate, may do absurd things in classic MacOS. May work under DOS. return 'C:\\' else: raise HomeDirError,'support for your operating system not implemented.' Cheers, f |