chiark / gitweb /
Only install latest apk of each app, other fixes
[fdroidserver.git] / fdroidserver / install.py
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3 #
4 # verify.py - part of the FDroid server tools
5 # Copyright (C) 2013, Ciaran Gultnieks, ciaran@ciarang.com
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU Affero General Public License for more details.
16 #
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
20 import sys
21 import os
22 from optparse import OptionParser
23
24 import common
25 from common import FDroidPopen
26 import metadata
27
28 options = None
29 config = None
30
31 def devices():
32     p = FDroidPopen(["adb", "devices"])
33     if p.returncode != 0:
34         raise Exception("An error occured when finding devices: %s" % p.stderr)
35     devs = []
36     return [l.split()[0] for l in p.stdout.splitlines()[1:-1]]
37
38
39 def main():
40
41     global options, config
42
43     # Parse command line...
44     parser = OptionParser()
45     parser.add_option("-v", "--verbose", action="store_true", default=False,
46                       help="Spew out even more information than normal")
47     (options, args) = parser.parse_args()
48
49     config = common.read_config(options)
50
51     output_dir = 'repo'
52     if not os.path.isdir(output_dir):
53         print "No signed output directory - nothing to do"
54         sys.exit(1)
55
56     # Get all apps...
57     allapps = metadata.read_metadata()
58
59     apps = common.read_app_args(args, options, allapps)
60
61     for app in apps:
62         last = None
63         for build in app['builds']:
64             apk = os.path.join(output_dir, common.getapkname(app, build))
65             if os.path.exists(apk):
66                 last = build
67         if last is None:
68             raise Exception("No available signed apks for %s" % app['id'])
69
70     for app in apps:
71         build = app['builds'][0]
72         apk = os.path.join(output_dir, common.getapkname(app, build))
73         if not os.path.exists(apk):
74             raise Exception("No such signed apk: %s" % apk)
75             continue
76         # Get device list each time to avoid device not found errors
77         devs = devices()
78         if not devs:
79             raise Exception("No attached devices found")
80         print "Installing %s..." % apk
81         for dev in devs:
82             print "Installing %s on %s..." % (apk, dev)
83             p = FDroidPopen(["adb", "-s", dev, "install", apk ])
84             fail= ""
85             for line in p.stdout.splitlines():
86                 if line.startswith("Failure"):
87                     fail = line[9:-1]
88             if fail:
89                 raise Exception("Failed to install %s on %s: %s" % (
90                     apk, dev, fail))
91
92     print "\nFinished"
93
94 if __name__ == "__main__":
95     main()
96