Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / lib / python2.4 / site-packages / Pmw / __init__.py
CommitLineData
920dae64
AT
1# This file is executed when the Pmw package is imported. It creates
2# a lazy importer/dynamic loader for Pmw and replaces the Pmw module
3# with it. Even though the loader from the most recent installed
4# version of Pmw is used, the user is able to specify which version of
5# Pmw megawidgets to load by using the setversion() function of the
6# loader.
7
8# This is the only file in Pmw which is not part of a particular Pmw
9# release.
10
11import sys
12import os
13import re
14
15def _hasLoader(dir):
16 # Only accept Pmw_V_R_P with single digits, since ordering will
17 # not work correctly with multiple digits (for example, Pmw_10_0
18 # will be before Pmw_9_9).
19 if re.search('^Pmw_[0-9]_[0-9](_[0-9])?$', dir) is not None:
20 for suffix in ('.py', '.pyc', '.pyo'):
21 path = os.path.join(_dir, dir, 'lib', 'PmwLoader' + suffix)
22 if os.path.isfile(path):
23 return 1
24 return 0
25
26# First get a list of all subdirectories containing versions of Pmw.
27_dir = __path__[0]
28_listdir = os.listdir(_dir)
29_instdirs = filter(_hasLoader, _listdir)
30_instdirs.sort()
31_instdirs.reverse()
32
33# Using the latest version import the dynamic loader.
34_loader = 'Pmw.' + _instdirs[0] + '.lib.PmwLoader'
35__import__(_loader)
36_mod = sys.modules[_loader]
37
38# Create the dynamic loader and install it into sys.modules.
39sys.modules['_Pmw'] = sys.modules['Pmw']
40sys.modules['Pmw'] = _mod.PmwLoader(_dir, _instdirs, _listdir)