-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
+#!/usr/bin/env python3
#
-# publish.py - part of the FDroid server tools
-# Copyright (C) 2010-13, Ciaran Gultnieks, ciaran@ciarang.com
+# 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
import sys
import os
-import shutil
-import subprocess
import glob
-from optparse import OptionParser
+from argparse import ArgumentParser
+import logging
+
+import common
+import net
+from common import FDroidException
+
+options = None
+config = None
-from common import BuildException
def main():
- #Read configuration...
- execfile('config.py', globals())
+ 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")
- parser.add_option("-p", "--package", default=None,
- help="Verify only the specified package")
- (options, args) = parser.parse_args()
+ parser = ArgumentParser(usage="%(prog)s [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]")
+ common.setup_global_opts(parser)
+ parser.add_argument("appid", nargs='*', help="app-id with optional versioncode in the form APPID[:VERCODE]")
+ options = parser.parse_args()
+
+ config = common.read_config(options)
tmp_dir = 'tmp'
if not os.path.isdir(tmp_dir):
- print "Creating temporary directory"
+ logging.info("Creating temporary directory")
os.makedirs(tmp_dir)
unsigned_dir = 'unsigned'
if not os.path.isdir(unsigned_dir):
- print "No unsigned directory - nothing to do"
+ logging.error("No unsigned directory - nothing to do")
sys.exit(0)
+ verified = 0
+ notverified = 0
+
+ vercodes = common.read_pkg_args(options.appid, True)
+
for apkfile in sorted(glob.glob(os.path.join(unsigned_dir, '*.apk'))):
apkfilename = os.path.basename(apkfile)
- i = apkfilename.rfind('_')
- if i == -1:
- raise BuildException("Invalid apk name")
- appid = apkfilename[:i]
- print "Processing " + apkfilename
+ appid, vercode = common.apknameinfo(apkfile)
+
+ if vercodes and appid not in vercodes:
+ continue
+ if vercodes[appid] and vercode not in vercodes[appid]:
+ continue
+
+ try:
- if not options.package or options.package == appid:
+ logging.info("Processing " + apkfilename)
remoteapk = os.path.join(tmp_dir, apkfilename)
if os.path.exists(remoteapk):
os.remove(remoteapk)
- if subprocess.call(['wget',
- 'https://f-droid.org/repo/' + apkfilename],
- cwd=tmp_dir) != 0:
- print "Failed to get " + apkfilename
- sys.exit(1)
-
- thisdir = os.path.join(tmp_dir, 'this_apk')
- thatdir = os.path.join(tmp_dir, 'that_apk')
- for d in [thisdir, thatdir]:
- if os.path.exists(d):
- shutil.rmtree(d)
- os.mkdir(d)
-
- if subprocess.call(['jar', 'xf',
- os.path.join("..", unsigned_dir, apkfilename)],
- cwd=thisdir) != 0:
- print "Failed to unpack local build of " + apkfilename
- sys.exit(1)
- if subprocess.call(['jar', 'xf', os.path.join("..", remoteapk)],
- cwd=thisdir) != 0:
- print "Failed to unpack remote build of " + apkfilename
- sys.exit(1)
-
- p = subprocess.Popen(['diff', '-r', 'this_apk', 'that_apk'],
- cwd=tmp_dir, stdout=subprocess.PIPE)
- out = p.communicate()[0]
- lines = out.splitlines()
- if len(lines) != 1 or lines[0].find('META-INF') == -1:
- print "Unexpected diff output"
- print out
- sys.exit(1)
-
- print "...successfully verified"
+ url = 'https://f-droid.org/repo/' + apkfilename
+ logging.info("...retrieving " + url)
+ net.download_file(url, dldir=tmp_dir)
-if __name__ == "__main__":
- main()
+ compare_result = common.compare_apks(
+ os.path.join(unsigned_dir, apkfilename),
+ remoteapk,
+ tmp_dir)
+ if compare_result:
+ raise FDroidException(compare_result)
+
+ logging.info("...successfully verified")
+ verified += 1
+ except FDroidException as e:
+ logging.info("...NOT verified - {0}".format(e))
+ notverified += 1
+ logging.info("Finished")
+ logging.info("{0} successfully verified".format(verified))
+ logging.info("{0} NOT verified".format(notverified))
+
+if __name__ == "__main__":
+ main()