mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-13 14:32:28 +03:00
Add -I/--icons to update
This commit is contained in:
parent
a1c2dc1a75
commit
9f246b04cc
2 changed files with 36 additions and 18 deletions
|
@ -82,9 +82,9 @@ __complete_build() {
|
||||||
}
|
}
|
||||||
|
|
||||||
__complete_update() {
|
__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
|
lopts="--help --createmeta --verbose --quiet --buildreport --interactive
|
||||||
--editor --wiki --pretty --clean"
|
--icons --editor --wiki --pretty --clean"
|
||||||
case "${prev}" in
|
case "${prev}" in
|
||||||
-e|--editor)
|
-e|--editor)
|
||||||
_filedir
|
_filedir
|
||||||
|
|
|
@ -214,6 +214,25 @@ def delete_disabled_builds(apps, apkcache, repodirs):
|
||||||
if apkfilename in apkcache:
|
if apkfilename in apkcache:
|
||||||
del apkcache[apkfilename]
|
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):
|
def scan_apks(apps, apkcache, repodir, knownapks):
|
||||||
"""Scan the apks in the given repo directory.
|
"""Scan the apks in the given repo directory.
|
||||||
|
@ -349,23 +368,16 @@ def scan_apks(apps, apkcache, repodir, knownapks):
|
||||||
apk = zipfile.ZipFile(apkfile, 'r')
|
apk = zipfile.ZipFile(apkfile, 'r')
|
||||||
thisinfo['icon'] = (thisinfo['id'] + '.' +
|
thisinfo['icon'] = (thisinfo['id'] + '.' +
|
||||||
str(thisinfo['versioncode']) + '.png')
|
str(thisinfo['versioncode']) + '.png')
|
||||||
iconfilename = os.path.join(icon_dir, thisinfo['icon'])
|
iconpath = os.path.join(icon_dir, thisinfo['icon'])
|
||||||
try:
|
try:
|
||||||
iconfile = open(iconfilename, 'wb')
|
iconfile = open(iconpath, 'wb')
|
||||||
iconfile.write(apk.read(thisinfo['iconsrc']))
|
iconfile.write(apk.read(thisinfo['iconsrc']))
|
||||||
iconfile.close()
|
iconfile.close()
|
||||||
except:
|
except:
|
||||||
print "WARNING: Error retrieving icon file"
|
print "WARNING: Error retrieving icon file"
|
||||||
apk.close()
|
apk.close()
|
||||||
|
|
||||||
im = Image.open(iconfilename)
|
resize_icon(iconpath)
|
||||||
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
|
|
||||||
|
|
||||||
# Record in known apks, getting the added date at the same time..
|
# Record in known apks, getting the added date at the same time..
|
||||||
added = knownapks.recordapk(thisinfo['apkname'], thisinfo['id'])
|
added = knownapks.recordapk(thisinfo['apkname'], thisinfo['id'])
|
||||||
|
@ -645,6 +657,8 @@ def main():
|
||||||
help="Report on build data status")
|
help="Report on build data status")
|
||||||
parser.add_option("-i", "--interactive", default=False, action="store_true",
|
parser.add_option("-i", "--interactive", default=False, action="store_true",
|
||||||
help="Interactively ask about things that need updating.")
|
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",
|
parser.add_option("-e", "--editor", default="/etc/alternatives/editor",
|
||||||
help="Specify editor to use in interactive mode. Default "+
|
help="Specify editor to use in interactive mode. Default "+
|
||||||
"is /etc/alternatives/editor")
|
"is /etc/alternatives/editor")
|
||||||
|
@ -656,6 +670,16 @@ def main():
|
||||||
help="Clean update - don't uses caches, reprocess all apks")
|
help="Clean update - don't uses caches, reprocess all apks")
|
||||||
(options, args) = parser.parse_args()
|
(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...
|
# Get all apps...
|
||||||
apps = common.read_metadata(verbose=options.verbose)
|
apps = common.read_metadata(verbose=options.verbose)
|
||||||
|
|
||||||
|
@ -680,12 +704,6 @@ def main():
|
||||||
apkcache = {}
|
apkcache = {}
|
||||||
cachechanged = False
|
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)
|
delete_disabled_builds(apps, apkcache, repodirs)
|
||||||
|
|
||||||
apks, cc = scan_apks(apps, apkcache, repodirs[0], knownapks)
|
apks, cc = scan_apks(apps, apkcache, repodirs[0], knownapks)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue