From 9f246b04cc41b7fcbe98d0ba667ede5b04c84f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 19 Aug 2013 11:30:54 +0200 Subject: [PATCH] Add -I/--icons to update --- completion/bash-completion | 4 +-- fdroidserver/update.py | 50 ++++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/completion/bash-completion b/completion/bash-completion index 748a7fa8..ce60c97e 100644 --- a/completion/bash-completion +++ b/completion/bash-completion @@ -82,9 +82,9 @@ __complete_build() { } __complete_update() { - opts="-h -c -v -q -b -i -e -w" + opts="-h -c -v -q -b -i -I -e -w" lopts="--help --createmeta --verbose --quiet --buildreport --interactive - --editor --wiki --pretty --clean" + --icons --editor --wiki --pretty --clean" case "${prev}" in -e|--editor) _filedir diff --git a/fdroidserver/update.py b/fdroidserver/update.py index bd630657..8e43071e 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -214,6 +214,25 @@ def delete_disabled_builds(apps, apkcache, repodirs): if apkfilename in apkcache: del apkcache[apkfilename] +def resize_icon(iconpath): + im = Image.open(iconpath) + if any(length > 72 for length in im.size): + print iconpath, "is too large:", im.size + im.thumbnail((72, 72), Image.ANTIALIAS) + print iconpath, "new size:", im.size + im.save(iconpath, "PNG") + else: + print iconpath, "is small enough:", im.size + +def resize_all_icons(repodirs): + """Resize all icons to max size 72x72 pixels + + :param apps: list of all applications, as per common.read_metadata + :param repodirs: the repo directories to process + """ + for repodir in repodirs: + for iconpath in glob.glob(os.path.join(repodir, 'icons', '*.png')): + resize_icon(iconpath) def scan_apks(apps, apkcache, repodir, knownapks): """Scan the apks in the given repo directory. @@ -349,23 +368,16 @@ def scan_apks(apps, apkcache, repodir, knownapks): apk = zipfile.ZipFile(apkfile, 'r') thisinfo['icon'] = (thisinfo['id'] + '.' + str(thisinfo['versioncode']) + '.png') - iconfilename = os.path.join(icon_dir, thisinfo['icon']) + iconpath = os.path.join(icon_dir, thisinfo['icon']) try: - iconfile = open(iconfilename, 'wb') + iconfile = open(iconpath, 'wb') iconfile.write(apk.read(thisinfo['iconsrc'])) iconfile.close() except: print "WARNING: Error retrieving icon file" apk.close() - im = Image.open(iconfilename) - if any(length > 72 for length in im.size): - print iconfilename, "is too large:", im.size - im.thumbnail((72, 72), Image.ANTIALIAS) - print iconfilename, "new size:", im.size - im.save(iconfilename, "PNG") - else: - print iconfilename, "is small enough:", im.size + resize_icon(iconpath) # Record in known apks, getting the added date at the same time.. added = knownapks.recordapk(thisinfo['apkname'], thisinfo['id']) @@ -645,6 +657,8 @@ def main(): help="Report on build data status") parser.add_option("-i", "--interactive", default=False, action="store_true", help="Interactively ask about things that need updating.") + parser.add_option("-I", "--icons", action="store_true", default=False, + help="Resize all the icons exceeding the max pixel size and exit") parser.add_option("-e", "--editor", default="/etc/alternatives/editor", help="Specify editor to use in interactive mode. Default "+ "is /etc/alternatives/editor") @@ -656,6 +670,16 @@ def main(): help="Clean update - don't uses caches, reprocess all apks") (options, args) = parser.parse_args() + repodirs = ['repo'] + if archive_older != 0: + repodirs.append('archive') + if not os.path.exists('archive'): + os.mkdir('archive') + + if options.icons: + resize_all_icons(repodirs) + sys.exit(0) + # Get all apps... apps = common.read_metadata(verbose=options.verbose) @@ -680,12 +704,6 @@ def main(): apkcache = {} cachechanged = False - repodirs = ['repo'] - if archive_older != 0: - repodirs.append('archive') - if not os.path.exists('archive'): - os.mkdir('archive') - delete_disabled_builds(apps, apkcache, repodirs) apks, cc = scan_apks(apps, apkcache, repodirs[0], knownapks)