Package PyFoam :: Package Infrastructure :: Module Hardcoded
[hide private]
[frames] | no frames]

Source Code for Module PyFoam.Infrastructure.Hardcoded

 1  #  ICE Revision: $Id$ 
 2  """Hardcoded values""" 
 3   
 4  from os import path,makedirs,environ 
 5  from PyFoam.ThirdParty.six import PY3 
 6   
 7  _pyFoamDirName="pyFoam" 
 8   
 9  _pyFoamConfigName="pyfoamrc" 
10   
11  pyFoamSiteVar="PYFOAM_SITE_DIR" 
12   
13 -def globalDirectory():
14 """@return: the global directory""" 15 return path.join("/etc",_pyFoamDirName)
16
17 -def globalConfigFile():
18 """@return: The name of the global configuration File""" 19 return path.join(globalDirectory(),_pyFoamConfigName)
20
21 -def globalConfigDir():
22 """@return: The name of the global configuration directory where .cfg-files can be placed""" 23 return globalConfigFile()+".d"
24
25 -def siteDirectory():
26 """@return: the site directory""" 27 if pyFoamSiteVar in environ: 28 return path.join(environ[pyFoamSiteVar],"etc") 29 else: 30 return None
31
32 -def siteConfigFile():
33 """@return: The name of the site configuration File""" 34 if pyFoamSiteVar in environ: 35 return path.join(siteDirectory(),_pyFoamConfigName) 36 else: 37 return None
38
39 -def siteConfigDir():
40 """@return: The name of the site configuration directory where .cfg-files can be placed""" 41 if pyFoamSiteVar in environ: 42 return siteConfigFile()+".d" 43 else: 44 return None
45
46 -def userDirectory():
47 """@return: the user directory""" 48 return path.expanduser(path.join("~","."+_pyFoamDirName))
49
50 -def userConfigFile():
51 """@return: The name of the user configuration File""" 52 return path.join(userDirectory(),_pyFoamConfigName)
53
54 -def userConfigDir():
55 """@return: The name of the user configuration directory where .cfg-files can be placed""" 56 return userConfigFile()+".d"
57
58 -def userName():
59 """@return: name of the current user""" 60 user="" 61 if "USER" in environ: 62 user=environ["USER"] 63 return user
64
65 -def logDirectory():
66 """Path to the log directory that this user may write to. 67 /var/log/pyFoam for root, ~/.pyFoam/log for all others 68 @return: path to the log directory.""" 69 if userName()=="root": 70 return path.join("/var/log","pyFoam") 71 else: 72 return path.join(userDirectory(),"log")
73
74 -def assertDirectory(name):
75 """Makes sure that the directory exists 76 @param name: the directory""" 77 if path.exists(name): 78 return 79 else: 80 if PY3: 81 perm=eval("0o755") 82 else: 83 perm=eval("0755") 84 85 makedirs(name,mode=perm)
86 87 # Should work with Python3 and Python2 88