Commits

Satish Balay committed 994b4da

cmake: fixup to work with python2.4 the - the current configure requirement

  • Participants
  • Parent commits 05b4f60

Comments (0)

Files changed (3)

File config/PETSc/Configure.py

 
   def dumpCMakeLists(self):
     import sys
-    if sys.version_info >= (2,5):
+    if sys.version_info >= (2,4):
       import cmakegen
       try:
         cmakegen.main(self.petscdir.dir, log=self.framework.log)
   def cmakeBoot(self):
     import sys
     self.cmakeboot_success = False
-    if sys.version_info >= (2,5) and hasattr(self.cmake,'cmake'):
+    if sys.version_info >= (2,4) and hasattr(self.cmake,'cmake'):
       try:
         import cmakeboot
         self.cmakeboot_success = cmakeboot.main(petscdir=self.petscdir.dir,petscarch=self.arch.arch,argDB=self.argDB,framework=self.framework,log=self.framework.log)

File config/cmakeboot.py

 #
 # by configure before running this script.
 
-from __future__ import with_statement  # For python-2.5
-
 import os,sys,string
 from collections import deque
 sys.path.insert(0, os.path.join(os.path.abspath('config')))
      self.logPrint('Output: '+output+'\nError: '+error)
      cachetxt = os.path.join(archdir, 'CMakeCache.txt')
      try:
-       with open(cachetxt, 'r') as f:
-         log.write('Contents of %s:\n' % cachetxt)
-         log.write(f.read())
+       f = open(cachetxt, 'r')
+       log.write('Contents of %s:\n' % cachetxt)
+       log.write(f.read())
+       f.close()
      except IOError, e:
        log.write('Could not read file %s: %r\n' % (cachetxt, e))
      return False

File config/cmakegen.py

 # This script supports one option:
 #   --verbose : Show mismatches between makefiles and the filesystem
 
-from __future__ import with_statement  # For python-2.5
-
 import os
-from collections import defaultdict, deque
+from collections import deque
 
+# compatibility code for python-2.4 from http://code.activestate.com/recipes/523034-emulate-collectionsdefaultdict/
+try:
+    from collections import defaultdict
+except:
+    class defaultdict(dict):
+        def __init__(self, default_factory=None, *a, **kw):
+            if (default_factory is not None and
+                not hasattr(default_factory, '__call__')):
+                raise TypeError('first argument must be callable')
+            dict.__init__(self, *a, **kw)
+            self.default_factory = default_factory
+        def __getitem__(self, key):
+            try:
+                return dict.__getitem__(self, key)
+            except KeyError:
+                return self.__missing__(key)
+        def __missing__(self, key):
+            if self.default_factory is None:
+                raise KeyError(key)
+            self[key] = value = self.default_factory()
+            return value
+        def __reduce__(self):
+            if self.default_factory is None:
+                args = tuple()
+            else:
+                args = self.default_factory,
+            return type(self), args, None, None, self.items()
+        def copy(self):
+            return self.__copy__()
+        def __copy__(self):
+            return type(self)(self.default_factory, self)
+        def __deepcopy__(self, memo):
+            import copy
+            return type(self)(self.default_factory,
+                              copy.deepcopy(self.items()))
+        def __repr__(self):
+            return 'defaultdict(%s, %s)' % (self.default_factory,
+                                            dict.__repr__(self))
 # Run with --verbose
 VERBOSE = False
 MISTAKES = []
     compareDirLists(mdirs,dirs) # diagnostic output to find unused directories
     candidates = set(mdirs).union(autodirs).difference(skipdirs)
     dirs[:] = list(candidates.intersection(dirs))
-    with open(makefile) as lines:
-      def stripsplit(line):
-        return filter(lambda c: c!="'", line[len('#requires'):]).split()
-      conditions.update(set(tuple(stripsplit(line)) for line in lines if line.startswith('#requires')))
+    lines = open(makefile)
+    def stripsplit(line):
+      return filter(lambda c: c!="'", line[len('#requires'):]).split()
+    conditions.update(set(tuple(stripsplit(line)) for line in lines if line.startswith('#requires')))
+    lines.close()
     def relpath(filename):
       return os.path.join(root,filename)
     sourcec = makevars.get('SOURCEC','').split()
   written = False               # We delete the temporary file if it wasn't finished, otherwise rename (atomic)
   fd,tmplists = tempfile.mkstemp(prefix='CMakeLists.txt.',dir=petscdir,text=True)
   try:
-    with os.fdopen(fd,'w') as f:
-      writeRoot(f)
-      f.write('include_directories (${PETSC_PACKAGE_INCLUDES})\n')
-      pkglist = [('sys'            , ''),
-                 ('vec'            , 'sys'),
-                 ('mat'            , 'vec sys'),
-                 ('dm'             , 'mat vec sys'),
-                 ('ksp'            , 'dm mat vec sys'),
-                 ('snes'           , 'ksp dm mat vec sys'),
-                 ('ts'             , 'snes ksp dm mat vec sys')]
-      for pkg,deps in pkglist:
-        writePackage(f,pkg,deps.split())
-      f.write ('''
+    f = os.fdopen(fd,'w')
+    writeRoot(f)
+    f.write('include_directories (${PETSC_PACKAGE_INCLUDES})\n')
+    pkglist = [('sys'            , ''),
+               ('vec'            , 'sys'),
+               ('mat'            , 'vec sys'),
+               ('dm'             , 'mat vec sys'),
+               ('ksp'            , 'dm mat vec sys'),
+               ('snes'           , 'ksp dm mat vec sys'),
+               ('ts'             , 'snes ksp dm mat vec sys')]
+    for pkg,deps in pkglist:
+      writePackage(f,pkg,deps.split())
+    f.write ('''
 if (PETSC_USE_SINGLE_LIBRARY)
   add_library (petsc %s)
   target_link_libraries (petsc ${PETSC_PACKAGE_LIBS})
 
 endif ()
 ''' % (' '.join([r'${PETSC' + pkg.upper() + r'_SRCS}' for pkg,deps in pkglist]),))
-      f.write('''
+    f.write('''
 if (PETSC_CLANGUAGE_Cxx)
   foreach (file IN LISTS %s)
     if (file MATCHES "^.*\\\\.c$")
   endforeach ()
 endif()''' % ('\n  '.join([r'PETSC' + pkg.upper() + r'_SRCS' for (pkg,_) in pkglist])))
     written = True
+    f.close()
   finally:
     if written:
       shutil.move(tmplists,os.path.join(petscdir,'CMakeLists.txt'))