aboutsummaryrefslogtreecommitdiffstats
path: root/python/servo/bootstrapper/base.py
blob: 40f3d1f5ebc70838d98d84c8e30597d5f8e3d9c7 (plain) (blame)
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
62
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

from __future__ import print_function, unicode_literals

import distutils
import subprocess


class BaseBootstrapper(object):
    """Base class for system bootstrappers."""

    def __init__(self, interactive=False):
        self.package_manager_updated = False
        self.interactive = interactive

    def ensure_system_packages(self):
        '''
        Check for missing packages.
        '''
        raise NotImplementedError('%s must implement ensure_system_packages()' %
                                  __name__)

    def install_system_packages(self):
        '''
        Install packages required to build Servo.
        '''
        raise NotImplementedError('%s must implement install_system_packages()' %
                                  __name__)

    def install_mobile_android_packages(self):
        '''
        Install packages required to build Servo for Android.
        '''
        raise NotImplementedError('Cannot bootstrap Servo for Android: '
                                  '%s does not yet implement install_mobile_android_packages()'
                                  % __name__)

    def which(self, name):
        """Python implementation of which.

        It returns the path of an executable or None if it couldn't be found.
        """
        return distutils.spawn.find_executable(name)

    def check_output(self, *args, **kwargs):
        """Run subprocess.check_output."""
        return subprocess.check_output(*args, **kwargs)

    def _ensure_package_manager_updated(self):
        if self.package_manager_updated:
            return

        self._update_package_manager()
        self.package_manager_updated = True

    def _update_package_manager(self):
        """Updates the package manager's manifests/package list.

        This should be defined in child classes.
        """