2 # -*- coding: utf-8 -*-
4 # verify.py - part of the FDroid server tools
5 # Copyright (C) 2013, Ciaran Gultnieks, ciaran@ciarang.com
6 # Copyright (C) 2013 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 optparse import OptionParser, OptionError
27 from common import FDroidPopen
33 p = FDroidPopen(["adb", "devices"])
35 raise Exception("An error occured when finding devices: %s" % p.stdout)
36 lines = p.stdout.splitlines()
37 if lines[0].startswith('* daemon not running'):
42 return [l.split()[0] for l in lines]
47 global options, config
49 # Parse command line...
50 parser = OptionParser(usage="Usage: %prog [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]")
51 parser.add_option("-v", "--verbose", action="store_true", default=False,
52 help="Spew out even more information than normal")
53 parser.add_option("-a", "--all", action="store_true", default=False,
54 help="Install all signed applications available")
55 (options, args) = parser.parse_args()
57 if not args and not options.all:
58 raise OptionError("If you really want to install all the signed apps, use --all", "all")
60 config = common.read_config(options)
63 if not os.path.isdir(output_dir):
64 print "No signed output directory - nothing to do"
69 vercodes = common.read_pkg_args(args, True)
70 apks = { appid : None for appid in vercodes }
72 # Get the signed apk with the highest vercode
73 for apkfile in sorted(glob.glob(os.path.join(output_dir, '*.apk'))):
75 appid, vercode = common.apknameinfo(apkfile)
78 if vercodes[appid] and vercode not in vercodes[appid]:
82 for appid, apk in apks.iteritems():
84 raise Exception("No signed apk available for %s" % appid)
88 apks = { common.apknameinfo(apkfile)[0] : apkfile for apkfile in
89 sorted(glob.glob(os.path.join(output_dir, '*.apk'))) }
91 for appid, apk in apks.iteritems():
92 # Get device list each time to avoid device not found errors
95 raise Exception("No attached devices found")
96 print "Installing %s..." % apk
98 print "Installing %s on %s..." % (apk, dev)
99 p = FDroidPopen(["adb", "-s", dev, "install", apk ])
101 for line in p.stdout.splitlines():
102 if line.startswith("Failure"):
105 if fail == "INSTALL_FAILED_ALREADY_EXISTS":
106 print "%s is already installed on %s." % (apk, dev)
108 raise Exception("Failed to install %s on %s: %s" % (
113 if __name__ == "__main__":