File: jhbuildutils.py

package info (click to toggle)
qtwebkit-opensource-src 5.7.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 291,692 kB
  • ctags: 268,122
  • sloc: cpp: 1,360,420; python: 70,286; ansic: 42,986; perl: 35,476; ruby: 12,236; objc: 9,465; xml: 8,396; asm: 3,873; yacc: 2,397; sh: 1,647; makefile: 650; lex: 644; java: 110
file content (53 lines) | stat: -rw-r--r-- 1,843 bytes parent folder | download | duplicates (6)
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
import glob
import os.path
import sys
import __builtin__

top_level_dir = None


def top_level_path(*args):
    global top_level_dir
    if not top_level_dir:
        top_level_dir = os.path.join(os.path.dirname(__file__), '..', '..')
    return os.path.join(*(top_level_dir,) + args)


def get_dependencies_path():
    if 'WEBKIT_OUTPUTDIR' in os.environ:
        return os.path.abspath(os.path.join(os.environ['WEBKIT_OUTPUTDIR'], 'Dependencies'))
    else:
        return os.path.abspath(top_level_path('WebKitBuild', 'Dependencies'))


def get_config_file_for_platform(platform):
    return top_level_path('Tools', platform, 'jhbuildrc')


def enter_jhbuild_environment_if_available(platform):
    if not os.path.exists(get_dependencies_path()):
        return False

    # Sometimes jhbuild chooses to install in a way that reads the library from the source directory, so fall
    # back to that method.
    source_path = os.path.join(get_dependencies_path(), "Source", "jhbuild")
    sys.path.insert(0, source_path)

    # When loading jhbuild from the source checkout it fails if the SRCDIR variable is not set.
    __builtin__.__dict__['SRCDIR'] = source_path

    # We don't know the Python version, so we just assume that we can safely take the first one in the list.
    site_packages_path = glob.glob(os.path.join(get_dependencies_path(), "Root", "lib", "*", "site-packages"))
    if len(site_packages_path):
       site_packages_path = site_packages_path[0]
       sys.path.insert(0, site_packages_path)

    try:
        import jhbuild.config
        from jhbuild.errors import FatalError
        config = jhbuild.config.Config(get_config_file_for_platform(platform))
    except FatalError, exception:
        sys.stderr.write('Could not load jhbuild config file: %s\n' % exception.args[0])
        return False

    return True