chiark / gitweb /
Add 'fdroid install', more rewriting
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 11 Dec 2013 17:35:58 +0000 (18:35 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Thu, 19 Dec 2013 16:05:40 +0000 (17:05 +0100)
completion/bash-completion
fdroid
fdroidserver/common.py
fdroidserver/install.py [new file with mode: 0644]

index b05ee2a2ee3e568a2f01980d020ffe1d5571bbf5..d4e54e3bb35af5dd4ee44bc345e2ab36083573b2 100644 (file)
@@ -45,6 +45,16 @@ __signed_package() {
        COMPREPLY=( $( compgen -W "$files" -- $cur ) )
 }
 
+__signed_vercode() {
+       local p
+       p=${cur:0:-1}
+
+       files=( repo/${p}_*.apk )
+       files=( ${files[@]#*_} )
+       files=${files[@]%.apk}
+       COMPREPLY=( $( compgen -P "${p}:" -W "$files" -- $cur ) )
+}
+
 __vercode() {
        local p
        p=${cur:0:-1}
@@ -88,6 +98,22 @@ __complete_build() {
        __complete_options
 }
 
+__complete_install() {
+       opts="-h -v"
+       lopts="--help --verbose --all"
+       case "${cur}" in
+               -*)
+                       __complete_options
+                       return 0;;
+               *:)
+                       __signed_vercode
+                       return 0;;
+               *)
+                       __signed_package
+                       return 0;;
+       esac
+}
+
 __complete_update() {
        opts="-h -c -v -q -b -i -I -e -w"
        lopts="--help --createmeta --verbose --quiet --buildreport --interactive
@@ -188,7 +214,8 @@ __complete_init() {
 _fdroid() {
        local cmd cmds aliased
        cmd=${COMP_WORDS[1]}
-       cmds=" build init update publish checkupdates import rewritemeta scanner verify stats server "
+       cmds=" build init install update publish checkupdates import
+ rewritemeta scanner verify stats server "
        aliased=false
 
        for c in $cmds; do eval "_fdroid_${c} () {
@@ -201,24 +228,6 @@ _fdroid() {
        }
 }
 
-_fdroid_build_project() {
-       local cur prev cmds opts lopts aliased
-       __fdroid_init
-       aliased=true
-       (( $COMP_CWORD == 1 )) && prev="-p"
-
-       __complete_build
-}
-
-_fdroid_checkupdates_project() {
-       local cur prev cmds opts lopts aliased
-       __fdroid_init
-       aliased=true
-       (( $COMP_CWORD == 1 )) && prev="-p"
-
-       __complete_checkupdates
-}
-
 _fd-commit() {
        __package
 }
diff --git a/fdroid b/fdroid
index 5846b91eb4ce75d22d2fbf0efee448bca6874868..e7b54d91d22d0caaa4d12ba566c1863662970de0 100755 (executable)
--- a/fdroid
+++ b/fdroid
@@ -22,6 +22,7 @@ import sys
 commands = [
         "build",
         "init",
+        "install",
         "update",
         "publish",
         "verify",
index fc23074901de98598419c93e6f258c071c11466b..14cdcec08182a9e36647387247ea72c21a58303c 100644 (file)
@@ -132,7 +132,12 @@ def read_app_args(args, options, allapps):
                     print "No such package: %s" % p
             raise Exception("Found invalid app ids in arguments")
 
-    apps = [app for app in apps if (options.force or not app['Disabled']) and
+    if hasattr(options, "force"):
+        force = options.force
+    else:
+        force = False
+
+    apps = [app for app in apps if (force or not app['Disabled']) and
             app['builds'] and len(app['Repo Type']) > 0 and len(app['builds']) > 0]
     if len(apps) == 0:
         raise Exception("No apps to process.")
diff --git a/fdroidserver/install.py b/fdroidserver/install.py
new file mode 100644 (file)
index 0000000..bef95e3
--- /dev/null
@@ -0,0 +1,87 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+#
+# verify.py - part of the FDroid server tools
+# Copyright (C) 2013, Ciaran Gultnieks, ciaran@ciarang.com
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import sys
+import os
+from optparse import OptionParser
+
+import common
+from common import FDroidPopen
+import metadata
+
+options = None
+config = None
+
+def devices():
+    p = FDroidPopen(["adb", "devices"])
+    if p.returncode != 0:
+        raise Exception("An error occured when finding devices: %s" % p.stderr)
+    devs = []
+    return [l.split()[0] for l in p.stdout.splitlines()[1:-1]]
+
+
+def main():
+
+    global options, config
+
+    # Parse command line...
+    parser = OptionParser()
+    parser.add_option("-v", "--verbose", action="store_true", default=False,
+                      help="Spew out even more information than normal")
+    (options, args) = parser.parse_args()
+
+    config = common.read_config(options)
+
+    output_dir = 'repo'
+    if not os.path.isdir(output_dir):
+        print "No signed output directory - nothing to do"
+        sys.exit(1)
+
+    # Get all apps...
+    allapps = metadata.read_metadata()
+
+    apps = common.read_app_args(args, options, allapps)
+
+    for app in apps:
+        for thisbuild in app['builds']:
+            apk = os.path.join(output_dir, common.getapkname(app, thisbuild))
+            if not os.path.exists(apk):
+                raise Exception("No such signed apk: %s" % apk)
+                continue
+            # Get device list each time to avoid device not found errors
+            devs = devices()
+            if not devs:
+                raise Exception("No attached devices found")
+            print "Installing %s..." % apk
+            for dev in devs:
+                print "Installing %s on %s..." % (apk, dev)
+                p = FDroidPopen(["adb", "-s", dev, "install", apk ])
+                fail= ""
+                for line in p.stdout.splitlines():
+                    if line.startswith("Failure"):
+                        fail = line[9:-1]
+                if fail:
+                    raise Exception("Failed to install %s on %s: %s" % (
+                        apk, dev, fail))
+
+    print "\nFinished"
+
+if __name__ == "__main__":
+    main()
+