-#!/usr/bin/env python2
-# -*- coding: utf-8 -*-
+#!/usr/bin/env python3
#
# verify.py - part of the FDroid server tools
# Copyright (C) 2013, Ciaran Gultnieks, ciaran@ciarang.com
import sys
import os
-import shutil
-import subprocess
import glob
-from optparse import OptionParser
+from argparse import ArgumentParser
import logging
import common
-from common import FDroidPopen
+import net
+from common import FDroidException
options = None
config = None
global options, config
# Parse command line...
- parser = OptionParser(usage="Usage: %prog [options] [APPID[:VERCODE] [APPID[:VERCODE] ...]]")
- parser.add_option("-v", "--verbose", action="store_true", default=False,
- help="Spew out even more information than normal")
- parser.add_option("-q", "--quiet", action="store_true", default=False,
- help="Restrict output to warnings and errors")
- (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)
verified = 0
notverified = 0
- vercodes = common.read_pkg_args(args, True)
+ vercodes = common.read_pkg_args(options.appid, True)
for apkfile in sorted(glob.glob(os.path.join(unsigned_dir, '*.apk'))):
os.remove(remoteapk)
url = 'https://f-droid.org/repo/' + apkfilename
logging.info("...retrieving " + url)
- p = FDroidPopen(['wget', url], cwd=tmp_dir)
- if p.returncode != 0:
- raise Exception("Failed to get " + apkfilename)
-
- 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:
- raise Exception("Failed to unpack local build of " + apkfilename)
- if subprocess.call(['jar', 'xf',
- os.path.join("..", "..", remoteapk)],
- cwd=thatdir) != 0:
- raise Exception("Failed to unpack remote build of " + apkfilename)
-
- p = FDroidPopen(['diff', '-r', 'this_apk', 'that_apk'], cwd=tmp_dir)
- lines = p.stdout.splitlines()
- if len(lines) != 1 or 'META-INF' not in lines[0]:
- raise Exception("Unexpected diff output - " + p.stdout)
+ net.download_file(url, dldir=tmp_dir)
+
+ 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 Exception, e:
+ except FDroidException as e:
logging.info("...NOT verified - {0}".format(e))
notverified += 1