Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / lib / python2.4 / site-packages / Pmw / Pmw_1_2 / bin / bundlepmw.py
CommitLineData
86530b38
AT
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
12import os
13import regsub
14import string
15import 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.
20files = [
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:
31needColor = 1
32
33# Set this to 0 if you do not use any of the Pmw.Blt functions:
34needBlt = 1
35
36def 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
47def 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.
59file = sys.argv[0]
60file = os.path.normpath(file)
61file = expandLinks(file)
62
63dir = os.path.dirname(file)
64dir = expandLinks(dir)
65dir = os.path.dirname(dir)
66dir = expandLinks(dir)
67dir = os.path.basename(dir)
68
69version = string.replace(dir[4:], '_', '.')
70
71# Code to import the Color module.
72colorCode = """
73import PmwColor
74Color = PmwColor
75del PmwColor
76"""
77
78# Code to import the Blt module.
79bltCode = """
80import PmwBlt
81Blt = PmwBlt
82del PmwBlt
83"""
84
85# Code used when not linking with PmwBlt.py.
86ignoreBltCode = """
87_bltImported = 1
88_bltbusyOK = 0
89"""
90
91# Code to define the functions normally supplied by the dynamic loader.
92extraCode = """
93
94### Loader functions:
95
96_VERSION = '%s'
97
98def setversion(version):
99 if version != _VERSION:
100 raise ValueError, 'Dynamic versioning not available'
101
102def setalphaversions(*alpha_versions):
103 if alpha_versions != ():
104 raise ValueError, 'Dynamic versioning not available'
105
106def version(alpha = 0):
107 if alpha:
108 return ()
109 else:
110 return _VERSION
111
112def installedversions(alpha = 0):
113 if alpha:
114 return ()
115 else:
116 return (_VERSION,)
117
118"""
119
120if '-noblt' in sys.argv:
121 sys.argv.remove('-noblt')
122 needBlt = 0
123
124if '-nocolor' in sys.argv:
125 sys.argv.remove('-nocolor')
126 needColor = 0
127
128if len(sys.argv) != 2:
129 print 'usage: bundlepmw.py [-noblt] [-nocolor] /path/to/Pmw/Pmw_X_X_X/lib'
130 sys.exit()
131
132srcdir = sys.argv[1]
133
134if os.path.exists('Pmw.py'):
135 print 'Pmw.py already exists. Remove it and try again.'
136 sys.exit()
137
138outfile = open('Pmw.py', 'w')
139
140if needColor:
141 outfile.write(colorCode)
142
143if needBlt:
144 outfile.write(bltCode)
145
146outfile.write(extraCode % version)
147
148# Specially handle PmwBase.py file:
149text = mungeFile('Base')
150text = regsub.gsub('import PmwLogicalFont', '', text)
151text = regsub.gsub('PmwLogicalFont._font_initialise', '_font_initialise', text)
152outfile.write(text)
153if not needBlt:
154 outfile.write(ignoreBltCode)
155
156files.append('LogicalFont')
157for file in files:
158 text = mungeFile(file)
159 outfile.write(text)
160
161print ''
162print ' Pmw.py has been created.'
163
164if 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')