-
Notifications
You must be signed in to change notification settings - Fork 0
/
la
executable file
·166 lines (126 loc) · 5.76 KB
/
la
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python3
#
# Copyright 2019 Vitalii Dmitriev
#
# 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.
import argparse
import logging
import multiprocessing
import os
import sys
from os import listdir
from os.path import abspath, basename, dirname, isfile, join
from subprocess import call
logger = logging.getLogger()
VERSION = '0.1.7'
ADB = 'adb'
PLATFORM = 'darwin' if sys.platform == 'darwin' else 'linux-x86'
SOONG_BIN_DIR = '/out/soong/host/%s/bin/' % PLATFORM
try:
OUT = os.environ['ANDROID_PRODUCT_OUT']
except KeyError:
logger.warning('$ANDROID_PRODUCT_OUT was not exported. Trying to use $OUT instead...')
try:
OUT = os.environ['OUT']
except KeyError:
raise KeyError('A build/envsetup.sh file was not sourced. Perform: source build/envsetup.sh')
def get_device_path(out_dir_path):
return "/%s" % out_dir_path.split(OUT)[-1]
def find_out(args):
if args.strict:
call(['find', OUT, '-name', "%s" % args.name])
else:
call(['find', OUT, '-iname', "*%s*" % args.name])
def find_file(abs_path):
path = dirname(abs_path)
name = basename(abs_path)
files = [file for file in listdir(path) if isfile(join(path, file)) and file.startswith(name)]
if len(files):
return files[0]
else:
raise FileNotFoundError()
def push_file(args):
"""TODO: check whether the adb installed before call!"""
abs_path = abspath(args.file)
if args.dir:
data = dirname(abs_path)
else:
data = find_file(args.file)
call([ADB, 'push', data, get_device_path(abs_path)])
def remount_as_root(args):
call([ADB, 'root'])
call([ADB, 'remount'])
def make(args):
jobs = args.jobs if args.jobs else multiprocessing.cpu_count() + 1
if args.lunch:
call(['source', 'build/envsetup.sh'])
call(['lunch', args.lunch])
if args.app:
call(['mma', args.app, '-j', jobs])
else:
call(['make', '-j', jobs])
def ship(args):
branch = args.branch if args.branch.startswith('HEAD:') else 'HEAD:refs/for/%s' % args.branch
call(['git', 'push', args.remote or 'origin', branch])
def on(args):
pass
def off(args):
pass
def copy(args):
call(['cpstr', '-s', args.source, '-d', args.destination, '-n', args.name])
def ignore(args):
print('[DEPRECATED]: use la on/la off when implemented!')
call(['mignore', args.directory])
def main():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
ship_parser = subparsers.add_parser('ship', help='''Send a code to Gerrit.
More flexible equivalent to git push origin HEAD:refs/for/branch''')
ship_parser.add_argument('-r', '--remote', help='Specify a remote, if need to use non-default')
ship_parser.add_argument('branch', help='''A branch name like master or HEAD:refs/meta/config.
If just a name was specified, creates a full branch name before push: master will become a HEAD:refs/for/master''')
ship_parser.set_defaults(function=ship)
make_parser = subparsers.add_parser('make', help='Build a firmware or an application')
make_parser.add_argument('''-l''', '''--lunch''', help='''If specified, init a new environment for a specific built
type. Can either be a number or a name''')
make_parser.add_argument('''--app''', help='''Build an app instead of a firmware.
Specify a project name (can be found in a manifest file)''')
make_parser.add_argument('-j', '--jobs', type=int, help='''Specify a number of tasks. See make -j.
If not specified, uses a number of cores + 1 by default''')
make_parser.set_defaults(function=make)
subparsers.add_parser('rr', help='adb root && adb remount').set_defaults(function=remount_as_root)
subparsers.add_parser('root', help='Same as rr').set_defaults(function=remount_as_root)
ignore_parser = subparsers.add_parser('ignore', help='Ignore or get back an Android.mk based project.')
ignore_parser.add_argument('directory', help="A directory to ignore a project in")
ignore_parser.set_defaults(function=ignore)
push_parser = subparsers.add_parser('push', help='''Push a file to the device.
The filename can be provider either with an extension, or without.
If several files were found, will push the first one''')
push_parser.add_argument('file', help='Name or path of an apk file')
push_parser.add_argument('-d', '--dir', action='store_true', help='Push the whole directory')
push_parser.set_defaults(function=push_file)
find_parser = subparsers.add_parser('find', help='Find something in out directory')
find_parser.add_argument('name', help='A name of a file to find')
find_parser.add_argument('-s', '--strict', action='store_true',
help='Strict search: case sensitive and full name with an extension (if any)')
find_parser.set_defaults(function=find_out)
copy_parser = subparsers.add_parser('copy', help='''Copy a string.xml string from one set of directories to another.
For now just calls the cpstr script.''')
copy_parser.add_argument('-s', '--source')
copy_parser.add_argument('-d', '--destination')
copy_parser.add_argument('-n', '--name')
copy_parser.set_defaults(function=copy)
args = parser.parse_args()
args.function(args)
if __name__ == "__main__":
sys.exit(main())