PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/hpc_kernel_samples/sparse_linear_algebra/casestudies/pagerank-petsc/petsc-2.3.2-p10/python/PETSc/utilities/petscdir.py

https://gitlab.com/steinret/CodeVault
Python | 146 lines | 144 code | 2 blank | 0 comment | 5 complexity | 433777b211cd0bd5f55945ff34f73b1a MD5 | raw file
  1. import config.base
  2. import os
  3. import re
  4. class Configure(config.base.Configure):
  5. def __init__(self, framework):
  6. config.base.Configure.__init__(self, framework)
  7. self.headerPrefix = 'PETSC'
  8. self.substPrefix = 'PETSC'
  9. self.isPetsc = 1
  10. return
  11. def __str__(self):
  12. if not hasattr(self, 'dir'):
  13. return ''
  14. desc = []
  15. cdir = str(self.dir)
  16. envdir = os.getenv('PETSC_DIR')
  17. if not cdir == envdir :
  18. desc.append(' **\n ** Before running "make" your PETSC_DIR must be specified with:')
  19. desc.append(' ** ** setenv PETSC_DIR '+str(cdir)+' (csh/tcsh)')
  20. desc.append(' ** ** PETSC_DIR='+str(cdir)+'; export PETSC_DIR (sh/bash)\n **')
  21. else:
  22. desc.append(' PETSC_DIR: '+str(self.dir))
  23. desc.append(' **\n ** Now build and test the libraries with "make all test"\n **')
  24. return '\n'.join(desc)+'\n'
  25. def setupHelp(self, help):
  26. import nargs
  27. help.addArgument('PETSc', '-PETSC_DIR', nargs.Arg(None, None, 'The root directory of the PETSc installation'))
  28. help.addArgument('PETSc', '-with-installation-method=<method>', nargs.Arg(None, 'tarball', 'Method of installation, e.g. tarball, clone, etc.'))
  29. return
  30. def configureDirectories(self):
  31. '''Checks PETSC_DIR and sets if not set'''
  32. if 'PETSC_DIR' in self.framework.argDB:
  33. self.dir = self.framework.argDB['PETSC_DIR']
  34. if self.dir == 'pwd':
  35. raise RuntimeError('You have set -PETSC_DIR=pwd, you need to use back quotes around the pwd\n like -PETSC_DIR=`pwd`')
  36. if not os.path.isdir(self.dir):
  37. raise RuntimeError('The value you set with -PETSC_DIR='+self.dir+' is not a directory')
  38. elif 'PETSC_DIR' in os.environ:
  39. self.dir = os.environ['PETSC_DIR']
  40. if self.dir == 'pwd':
  41. raise RuntimeError('''
  42. The environmental variable PETSC_DIR is set incorrectly. Please use the following: [notice backquotes]
  43. For sh/bash : PETSC_DIR=`pwd`; export PETSC_DIR
  44. for csh/tcsh : setenv PETSC_DIR `pwd`''')
  45. elif not os.path.isdir(self.dir):
  46. raise RuntimeError('The environmental variable PETSC_DIR '+self.dir+' is not a directory')
  47. else:
  48. self.dir = os.getcwd()
  49. if self.isPetsc and not os.path.realpath(self.dir) == os.path.realpath(os.getcwd()):
  50. raise RuntimeError('The environmental variable PETSC_DIR '+self.dir+' MUST be the current directory '+os.getcwd())
  51. if self.dir[1] == ':':
  52. try:
  53. dir = self.dir.replace('\\','/')
  54. (dir, error, status) = self.executeShellCommand('cygpath -au '+dir)
  55. self.dir = dir.replace('\n','')
  56. except RuntimeError:
  57. pass
  58. versionHeader = os.path.join(self.dir, 'include', 'petscversion.h')
  59. versionInfo = []
  60. if os.path.exists(versionHeader):
  61. f = file(versionHeader)
  62. for line in f:
  63. if line.find('define PETSC_VERSION') >= 0:
  64. versionInfo.append(line[:-1])
  65. f.close()
  66. else:
  67. raise RuntimeError('Invalid PETSc directory '+str(self.dir)+' it may not exist?')
  68. self.logPrint('Version Information:')
  69. for line in versionInfo:
  70. self.logPrint(line)
  71. self.addMakeMacro('DIR', self.dir)
  72. self.addDefine('DIR', self.dir)
  73. self.framework.argDB['search-dirs'].append(os.path.join(self.dir, 'bin', 'win32fe'))
  74. import sys
  75. auxDir = None
  76. searchDirs = [os.path.join(self.dir, 'config'), os.path.join(self.dir, 'bin', 'config')] + sys.path
  77. for dir in searchDirs:
  78. if os.path.isfile(os.path.join(dir, 'config.sub')):
  79. auxDir = dir
  80. configSub = os.path.join(auxDir, 'config.sub')
  81. configGuess = os.path.join(auxDir, 'config.guess')
  82. break
  83. if auxDir is None:
  84. raise RuntimeError('Unable to locate config.sub in '+str(searchDirs)+'.\nYour PETSc directory is incomplete.\n Get PETSc again')
  85. try:
  86. host = config.base.Configure.executeShellCommand(self.shell+' '+configGuess, log = self.framework.log)[0]
  87. output = config.base.Configure.executeShellCommand(self.shell+' '+configSub+' '+host, log = self.framework.log)[0]
  88. except RuntimeError, e:
  89. fd = open(configGuess)
  90. data = fd.read()
  91. fd.close()
  92. if data.find('\r\n') >= 0:
  93. raise RuntimeError('''It appears petsc.tar.gz is uncompressed on Windows (perhaps with Winzip)
  94. and files copied over to Unix/Linux. Windows introduces LF characters which are
  95. inappropriate on other systems. Please use gunzip/tar on the install machine.\n''')
  96. raise RuntimeError('Unable to determine host type using '+configSub+': '+str(e))
  97. m = re.match(r'^(?P<cpu>[^-]*)-(?P<vendor>[^-]*)-(?P<os>.*)$', output)
  98. if not m:
  99. raise RuntimeError('Unable to parse output of '+configSub+': '+output)
  100. self.framework.host_cpu = m.group('cpu')
  101. self.framework.host_vendor = m.group('vendor')
  102. self.framework.host_os = m.group('os')
  103. return
  104. def configureExternalPackagesDir(self):
  105. if self.framework.externalPackagesDir is None:
  106. self.externalPackagesDir = os.path.join(self.dir, 'externalpackages')
  107. else:
  108. self.externalPackagesDir = self.framework.externalPackagesDir
  109. return
  110. def configureInstallationMethod(self):
  111. if os.path.exists(os.path.join(self.dir, '.hg')):
  112. self.logPrint('This is a Mercurial clone')
  113. self.isClone = 1
  114. elif os.path.exists(os.path.join(self.dir, 'BitKeeper')):
  115. self.logPrint('This is a BitKeeper clone')
  116. self.isClone = 1
  117. elif os.path.exists(os.path.join(self.dir, 'BK')):
  118. self.logPrint('This is a fake BitKeeper clone')
  119. self.isClone = 1
  120. elif os.path.exists(os.path.join(self.dir, '_darcs')):
  121. self.logPrint('This is a DARCS clone')
  122. self.isClone = 1
  123. elif self.framework.argDB['with-installation-method'] == 'clone':
  124. self.logPrint('This is a forced clone')
  125. self.isClone = 1
  126. else:
  127. self.logPrint('This is a tarball installation')
  128. self.isClone = 0
  129. if self.isClone and not os.path.exists(os.path.join(self.dir, 'maint')):
  130. raise RuntimeError('Your petsc-dev directory is broken, remove the entire directory and start all over again')
  131. return
  132. def configure(self):
  133. self.executeTest(self.configureDirectories)
  134. self.executeTest(self.configureExternalPackagesDir)
  135. self.executeTest(self.configureInstallationMethod)
  136. return