chiark / gitweb /
update: app store metadata from Triple-T gradle play publisher
authorHans-Christoph Steiner <hans@eds.org>
Thu, 13 Apr 2017 16:42:30 +0000 (18:42 +0200)
committerHans-Christoph Steiner <hans@eds.org>
Wed, 19 Apr 2017 08:05:24 +0000 (10:05 +0200)
Since f-droid.org has the source repos, `fdroid update` can just grab files
from the source repo.  This makes `fdroid update` use the metadata that is
laid out in the Triple-T gradle play publisher filesystem layout:

https://github.com/Triple-T/gradle-play-publisher#upload-images
https://github.com/Triple-T/gradle-play-publisher#play-store-metadata

closes #143

fdroidserver/update.py

index 4dc000c269a83c23ecb16f85bd791438976af7d3..d08df297681ec908368bb2ed8d891f63284ecd88 100644 (file)
@@ -66,6 +66,11 @@ all_screen_densities = ['0'] + screen_densities
 UsesPermission = collections.namedtuple('UsesPermission', ['name', 'maxSdkVersion'])
 UsesPermissionSdk23 = collections.namedtuple('UsesPermissionSdk23', ['name', 'maxSdkVersion'])
 
+ALLOWED_EXTENSIONS = ('png', 'jpg', 'jpeg')
+GRAPHIC_NAMES = ('featureGraphic', 'icon', 'promoGraphic', 'tvBanner')
+SCREENSHOT_DIRS = ('phoneScreenshots', 'sevenInchScreenshots',
+                   'tenInchScreenshots', 'tvScreenshots', 'wearScreenshots')
+
 
 def dpi_to_px(density):
     return (int(density) * 48) / 160
@@ -551,6 +556,85 @@ def insert_obbs(repodir, apps, apks):
                 break
 
 
+def _get_localized_dict(app, locale):
+    '''get the dict to add localized store metadata to'''
+    if 'localized' not in app:
+        app['localized'] = collections.OrderedDict()
+    if locale not in app['localized']:
+        app['localized'][locale] = collections.OrderedDict()
+    return app['localized'][locale]
+
+
+def _set_localized_text_entry(app, locale, key, f):
+    limit = config['char_limits'][key]
+    localized = _get_localized_dict(app, locale)
+    with open(f) as fp:
+        text = fp.read()[:limit]
+        if len(text) > 0:
+            localized[key] = text
+
+
+def copy_triple_t_store_metadata(apps):
+    """Include store metadata from the app's source repo
+
+    The Triple-T Gradle Play Publisher is a plugin that has a standard
+    file layout for all of the metadata and graphics that the Google
+    Play Store accepts.  Since F-Droid has the git repo, it can just
+    pluck those files directly.  This method reads any text files into
+    the app dict, then copies any graphics into the fdroid repo
+    directory structure.
+
+    This needs to be run before insert_localized_app_metadata() so that
+    the graphics files that are copied into the fdroid repo get
+    properly indexed.
+
+    https://github.com/Triple-T/gradle-play-publisher#upload-images
+    https://github.com/Triple-T/gradle-play-publisher#play-store-metadata
+
+    """
+
+    if not os.path.isdir('build'):
+        return  # nothing to do
+
+    for packageName, app in apps.items():
+        for d in glob.glob(os.path.join('build', packageName, '*', 'src', '*', 'play')):
+            logging.debug('Triple-T Gradle Play Publisher: ' + d)
+            for root, dirs, files in os.walk(d):
+                segments = root.split('/')
+                locale = segments[-2]
+                for f in files:
+                    if f == 'fulldescription':
+                        _set_localized_text_entry(app, locale, 'Description',
+                                                  os.path.join(root, f))
+                        continue
+                    elif f == 'shortdescription':
+                        _set_localized_text_entry(app, locale, 'Summary',
+                                                  os.path.join(root, f))
+                        continue
+                    elif f == 'title':
+                        _set_localized_text_entry(app, locale, 'Name',
+                                                  os.path.join(root, f))
+                        continue
+                    elif f == 'video':
+                        _set_localized_text_entry(app, locale, 'Video',
+                                                  os.path.join(root, f))
+                        continue
+
+                    base, extension = common.get_extension(f)
+                    dirname = os.path.basename(root)
+                    if dirname in GRAPHIC_NAMES and extension in ALLOWED_EXTENSIONS:
+                        if segments[-2] == 'listing':
+                            locale = segments[-3]
+                        else:
+                            locale = segments[-2]
+                        destdir = os.path.join('repo', packageName, locale)
+                        os.makedirs(destdir, mode=0o755, exist_ok=True)
+                        sourcefile = os.path.join(root, f)
+                        destfile = os.path.join(destdir, dirname + '.' + extension)
+                        logging.debug('copying ' + sourcefile + ' ' + destfile)
+                        shutil.copy(sourcefile, destfile)
+
+
 def insert_localized_app_metadata(apps):
     """scans standard locations for graphics and localized text
 
@@ -575,24 +659,9 @@ def insert_localized_app_metadata(apps):
     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',
-                      'tenInchScreenshots', 'tvScreenshots', 'wearScreenshots')
-
     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
@@ -605,35 +674,33 @@ def insert_localized_app_metadata(apps):
             locale = segments[-1]
             destdir = os.path.join('repo', packageName, locale)
             for f in files:
-                key = None
                 if f == 'full_description.txt':
-                    key = 'Description'
+                    _set_localized_text_entry(apps[packageName], locale, 'Description',
+                                              os.path.join(root, f))
+                    continue
                 elif f == 'short_description.txt':
-                    key = 'Summary'
+                    _set_localized_text_entry(apps[packageName], locale, 'Summary',
+                                              os.path.join(root, f))
+                    continue
                 elif f == 'title.txt':
-                    key = 'Name'
+                    _set_localized_text_entry(apps[packageName], locale, 'Name',
+                                              os.path.join(root, f))
+                    continue
                 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
+                    _set_localized_text_entry(apps[packageName], locale, 'Video',
+                                              os.path.join(root, f))
                     continue
 
                 base, extension = common.get_extension(f)
-                if base in graphicnames and extension in allowed_extensions:
+                if base in GRAPHIC_NAMES and extension in ALLOWED_EXTENSIONS:
                     os.makedirs(destdir, mode=0o755, exist_ok=True)
                     logging.debug('copying ' + os.path.join(root, f) + ' ' + destdir)
                     shutil.copy(os.path.join(root, f), destdir)
             for d in dirs:
-                if d in screenshotdirs:
+                if d in SCREENSHOT_DIRS:
                     for f in glob.glob(os.path.join(root, d, '*.*')):
                         _, extension = common.get_extension(f)
-                        if extension in allowed_extensions:
+                        if extension in ALLOWED_EXTENSIONS:
                             screenshotdestdir = os.path.join(destdir, d)
                             os.makedirs(screenshotdestdir, mode=0o755, exist_ok=True)
                             logging.debug('copying ' + f + ' ' + screenshotdestdir)
@@ -657,14 +724,14 @@ def insert_localized_app_metadata(apps):
                 logging.warning('Found "%s" graphic without metadata for app "%s"!'
                                 % (filename, packageName))
                 continue
-            graphics = get_localized_dict(apps, packageName, locale)
+            graphics = _get_localized_dict(apps[packageName], locale)
 
-            if extension not in allowed_extensions:
+            if extension not in ALLOWED_EXTENSIONS:
                 logging.warning('Only PNG and JPEG are supported for graphics, found: ' + f)
-            elif base in graphicnames:
+            elif base in GRAPHIC_NAMES:
                 # there can only be zero or one of these per locale
                 graphics[base] = filename
-            elif screenshotdir in screenshotdirs:
+            elif screenshotdir in SCREENSHOT_DIRS:
                 # there can any number of these per locale
                 logging.debug('adding ' + base + ':' + f)
                 if screenshotdir not in graphics:
@@ -1394,6 +1461,7 @@ def main():
     if newmetadata:
         apps = metadata.read_metadata()
 
+    copy_triple_t_store_metadata(apps)
     insert_obbs(repodirs[0], apps, apks)
     insert_localized_app_metadata(apps)