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 -def globalDirectory():
12 """@return: the global directory""" 13 return path.join("/etc",_pyFoamDirName)
14
15 -def globalConfigFile():
16 """@return: The name of the global configuration File""" 17 return path.join(globalDirectory(),_pyFoamConfigName)
18
19 -def globalConfigDir():
20 """@return: The name of the global configuration directory where .cfg-files can be placed""" 21 return globalConfigFile()+".d"
22
23 -def userDirectory():
24 """@return: the user directory""" 25 return path.expanduser(path.join("~","."+_pyFoamDirName))
26
27 -def userConfigFile():
28 """@return: The name of the user configuration File""" 29 return path.join(userDirectory(),_pyFoamConfigName)
30
31 -def userConfigDir():
32 """@return: The name of the user configuration directory where .cfg-files can be placed""" 33 return userConfigFile()+".d"
34
35 -def userName():
36 """@return: name of the current user""" 37 user="" 38 if "USER" in environ: 39 user=environ["USER"] 40 return user
41
42 -def logDirectory():
43 """Path to the log directory that this user may write to. 44 /var/log/pyFoam for root, ~/.pyFoam/log for all others 45 @return: path to the log directory.""" 46 if userName()=="root": 47 return path.join("/var/log","pyFoam") 48 else: 49 return path.join(userDirectory(),"log")
50
51 -def assertDirectory(name):
52 """Makes sure that the directory exists 53 @param name: the directory""" 54 if path.exists(name): 55 return 56 else: 57 if PY3: 58 perm=eval("0o755") 59 else: 60 perm=eval("0755") 61 62 makedirs(name,mode=perm)
63 64 # Should work with Python3 and Python2 65