2 # -*- coding: utf-8 -*-
4 # install.py - part of the FDroid server tools
5 # Copyright (C) 2013, Ciaran Gultnieks, ciaran@ciarang.com
6 # Copyright (C) 2013-2014 Daniel Martà <mvdan@mvdan.cc>
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 from argparse import ArgumentParser
28 from common import SdkToolsPopen, FDroidException
35 p = SdkToolsPopen(['adb', "devices"])
37 raise FDroidException("An error occured when finding devices: %s" % p.output)
38 lines = p.output.splitlines()
39 if lines[0].startswith('* daemon not running'):
44 return [l.split()[0] for l in lines]
49 global options, config
51 # Parse command line...
52 parser = ArgumentParser(usage="%(prog)s [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]")
53 common.setup_global_opts(parser)
54 parser.add_argument("appid", nargs='*', help="app-id with optional versioncode in the form APPID[:VERCODE]")
55 parser.add_argument("-a", "--all", action="store_true", default=False,
56 help="Install all signed applications available")
57 options = parser.parse_args()
59 if not options.appid and not options.all:
60 parser.error("option %s: If you really want to install all the signed apps, use --all" % "all")
62 config = common.read_config(options)
65 if not os.path.isdir(output_dir):
66 logging.info("No signed output directory - nothing to do")
71 vercodes = common.read_pkg_args(options.appid, True)
72 apks = {appid: None for appid in vercodes}
74 # Get the signed apk with the highest vercode
75 for apkfile in sorted(glob.glob(os.path.join(output_dir, '*.apk'))):
78 appid, vercode = common.apknameinfo(apkfile)
79 except FDroidException:
83 if vercodes[appid] and vercode not in vercodes[appid]:
87 for appid, apk in apks.iteritems():
89 raise FDroidException("No signed apk available for %s" % appid)
93 apks = {common.apknameinfo(apkfile)[0]: apkfile for apkfile in
94 sorted(glob.glob(os.path.join(output_dir, '*.apk')))}
96 for appid, apk in apks.iteritems():
97 # Get device list each time to avoid device not found errors
100 raise FDroidException("No attached devices found")
101 logging.info("Installing %s..." % apk)
103 logging.info("Installing %s on %s..." % (apk, dev))
104 p = SdkToolsPopen(['adb', "-s", dev, "install", apk])
106 for line in p.output.splitlines():
107 if line.startswith("Failure"):
112 if fail == "INSTALL_FAILED_ALREADY_EXISTS":
113 logging.warn("%s is already installed on %s." % (apk, dev))
115 raise FDroidException("Failed to install %s on %s: %s" % (
118 logging.info("\nFinished")
120 if __name__ == "__main__":