File: DemoVersion.py

package info (click to toggle)
python-pmw 2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,968 kB
  • sloc: python: 42,737; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 953 bytes parent folder | download | duplicates (2)
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 importlib
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 = importlib.util.find_spec(__name__).origin
    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 = dir[4:].replace('_', '.')
    import Pmw
    if version in Pmw.installedversions():
        Pmw.setversion(version)
    else:
        print('No such Pmw version ' + str(version) + '.')
        print('Using default version ' + str(Pmw.version()))