File: util.py

package info (click to toggle)
indigo 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 48,936 kB
  • sloc: ansic: 332,816; cpp: 169,470; python: 20,033; java: 13,701; cs: 9,979; asm: 8,475; sql: 6,743; xml: 6,354; javascript: 1,245; sh: 555; php: 506; makefile: 54
file content (61 lines) | stat: -rw-r--r-- 1,648 bytes parent folder | download
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
import platform
import re
import sys


def isIronPython():
    return sys.platform == 'cli'


def isJython():
    return os.name == 'java'


def getIndigoVersion():
    version = ""
    cur_dir = os.path.split(__file__)[0]
    if not os.path.exists(os.path.join(cur_dir, "../../../indigo/api/indigo-version.cmake")):
        return version
    for line in open(os.path.join(cur_dir, "../../../indigo/api/indigo-version.cmake")):
        m = re.search('SET\(INDIGO_VERSION "(.*)"', line)
        if m:
            version = m.group(1)
    return version


def getCpuCount():
    if os.name == 'java':
        from java.lang import Runtime
        runtime = Runtime.getRuntime()
        cpu_count = runtime.availableProcessors()
    else:
        import multiprocessing
        cpu_count = multiprocessing.cpu_count()
    return cpu_count


def getPlatform():
    system_name = None
    if isJython():
        import java.lang.System
        osname = java.lang.System.getProperty('os.name')
        if osname.startswith('Windows'):
            system_name = 'win'
        elif osname == 'Mac OS X':
            system_name = 'mac'
        elif osname == 'Linux':
            system_name = 'linux'
        else:
            raise EnvironmentError('Unsupported operating system %s' % osname)
    else:
        if os.name == 'nt':
            system_name = 'win'
        elif os.name == 'posix':
            if platform.mac_ver()[0]:
                system_name = 'mac'
            else:
                system_name = 'linux'
        else:
            raise EnvironmentError('Unsupported operating system %s' % os.name)
    return system_name