From: Hans-Christoph Steiner Date: Thu, 13 Apr 2017 11:08:03 +0000 (+0200) Subject: update: include localized app store metadata from fastlane X-Git-Tag: 0.8~74^2~6 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=89c480181c6a83b83c12759ae4b65f56b37b86d8;p=fdroidserver.git update: include localized app store metadata from fastlane This includes all metadata from the app's source repo following the path layout specified for the fastlane supply tool: https://github.com/fastlane/fastlane/blob/1.109.0/supply/README.md#images-and-screenshots refs #35 closes #143 --- diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 271d334c..4dc000c2 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -551,10 +551,13 @@ def insert_obbs(repodir, apps, apks): break -def insert_graphics(repodir, apps): - """Scans for screenshot PNG files in statically defined screenshots - directory and adds them to the app metadata. The screenshots and - graphic must be PNG or JPEG files ending with ".png", ".jpg", or ".jpeg" +def insert_localized_app_metadata(apps): + """scans standard locations for graphics and localized text + + Scans for localized description files, store graphics, and + screenshot PNG files in statically defined screenshots directory + and adds them to the app metadata. The screenshots and graphic + must be PNG or JPEG files ending with ".png", ".jpg", or ".jpeg" and must be in the following layout: repo/packageName/locale/featureGraphic.png @@ -563,17 +566,23 @@ def insert_graphics(repodir, apps): Where "packageName" is the app's packageName and "locale" is the locale of the graphics, e.g. what language they are in, using the IETF RFC5646 - format (en-US, fr-CA, es-MX, etc). This is following this pattern: - https://github.com/fastlane/fastlane/blob/1.109.0/supply/README.md#images-and-screenshots - - This will also scan the metadata/ folder and the apps' source repos - for standard locations of graphic and screenshot files. If it finds - them, it will copy them into the repo. - - :param repodir: repo directory to scan + format (en-US, fr-CA, es-MX, etc). + This will also scan the app's git for a fastlane folder, and the + metadata/ folder and the apps' source repos for standard locations + of graphic and screenshot files. If it finds them, it will copy + them into the repo. The fastlane files follow this pattern: + https://github.com/fastlane/fastlane/blob/1.109.0/supply/README.md#images-and-screenshots """ + def get_localized_dict(apps, packageName, locale): + '''get the dict to add localized store metadata to''' + if 'localized' not in apps[packageName]: + apps[packageName]['localized'] = collections.OrderedDict() + if locale not in apps[packageName]['localized']: + apps[packageName]['localized'][locale] = collections.OrderedDict() + return apps[packageName]['localized'][locale] + allowed_extensions = ('png', 'jpg', 'jpeg') graphicnames = ('featureGraphic', 'icon', 'promoGraphic', 'tvBanner') screenshotdirs = ('phoneScreenshots', 'sevenInchScreenshots', @@ -582,13 +591,39 @@ def insert_graphics(repodir, apps): sourcedirs = glob.glob(os.path.join('build', '[A-Za-z]*', 'fastlane', 'metadata', 'android', '[a-z][a-z][A-Z-.@]*')) sourcedirs += glob.glob(os.path.join('metadata', '[A-Za-z]*', '[a-z][a-z][A-Z-.@]*')) + char_limits = config['char_limits'] + for d in sorted(sourcedirs): if not os.path.isdir(d): continue for root, dirs, files in os.walk(d): segments = root.split('/') - destdir = os.path.join('repo', segments[1], segments[-1]) # repo/packageName/locale + packageName = segments[1] + if packageName not in apps: + logging.debug(packageName + ' does not have app metadata, skipping l18n scan.') + continue + locale = segments[-1] + destdir = os.path.join('repo', packageName, locale) for f in files: + key = None + if f == 'full_description.txt': + key = 'Description' + elif f == 'short_description.txt': + key = 'Summary' + elif f == 'title.txt': + key = 'Name' + elif f == 'video.txt': + key = 'Video' + + if key: + limit = char_limits[key] + localized = get_localized_dict(apps, packageName, locale) + with open(os.path.join(root, f)) as fp: + text = fp.read()[:limit] + if len(text) > 0: + localized[key] = text + continue + base, extension = common.get_extension(f) if base in graphicnames and extension in allowed_extensions: os.makedirs(destdir, mode=0o755, exist_ok=True) @@ -622,11 +657,7 @@ def insert_graphics(repodir, apps): logging.warning('Found "%s" graphic without metadata for app "%s"!' % (filename, packageName)) continue - if 'localized' not in apps[packageName]: - apps[packageName]['localized'] = collections.OrderedDict() - if locale not in apps[packageName]['localized']: - apps[packageName]['localized'][locale] = collections.OrderedDict() - graphics = apps[packageName]['localized'][locale] + graphics = get_localized_dict(apps, packageName, locale) if extension not in allowed_extensions: logging.warning('Only PNG and JPEG are supported for graphics, found: ' + f) @@ -1364,7 +1395,7 @@ def main(): apps = metadata.read_metadata() insert_obbs(repodirs[0], apps, apks) - insert_graphics(repodirs[0], apps) + insert_localized_app_metadata(apps) # Scan the archive repo for apks as well if len(repodirs) > 1: