PEP8 improvements and python3 compatibility.

Emin Mastizada 6 years ago committed by Sebastian Kaspari
parent eb5010f68d
commit 5596105d4f

@ -7,6 +7,7 @@ import base64
import os
import taskcluster
def write_secret_to_file(path, data, key, base64decode=False):
path = os.path.join(os.path.dirname(__file__), '../../' + path)
with open(path, 'w') as f:
@ -15,6 +16,7 @@ def write_secret_to_file(path, data, key, base64decode=False):
value = base64.b64decode(value)
f.write(value)
def fetch_secret_from_taskcluster(name):
secrets = taskcluster.Secrets({'baseUrl': 'http://taskcluster/secrets/v1'})
return secrets.get(name)
@ -27,7 +29,10 @@ def main():
parser.add_argument('-s', dest="secret", action="store", help="name of the secret")
parser.add_argument('-k', dest='key', action="store", help='key of the secret')
parser.add_argument('-f', dest="path", action="store", help='file to save secret to')
parser.add_argument('--decode', dest="decode", action="store_true", default=False, help='base64 decode secret before saving to file')
parser.add_argument(
'--decode', dest="decode", action="store_true", default=False,
help='base64 decode secret before saving to file'
)
result = parser.parse_args()

@ -4,10 +4,10 @@
import argparse
import fnmatch
import glob
import os
import subprocess
def collect_apks(path, pattern):
matches = []
for root, dirnames, filenames in os.walk(path):
@ -15,56 +15,64 @@ def collect_apks(path, pattern):
matches.append(os.path.join(root, filename))
return matches
def zipalign(path):
unsigned_apks = collect_apks(path, '*-unsigned.apk')
print "Found %d APK(s) to zipalign in %s" % (len(unsigned_apks), path)
print("Found {apk_count} APK(s) to zipalign in {path}".format(apk_count=len(unsigned_apks), path=path))
for apk in unsigned_apks:
print "Zipaligning", apk
print("Zipaligning", apk)
split = os.path.splitext(apk)
print subprocess.check_output(["zipalign", "-f", "-v", "-p", "4", apk, split[0] + "-aligned" + split[1]])
print(subprocess.check_output(["zipalign", "-f", "-v", "-p", "4", apk, split[0] + "-aligned" + split[1]]))
def sign(path, store, store_token, key_alias, key_token):
unsigned_apks = collect_apks(path, '*-aligned.apk')
print "Found %d APK(s) to sign in %s" % (len(unsigned_apks), path)
print("Found {apk_count} APK(s) to sign in {path}".format(apk_count=len(unsigned_apks), path=path))
for apk in unsigned_apks:
print "Signing", apk
print subprocess.check_output([
print("Signing", apk)
print(subprocess.check_output([
"apksigner", "sign",
"--ks", store,
"--ks-key-alias", key_alias,
"--ks-pass", "file:%s" % store_token,
"--key-pass", "file:%s" % key_token,
"-v",
"--out", apk.replace('unsigned', 'signed'), apk])
"--out", apk.replace('unsigned', 'signed'), apk]))
def archive(path, archive):
def archive_result(path, archive):
if not os.path.exists(archive):
os.makedirs(archive)
signed_apks = collect_apks(path, '*-signed-*.apk')
print "Found %d APK(s) to archive in %s" % (len(signed_apks), path)
print("Found {apk_count} APK(s) to archive in {path}".format(apk_count=len(signed_apks), path=path))
for apk in signed_apks:
print "Verifying", apk
print subprocess.check_output(['apksigner', 'verify', apk])
print("Verifying", apk)
print(subprocess.check_output(['apksigner', 'verify', apk]))
destination = archive + "/" + os.path.basename(apk)
print "Archiving", apk
print " `->", destination
print("Archiving", apk)
print(" `->", destination)
os.rename(apk, destination)
def main():
parser = argparse.ArgumentParser(
description='Zipaligns, signs and archives APKs')
parser.add_argument('--path', dest="path", action="store", help='Root path to search for APK files')
parser.add_argument('--zipalign', dest="zipalign", action="store_true", default=False, help='Zipaligns APKs before signing')
parser.add_argument('--archive', metavar="PATH", dest="archive", action="store", default=False, help='Path to save sign APKs to')
parser.add_argument('--zipalign', dest="zipalign", action="store_true", default=False,
help='Zipaligns APKs before signing')
parser.add_argument('--archive', metavar="PATH", dest="archive", action="store", default=False,
help='Path to save sign APKs to')
parser.add_argument('--store', metavar="PATH", dest="store", action="store", help='Path to keystore')
parser.add_argument('--store-token', metavar="PATH", dest="store_token", action="store", help='Path to keystore password file')
parser.add_argument('--store-token', metavar="PATH", dest="store_token", action="store",
help='Path to keystore password file')
parser.add_argument('--key-alias', metavar="ALIAS", dest="key_alias", action="store", help='Key alias')
parser.add_argument('--key-token', metavar="PATH", dest="key_token", action="store", help='Path to key password file')
parser.add_argument('--key-token', metavar="PATH", dest="key_token", action="store",
help='Path to key password file')
result = parser.parse_args()
@ -74,7 +82,7 @@ def main():
sign(result.path, result.store, result.store_token, result.key_alias, result.key_token)
if result.archive:
archive(result.path, result.archive)
archive_result(result.path, result.archive)
if __name__ == "__main__":

Loading…
Cancel
Save