chiark / gitweb /
Add 'fdroid install', more rewriting
[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         for thisbuild in app['builds']:
63             apk = os.path.join(output_dir, common.getapkname(app, thisbuild))
64             if not os.path.exists(apk):
65                 raise Exception("No such signed apk: %s" % apk)
66                 continue
67             # Get device list each time to avoid device not found errors
68             devs = devices()
69             if not devs:
70                 raise Exception("No attached devices found")
71             print "Installing %s..." % apk
72             for dev in devs:
73                 print "Installing %s on %s..." % (apk, dev)
74                 p = FDroidPopen(["adb", "-s", dev, "install", apk ])
75                 fail= ""
76                 for line in p.stdout.splitlines():
77                     if line.startswith("Failure"):
78                         fail = line[9:-1]
79                 if fail:
80                     raise Exception("Failed to install %s on %s: %s" % (
81                         apk, dev, fail))
82
83     print "\nFinished"
84
85 if __name__ == "__main__":
86     main()
87