~doanac/phablet-tools/phablet-device

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
64
#! /usr/bin/python2.7
# Copyright (C) 2013 Canonical Ltd.
# Author: Sergio Schvezov <sergio.schvezov@canonical.com>

# 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; version 3 of the License.
#
# 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 logging
import os
import sys

from phabletutils.device import (AndroidBridge, Fastboot)
from phabletutils import arguments
from phabletutils import license
from phabletutils import settings

logging.basicConfig(level=logging.INFO)
log = logging.getLogger()
log.name = 'phablet-flash'


def accepted_pathname():
    return os.path.expanduser(settings.accept_path)


def main(argv):
    parser = arguments.get_parser()
    args = parser.parse_args(argv[1:])
    if args.debug:
        log.setLevel(logging.DEBUG)
    if not license.has_accepted(accepted_pathname()) and \
       not license.query(settings.legal_notice, accepted_pathname()):
        exit(1)
    try:
        project = args.func(args)
        if project:
            fastboot = Fastboot(args.serial)
            adb = AndroidBridge(args.serial)
            adb.start()
            project.download()
            if not args.download_only:
                project.install(adb, fastboot)
    except KeyboardInterrupt:
        log.info('Provisioning manually interrupted. Resume by rerunning '
                 'the command')
        exit(1)
    except Exception as e:
        log.error(e)
        if args.debug:
            log.exception(e)
        exit(1)


if __name__ == "__main__":
    main(sys.argv)