aboutsummaryrefslogtreecommitdiff
path: root/lava_android_test/main.py
blob: cb39a72ca0b1bb4c346f43570f1fbe1115438db9 (plain)
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
63
# Copyright (c) 2010-2012 Linaro
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import shutil
from tempfile import mkdtemp
from lava_android_test import utils
from lava_android_test.config import get_config, set_config
from lava_tool.dispatcher import LavaDispatcher, run_with_dispatcher_class


class LAVAAndroidTestDispatcher(LavaDispatcher):
    toolname = 'lava_android_test'
    description = """
    LAVA Android Test wrapper framework
    """
    epilog = """
    Please report all bugs using the Launchpad bug tracker:
    http://bugs.launchpad.net/lava-android-test/+filebug
    """


def check_adb_installed():
    return utils.check_command_exist('adb')


def main():
    if not check_adb_installed():
        print >> sys.stderr, "Can't find the command adb."
        print >> sys.stderr, ("Please add the path of adb"
                              " command to PATH environment.")
        sys.exit(1)

    config = get_config()
    try:
        if not os.path.exists(config.tempdir_host):
            os.makedirs(config.tempdir_host)
            #make every user can write/read this directory
            os.chmod(config.tempdir_host, 0777)
        config.tempdir_host = mkdtemp(dir=config.tempdir_host)
        set_config(config)
        os.chmod(config.tempdir_host, 0755)
        run_with_dispatcher_class(LAVAAndroidTestDispatcher)
    finally:
        #can't remove the parent directory, because there may be other
        #instance using the parent directory
        shutil.rmtree(config.tempdir_host)


if __name__ == '__main__':
    main()