]> SALOME platform Git repositories - tools/eficas.git/blob - Pmw/Pmw_1_2/bin/bundlepmw.py
Salome HOME
Modif V6_4_°
[tools/eficas.git] / Pmw / Pmw_1_2 / bin / bundlepmw.py
1 #!/usr/bin/env python
2
3 # Helper script when freezing Pmw applications.  It concatenates all
4 # Pmw megawidget files into a single file, 'Pmw.py', in the current
5 # directory.  The script must be called with one argument, being the
6 # path to the 'lib' directory of the required version of Pmw.
7 # To freeze a Pmw application, you will also need to copy the
8 # following files to the application directory before freezing:
9 #
10 #    PmwBlt.py PmwColor.py
11
12 import os
13 import regsub
14 import string
15 import sys
16
17 # The order of these files is significant.  Files which reference
18 # other files must appear later.  Files may be deleted if they are not
19 # used.
20 files = [
21     'Dialog', 'TimeFuncs', 'Balloon', 'ButtonBox', 'EntryField',
22     'Group', 'LabeledWidget', 'MainMenuBar', 'MenuBar', 'MessageBar',
23     'MessageDialog', 'NoteBook', 'OptionMenu', 'PanedWidget', 'PromptDialog',
24     'RadioSelect', 'ScrolledCanvas', 'ScrolledField', 'ScrolledFrame',
25     'ScrolledListBox', 'ScrolledText', 'HistoryText', 'SelectionDialog',
26     'TextDialog', 'TimeCounter', 'AboutDialog', 'ComboBox', 'ComboBoxDialog',
27     'Counter', 'CounterDialog',
28 ]
29
30 # Set this to 0 if you do not use any of the Pmw.Color functions:
31 needColor = 1
32
33 # Set this to 0 if you do not use any of the Pmw.Blt functions:
34 needBlt = 1
35
36 def expandLinks(path):
37     if not os.path.isabs(path):
38         path = os.path.join(os.getcwd(), path)
39     while 1:
40         if not os.path.islink(path):
41             break
42         dir = os.path.dirname(path)
43         path = os.path.join(dir, os.readlink(path))
44
45     return path
46
47 def mungeFile(file):
48     # Read the file and modify it so that it can be bundled with the
49     # other Pmw files.
50     file = 'Pmw' + file + '.py'
51     text = open(os.path.join(srcdir, file)).read()
52     text = regsub.gsub('import Pmw\>', '', text)
53     text = regsub.gsub('INITOPT = Pmw.INITOPT', '', text)
54     text = regsub.gsub('\<Pmw\.', '', text)
55     text = '\n' + ('#' * 70) + '\n' + '### File: ' + file + '\n' + text
56     return text
57
58 # Work out which version is being bundled.
59 file = sys.argv[0]
60 file = os.path.normpath(file)
61 file = expandLinks(file)
62
63 dir = os.path.dirname(file)
64 dir = expandLinks(dir)
65 dir = os.path.dirname(dir)
66 dir = expandLinks(dir)
67 dir = os.path.basename(dir)
68
69 version = string.replace(dir[4:], '_', '.')
70
71 # Code to import the Color module.
72 colorCode = """
73 import PmwColor
74 Color = PmwColor
75 del PmwColor
76 """
77
78 # Code to import the Blt module.
79 bltCode = """
80 import PmwBlt
81 Blt = PmwBlt
82 del PmwBlt
83 """
84
85 # Code used when not linking with PmwBlt.py.
86 ignoreBltCode = """
87 _bltImported = 1
88 _bltbusyOK = 0
89 """
90
91 # Code to define the functions normally supplied by the dynamic loader.
92 extraCode = """
93
94 ### Loader functions:
95
96 _VERSION = '%s'
97
98 def setversion(version):
99     if version != _VERSION:
100         raise ValueError, 'Dynamic versioning not available'
101
102 def setalphaversions(*alpha_versions):
103     if alpha_versions != ():
104         raise ValueError, 'Dynamic versioning not available'
105
106 def version(alpha = 0):
107     if alpha:
108         return ()
109     else:
110         return _VERSION
111
112 def installedversions(alpha = 0):
113     if alpha:
114         return ()
115     else:
116         return (_VERSION,)
117
118 """
119
120 if '-noblt' in sys.argv:
121     sys.argv.remove('-noblt')
122     needBlt = 0
123
124 if '-nocolor' in sys.argv:
125     sys.argv.remove('-nocolor')
126     needColor = 0
127
128 if len(sys.argv) != 2:
129     print 'usage: bundlepmw.py [-noblt] [-nocolor] /path/to/Pmw/Pmw_X_X_X/lib'
130     sys.exit()
131
132 srcdir = sys.argv[1]
133
134 if os.path.exists('Pmw.py'):
135     print 'Pmw.py already exists. Remove it and try again.'
136     sys.exit()
137     
138 outfile = open('Pmw.py', 'w')
139
140 if needColor:
141     outfile.write(colorCode)
142
143 if needBlt:
144     outfile.write(bltCode)
145
146 outfile.write(extraCode % version)
147
148 # Specially handle PmwBase.py file:
149 text = mungeFile('Base')
150 text = regsub.gsub('import PmwLogicalFont', '', text)
151 text = regsub.gsub('PmwLogicalFont._font_initialise', '_font_initialise', text)
152 outfile.write(text)
153 if not needBlt:
154     outfile.write(ignoreBltCode)
155
156 files.append('LogicalFont')
157 for file in files:
158     text = mungeFile(file)
159     outfile.write(text)
160
161 print ''
162 print '   Pmw.py has been created.'
163
164 if needColor or needBlt:
165     print '   Before running freeze, also copy the following file(s):'
166     if needBlt:
167         print '   ' + os.path.join(srcdir, 'PmwBlt.py')
168     if needColor:
169         print '   ' + os.path.join(srcdir, 'PmwColor.py')