2021-03-26 20:28:24 +00:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from voussoirkit import interactive
|
|
|
|
from voussoirkit import pathclass
|
|
|
|
from voussoirkit import pipeable
|
2021-09-24 06:42:34 +00:00
|
|
|
from voussoirkit import stringtools
|
2021-03-26 20:28:24 +00:00
|
|
|
from voussoirkit import vlogging
|
|
|
|
|
|
|
|
log = vlogging.getLogger(__name__, 'adbinstall')
|
|
|
|
|
|
|
|
def adbinstall_argparse(args):
|
|
|
|
patterns = pipeable.input_many(args.apks, skip_blank=True, strip=True)
|
2021-09-24 06:42:34 +00:00
|
|
|
apks = pathclass.glob_many(patterns, files=True)
|
2021-03-26 20:28:24 +00:00
|
|
|
installs = []
|
2021-08-10 00:37:19 +00:00
|
|
|
for apk in apks:
|
2021-03-26 20:28:24 +00:00
|
|
|
apk = pathclass.Path(apk)
|
|
|
|
if apk.is_dir:
|
|
|
|
files = apk.glob('*.apk')
|
2021-09-24 06:42:34 +00:00
|
|
|
files.sort(key=lambda x: stringtools.natural_sorter(x.basename.lower()))
|
2021-03-26 20:28:24 +00:00
|
|
|
apk = files[-1]
|
|
|
|
installs.append(apk)
|
|
|
|
|
|
|
|
if not args.autoyes:
|
|
|
|
for apk in installs:
|
|
|
|
print(apk.absolute_path)
|
|
|
|
if not interactive.getpermission('Is that okay?', must_pick=True):
|
|
|
|
return 1
|
|
|
|
|
|
|
|
for apk in installs:
|
|
|
|
command = f'adb install "{apk.absolute_path}"'
|
|
|
|
log.info(command)
|
|
|
|
os.system(command)
|
|
|
|
|
2021-09-24 06:42:34 +00:00
|
|
|
return 0
|
|
|
|
|
2021-06-22 05:11:19 +00:00
|
|
|
@vlogging.main_decorator
|
2021-03-26 20:28:24 +00:00
|
|
|
def main(argv):
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
|
|
|
|
|
|
parser.add_argument('apks', nargs='+')
|
|
|
|
parser.add_argument('--yes', dest='autoyes', action='store_true')
|
|
|
|
parser.set_defaults(func=adbinstall_argparse)
|
|
|
|
|
|
|
|
args = parser.parse_args(argv)
|
|
|
|
return args.func(args)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
raise SystemExit(main(sys.argv[1:]))
|