r1 - 18 Jan 2005 - 21:19:00 - MikeTYou are here: OSAF >  Journal Web  >  TWikiUsers > MikeT > MikeTaylorNotes > MikeTaylor20050117

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
Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r1 | More topic actions
 
Open Source Applications Foundation
Except where otherwise noted, this site and its content are licensed by OSAF under an Creative Commons License, Attribution Only 3.0.
See list of page contributors for attributions.