Package ComboCode :: Package cc :: Package path
[hide private]
[frames] | no frames]

Source Code for Package ComboCode.cc.path

 1  # -*- coding: utf-8 -*- 
 2   
 3  import os 
 4   
 5  #-- Method only accessible when importing cc.data.  
 6  #   Should not be called otherwise. Method is here to avoid unnecessary globals 
7 -def __readPaths():
8 9 ''' 10 Read the relevant paths from the usr/Path.dat file. 11 12 Default values typically return an expected location for model related 13 folders, and an empty string for data locations (in which case no data are 14 used). 15 16 @return: The pathnames with associated path are returned. 17 @rtype: dict 18 19 ''' 20 21 dd = dict([('gdata','GASTRoNOoM/src/data'),('gastronoom','GASTRoNOoM'),\ 22 ('chemistry','Chemistry'),('csource',''),\ 23 ('mcmax','MCMax'),('mobs','MCMax/Observation_Files'),\ 24 ('mopac','MCMax/Opacities'),('data',''),('dradio',''),\ 25 ('dpacs',''),('dspire',''),('dsed',''),('dphot',''),\ 26 ('dcflux',''),('ll','LineLists'),('ivsdata',''),('atm',''),\ 27 ('starf',''),('densf','')]) 28 filename = os.path.join(usr,'Path.dat') 29 FILE = open(filename,'r') 30 lines = FILE.readlines() 31 FILE.close() 32 lines = [line.strip('\n').strip() for line in lines if line.strip('\n')] 33 dd.update(dict([line.split('=') for line in lines if line[0] != '#'])) 34 for k,v in dd.items(): 35 if not v: 36 dd[k] = '' 37 elif not v[0] == '/': 38 dd[k] = os.path.join(os.path.expanduser('~'),v) 39 return dd
40 41 42 43 #-- Define the home, usr and aux paths for ComboCode. If working folder is the 44 # CC home folder itself, make sure home is not just an empty string. 45 home = os.path.dirname(__file__).replace('cc/path','') 46 if not home: home = os.getcwd() 47 usr = os.path.join(home,'usr') 48 aux = os.path.join(home,'aux') 49 50 #-- Insert the path names and values taken from usr/Path.dat into the globals 51 # of the module's namespace. These paths are only available through, e.g., 52 # cc.paths.pathname 53 globals().update(__readPaths()) 54 55 #-- Note that this module can be used to set additional paths in any given 56 # python session. The paths are then always remembered until they are changed 57 # within that session. e.g. mout and gout give the mcmax and gastronoom 58 # output folders, but they are only created when ComboCode is ran. 59