File: DemoVersion.py

package info (click to toggle)
python-pmw 0.8.5-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,820 kB
  • ctags: 3,468
  • sloc: python: 14,898; makefile: 37; sh: 17
file content (36 lines) | stat: -rw-r--r-- 875 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Set the version of Pmw to use for the demonstrations based on the
# directory name.

import imp
import os
import string

def expandLinks(path):
    if not os.path.isabs(path):
	path = os.path.join(os.getcwd(), path)
    while 1:
	if not os.path.islink(path):
	    break
	dir = os.path.dirname(path)
	path = os.path.join(dir, os.readlink(path))

    return path

def setPmwVersion():
    file = imp.find_module(__name__)[1]
    file = os.path.normpath(file)
    file = expandLinks(file)

    dir = os.path.dirname(file)
    dir = expandLinks(dir)
    dir = os.path.dirname(dir)
    dir = expandLinks(dir)
    dir = os.path.basename(dir)

    version = string.replace(dir[4:], '_', '.')
    import Pmw
    if version in Pmw.installedversions():
	Pmw.setversion(version)
    else:
	print 'No such Pmw version', `version` + '.',
	print 'Using default version', `Pmw.version()`