forked from google/python-adb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfastboot_debug.py
More file actions
executable file
·119 lines (98 loc) · 3.55 KB
/
Copy pathfastboot_debug.py
File metadata and controls
executable file
·119 lines (98 loc) · 3.55 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Fastboot in python.
Call it similar to how you call android's fastboot. Call it similar to how you
call android's fastboot, but this only accepts usb paths and no serials.
"""
import argparse
import inspect
import logging
import sys
import progressbar
import common_cli
import fastboot
def Devices(args):
"""Lists the available devices.
List of devices attached
015DB7591102001A device
"""
for device in fastboot.FastbootCommands.Devices():
print('%s\tdevice' % device.serial_number)
return 0
def _InfoCb(message):
# Use an unbuffered version of stdout.
if not message.message:
return
sys.stdout.write('%s: %s\n' % (message.header, message.message))
sys.stdout.flush()
def main():
common = common_cli.GetCommonArguments()
device = common_cli.GetDeviceArguments()
device.add_argument(
'--chunk_kb', type=int, default=1024, metavar='1024',
help='Size of packets to write in Kb. For older devices, it may be '
'required to use 4.')
parents = [common, device]
parser = argparse.ArgumentParser(
description=sys.modules[__name__].__doc__, parents=[common])
subparsers = parser.add_subparsers(title='Commands', dest='command_name')
subparser = subparsers.add_parser(
name='help', help='Prints the commands available')
subparser = subparsers.add_parser(
name='devices', help='Lists the available devices', parents=[common])
common_cli.MakeSubparser(
subparsers, parents, fastboot.FastbootCommands.Continue)
common_cli.MakeSubparser(
subparsers, parents, fastboot.FastbootCommands.Download,
{'source_file': 'Filename on the host to push'})
common_cli.MakeSubparser(
subparsers, parents, fastboot.FastbootCommands.Erase)
common_cli.MakeSubparser(
subparsers, parents, fastboot.FastbootCommands.Flash)
common_cli.MakeSubparser(
subparsers, parents, fastboot.FastbootCommands.Getvar)
common_cli.MakeSubparser(
subparsers, parents, fastboot.FastbootCommands.Oem)
common_cli.MakeSubparser(
subparsers, parents, fastboot.FastbootCommands.Reboot)
if len(sys.argv) == 1:
parser.print_help()
return 2
args = parser.parse_args()
if args.verbose:
logging.basicConfig(level=logging.DEBUG)
if args.command_name == 'devices':
return Devices(args)
if args.command_name == 'help':
parser.print_help()
return 0
kwargs = {}
argspec = inspect.getargspec(args.method)
if 'info_cb' in argspec.args:
kwargs['info_cb'] = _InfoCb
if 'progress_callback' in argspec.args:
bar = progressbar.ProgessBar(
widgets=[progressbar.Bar(), progressbar.Percentage()])
bar.start()
def SetProgress(current, total):
bar.update(current / total * 100.0)
if current == total:
bar.finish()
kwargs['progress_callback'] = SetProgress
return common_cli.StartCli(
args, fastboot.FastbootCommands.ConnectDevice, chunk_kb=args.chunk_kb,
extra=kwargs)
if __name__ == '__main__':
sys.exit(main())