1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-10-03 17:50:11 +02:00

Add -I/--icons to update

This commit is contained in:
Daniel Martí 2013-08-19 11:30:54 +02:00
parent a1c2dc1a75
commit 9f246b04cc
2 changed files with 36 additions and 18 deletions

View File

@ -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

View File

@ -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)