Routine to determine profile directory
def locateProfileDir():
"""
Locate the Chandler repository.
The location is determined either by parameters, or if not specified, by
the presence of a .chandler directory in the users home directory.
"""
# if a profileDir is specified then just use it
if application.Globals.options.profileDir:
application.Globals.options.profileDir = os.path.expanduser(application.Globals.options.profileDir)
else:
profileDir = None
homeDir = os.path.expanduser('~')
macDir = os.path.join(homeDir, 'Library', 'Application Support')
# try to find any existing directories
dirs = [ os.path.join(homeDir, '.chandler'), # look in posix home dir
os.path.join(macDir, 'Chandler'), # special case for OS/X
application.Globals.chandlerDirectory, # finally look in the application dir
]
for path in dirs:
if path:
path = os.path.expanduser(path)
if os.path.isdir(path):
if os.path.isdir(os.path.join(path, '__repository__')):
profileDir = path
break
# if not found, then figure out where to create one
if not profileDir:
if os.path.isdir(homeDir):
if os.path.isdir(macDir):
profileDir = os.path.join(macDir, 'Chandler')
else:
profileDir = os.path.join(homeDir, '.chandler')
os.mkdir(profileDir)
else:
profileDir = application.Globals.chandlerDirectory
application.Globals.options.profileDir = profileDir