On Sun, 2007-04-29 at 12:01 +0200, Giovanni Bajo wrote: > On 29/04/2007 9.34, Didrik Pinte wrote: > > > Thuban allows the user to have a user module to load the extensions he > > wants. This is done using a thubanstart.py file stored in c:\Documents > > and settings\username\Application Data\thuban\ > > > > If I had this path to the Analysis in the spec, the exe containts the > > thubanstart.py file and I cannot modify it anymore or take into account > > the fact that the user has another file. > > > > If I do not add the path to the thubanstart.py file to the Analysis in > > the spec, the application does not load the file when starting. > > > > How can I keep a user file in c:\Documents and settings\username > > \Application Data\thuban\ while using the exe built with pyinstaller ? > > How do you load the module from that directory? Can you show me the code?
This is the method used to load the startup file :
-----------------------------------------------------------------------------
def read_startup_files(self):
"""Read the startup files."""
# for now the startup file is ~/.thuban/thubanstart.py
dir = get_application_dir()
if os.path.isdir(dir):
sys.path.append(dir)
try:
import thubanstart
except ImportError:
tb = sys.exc_info()[2]
try:
if tb.tb_next is not None:
# The ImportError exception was raised from
# inside the thubanstart module.
sys.stderr.write(_("Cannot import the
thubanstart"
" module\n"))
traceback.print_exc(None, sys.stderr)
else:
# There's no thubanstart module.
sys.stderr.write(_("No thubanstart module
available\n"))
finally:
# make sure we delete the traceback object,
# otherwise there's be circular references involving
# the current stack frame
del tb
except:
sys.stderr.write(_("Cannot import the thubanstart module
\n"))
traceback.print_exc(None, sys.stderr)
else:
# There's no .thuban directory
sys.stderr.write(_("No ~/.thuban directory\n"))
-----------------------------------------------------------------------------
and get_application_dir() is defined like this :
-----------------------------------------------------------------------------
def get_application_dir():
"""Determine the path to the .thuban directory. Create the directory
if it doesn't exist.
Under posix systems use the os.expanduser() method.
Under Win32 try to read the "Explorer/Shell Folders/" value
"AppData".
"""
if os.name == 'posix':
dir = os.path.expanduser("~/.thuban")
if not os.path.isdir(dir):
os.mkdir(dir)
return dir
elif os.name == 'nt':
regkey = 1
try:
import _winreg as wreg
except ImportError:
regkey = 0
if regkey:
try:
key = wreg.OpenKey(wreg.HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\"\
"Explorer\\Shell Folders")
dir = wreg.QueryValueEx(key, "AppData")[0]
dir = os.path.join(dir, "thuban")
except:
regkey = 0
if not regkey:
# The fallback. This should result in something like the
# user directory ...
guess = os.path.dirname(
os.path.dirname(os.path.dirname(mktemp()))
)
dir = os.path.join(guess, "thuban")
if not os.path.isdir(dir):
os.mkdir(dir)
return dir
else:
raise RuntimeError(_("No implementation of get_application_dir"
" available for platform") + os.name)
-----------------------------------------------------------------------------
Thanks for your help,
Didrik
signature.asc
Description: This is a digitally signed message part
