~ubuntu-branches/ubuntu/warty/petsc/warty

« back to all changes in this revision

Viewing changes to python/BuildSystem/setsplicers.py

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2004-06-07 13:41:43 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040607134143-92p586zrauvie0le
Tags: 2.2.0-2
* Upstream patch level 2.
* New PETSC_BOPT_EXTRA option for different BOPT and lib names, with _c++
  symlinks only for plain and single (closes: #249617).
* New DEBIAN_DIST=contrib option to link with hypre, parmetis (closes:
  #249619).
* Combined petsc-c and petsc-fortran substvars into petsc-compilers.
* Extra quote in -dev prerm eliminates "too many arguments" problem.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
#   This is absolute crap; we really need to parse the impls and process them
 
4
#
 
5
import user
 
6
 
 
7
import os
 
8
import sys
 
9
import re
 
10
import cPickle
 
11
import string
 
12
 
 
13
def setSplicersDir(splicedimpls,dir,names):
 
14
 
 
15
  reg        = re.compile('splicer.begin\(([A-Za-z0-9._]*)\)')
 
16
  reginclude = re.compile('#include [ ]*"([a-zA-Z_0-9/]*.[h]*)"')
 
17
 
 
18
  if 'SCCS' in names: del names[names.index('SCCS')]
 
19
  if 'BitKeeper' in names: del names[names.index('BitKeeper')]
 
20
  if 'docs' in names: del names[names.index('docs')]
 
21
  for f in names:
 
22
    ext = os.path.splitext(f)[1]
 
23
    if not ext in splicedimpls: continue
 
24
    if f == '__init__.py': continue
 
25
    if not os.path.isfile(os.path.join(dir,f)): continue
 
26
    fd = open(os.path.join(dir,f),'r')
 
27
    foundreplacement = 0
 
28
    text = ''
 
29
    line = fd.readline()
 
30
    while line:
 
31
      text = text+line
 
32
      if not line.find('splicer.begin') == -1:
 
33
        fl = reg.search(line)
 
34
        name = fl.group(1)
 
35
 
 
36
        line = fd.readline()
 
37
        body = ''
 
38
        while line.find('splicer.end') == -1:
 
39
          body = body + line
 
40
          line = fd.readline()
 
41
 
 
42
            
 
43
        # replace body with saved splicer block
 
44
        if name.endswith('._includes') and ext == '.cc':
 
45
          foundreplacement = 1
 
46
#          print 'handling includes for class '+name
 
47
          name = name[0:-10]
 
48
          len1  = len(name)
 
49
          body = '#include "SIDL.hh"\n'
 
50
          for n in splicedimpls[ext]:
 
51
            if n.startswith(name) and n.endswith('._includes') and n[len1+1:-10].find('.') == -1:
 
52
#              print '   '+n
 
53
              body = body + splicedimpls[ext][n]
 
54
        elif name in splicedimpls[ext]:
 
55
          foundreplacement = 1
 
56
#          print 'Replacing -------'+name
 
57
#          print body
 
58
#          print 'with ------------'
 
59
#          print splicedimpls[ext][name]
 
60
          body = splicedimpls[ext][name]
 
61
        else:
 
62
#          print 'Cannot find splicer block '+name+' '+f+' ext '+ext
 
63
          pass
 
64
          
 
65
#         convert ASE directory hierarchy of includes
 
66
        nb = ''
 
67
        for l in body.split('\n'):
 
68
          if reginclude.search(l):
 
69
            fname    = reginclude.match(l).group(1)
 
70
            (fn,extmp) = os.path.splitext(fname)
 
71
            fn = fn.split('/')
 
72
            if len(fn) > 1 and fn[-1] == fn[-2]:
 
73
              t = '#include "'+string.join(fn[0:-1],'_')+'.hh"'
 
74
              nb = nb + t + '\n'
 
75
            else:
 
76
              nb = nb + l + '\n'              
 
77
          else:
 
78
            nb = nb + l + '\n'              
 
79
          
 
80
        text = text+nb
 
81
        text = text+line
 
82
      line = fd.readline()
 
83
    fd.close()
 
84
 
 
85
    if foundreplacement:
 
86
#      print 'Replaced blocks in '+os.path.join(dir,f)
 
87
      fd = open(os.path.join(dir,f),'w')
 
88
      fd.write(text)
 
89
      fd.close()
 
90
 
 
91
#    print text
 
92
  
 
93
def setSplicers(directory):
 
94
 
 
95
  f    = open('splicerblocks', 'r')
 
96
  splicedimpls = cPickle.load(f)
 
97
  f.close()
 
98
 
 
99
  # change SIDL.Args and SIDL.ProjectState impl names
 
100
  replaces =  {'SIDL.Args':'SIDLASE.Args','SIDL.ProjectState':'SIDLASE.ProjectState'}
 
101
  for i in splicedimpls:
 
102
    sillytmp = splicedimpls[i]
 
103
    for j in sillytmp:
 
104
      for k in replaces:
 
105
        if not string.find(j,k) == -1:
 
106
          newname = j.replace(k,replaces[k])
 
107
#          print 'Converting '+j+' to '+newname+' ext '+i
 
108
          splicedimpls[i][newname] = splicedimpls[i][j]
 
109
          del splicedimpls[i][j]
 
110
 
 
111
  
 
112
  regset    = re.compile('\.set\(([->< a-zA-Z_0-9/.\(\)\[\]&+*]*),([->< a-zA-Z_0-9/.\(\)\[\]&+*]*)\)[ ]*;')
 
113
  regcreate = re.compile('\.create\(([->< a-zA-Z_0-9/.\(\)\[\]&+*]*),([->< a-zA-Z_0-9/.\(\)\[\]&+*]*),([->< a-zA-Z_0-9/.\(\)\[\]&+*]*)\)[ ]*;')
 
114
  replaces =  {'SIDL/Args':'SIDLASE/Args',    'SIDL/ProjectState':'SIDLASE/ProjectState',
 
115
               'SIDL::Args':'SIDLASE::Args',  'SIDL::ProjectState':'SIDLASE::ProjectState',
 
116
               '.dim(':'.dimen(',             '.destroy(':'.deleteRef(',
 
117
               '.setMessage(':'.setNote(',    '.getMessage(':'getNote(',
 
118
               '.isInstanceOf(':'.isType(', ' IDENT':' MPIB::IDENT',
 
119
               ' SIMILAR':' MPIB::SIMILAR',    ' CONGRUENT':' MPIB::CONGRUENT',
 
120
               '__enum':''}
 
121
  for i in splicedimpls:
 
122
    for j in splicedimpls[i]:
 
123
      if regset.search(splicedimpls[i][j]):
 
124
        splicedimpls[i][j] = regset.sub('.set(\\2,\\1);',splicedimpls[i][j])
 
125
      if regcreate.search(splicedimpls[i][j]):
 
126
        splicedimpls[i][j] = regcreate.sub('.createRow(\\1,\\2,\\3);',splicedimpls[i][j])
 
127
      for k in replaces:    
 
128
        splicedimpls[i][j] = splicedimpls[i][j].replace(k,replaces[k])
 
129
  
 
130
  if not directory: directory = os.getcwd()
 
131
  os.path.walk(directory,setSplicersDir,splicedimpls)
 
132
 
 
133
    
 
134
if __name__ ==  '__main__':
 
135
  if len(sys.argv) > 2: sys.exit('Usage: getsplicers.py <directory>')
 
136
  sys.argv.append(None)
 
137
  setSplicers(sys.argv[1])
 
138