diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 26e248d5..7b8bc26a 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -34,6 +34,7 @@ import json import time import yaml import copy +import pathlib import defusedxml.ElementTree as ElementTree from datetime import datetime, timezone from argparse import ArgumentParser @@ -1136,6 +1137,9 @@ def insert_localized_app_metadata(apps): if base not in apps[packageName] or not isinstance(apps[packageName][base], collections.OrderedDict): apps[packageName][base] = collections.OrderedDict() apps[packageName][base][locale] = common.file_entry(dst) + + # copy screenshots from local source code checkout into wellknown + # location in repo directory for d in dirs: if d in SCREENSHOT_DIRS: if locale == 'images': @@ -1148,6 +1152,8 @@ def insert_localized_app_metadata(apps): os.makedirs(screenshotdestdir, mode=0o755, exist_ok=True) _strip_and_copy_image(f, screenshotdestdir) + +def ingest_screenshots_from_repo_dir(apps): repodirs = sorted(glob.glob(os.path.join('repo', '[A-Za-z]*', '[a-z][a-z]*'))) for d in repodirs: if not os.path.isdir(d): @@ -1208,6 +1214,86 @@ def insert_localized_app_metadata(apps): logging.warning(_('Unsupported graphics file found: {path}').format(path=f)) +LANG_CODE = re.compile(r'^[a-z]{2}([-_][A-Z][a-zA-Z]{1,3})?$') + + +FASTLANE_IOS_MAP = { + "name.txt": 'name', + "subtitle.txt": 'summary', + "description.txt": 'description', +} + + +def parse_ios_screenshot_name(path): + """ + Infer type info from screenshot file name. + + Device type/name is part of the file name of iOS fastlane screenshots. + Here are some example: + * 'iPhone 8+ @ iOS 16-1.png' + * 'iPad Pro 12.9" 2gen @ iOS 16-1.png' + * '1_ipadPro129_1.1.png' + * '1_iphone6Plus_1.1.png' + """ + s = path.stem.split('@') + if len(s) >= 2: + if "iphone" in s[0].lower(): + return ("phoneScreenshots", '@'.join(s[1:])) + elif "ipad" in s[0].lower(): + return ("tenInchScreenshots", "@".join(s[1:])) + else: + return ('phoneScreenshots', s[0]) + + +def insert_localized_ios_app_metadata(apps_with_packages): + + if not any(pathlib.Path('repo').glob('*.ipa')): + # no IPA files present in repo, nothing to do here, exiting early + return + + for package_name, app in apps_with_packages.items(): + if not any(pathlib.Path('repo').glob(f'{package_name}*.ipa')): + # couldn't find any IPA files for this package_name + # so we don't have to look for fastlane data + continue + + fastlane_dir = pathlib.Path('build', package_name, 'fastlane') + + for lang_dir in (fastlane_dir / 'metadata').iterdir(): + lang_code = lang_dir.name + m = LANG_CODE.match(lang_code) + if m: + for metadata_file in (lang_dir).iterdir(): + key = FASTLANE_IOS_MAP.get(metadata_file.name) + if key: + _set_localized_text_entry(app, lang_code, key, metadata_file) + + # discover available screenshots and put findings in a dict + screenshots = {} + for lang_sdir in (fastlane_dir / 'screenshots').iterdir(): + lang_code = lang_sdir.name + m = LANG_CODE.match(lang_code) + if m: + screenshots[lang_code] = {} + for screenshot in (lang_sdir).iterdir(): + if screenshot.suffix[1:] in ALLOWED_EXTENSIONS: + # asdf #TODO + device_name, screenshot_name = parse_ios_screenshot_name(screenshot) + + if not screenshots[lang_code].get(device_name): + screenshots[lang_code][device_name] = {} + screenshots[lang_code][device_name][screenshot_name] = screenshot + + # copy screenshots to repo dir + for lang_code in screenshots.keys(): + for device in screenshots[lang_code].keys(): + dest_dir = pathlib.Path('repo') / package_name / lang_code / device + dest_dir.mkdir(mode=0o755, parents=True, exist_ok=True) + for name, path in screenshots[lang_code][device].items(): + dest = dest_dir / (name.replace(" ", "_").replace("\t", "_") + path.suffix) + _strip_and_copy_image(str(path), str(dest)) + + def scan_repo_files(apkcache, repodir, knownapks, use_date_from_file=False): """Scan a repo for all files with an extension except APK/OBB/IPA. @@ -2238,6 +2324,8 @@ def prepare_apps(apps, apks, repodir): translate_per_build_anti_features(apps_with_packages, apks) if repodir == 'repo': insert_localized_app_metadata(apps_with_packages) + insert_localized_ios_app_metadata(apps_with_packages) + ingest_screenshots_from_repo_dir(apps_with_packages) insert_missing_app_names_from_apks(apps_with_packages, apks) return apps_with_packages diff --git a/tests/update.TestCase b/tests/update.TestCase index bebab3f0..37e4be9b 100755 --- a/tests/update.TestCase +++ b/tests/update.TestCase @@ -165,6 +165,7 @@ class UpdateTest(unittest.TestCase): apps['eu.siacs.conversations']['Builds'] = [build_conversations] fdroidserver.update.insert_localized_app_metadata(apps) + fdroidserver.update.ingest_screenshots_from_repo_dir(apps) appdir = os.path.join('repo', 'info.guardianproject.urzip', 'en-US') self.assertTrue( @@ -278,6 +279,7 @@ class UpdateTest(unittest.TestCase): knownapks = fdroidserver.common.KnownApks() apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks, False) fdroidserver.update.insert_localized_app_metadata(apps) + fdroidserver.update.ingest_screenshots_from_repo_dir(apps) fdroidserver.update.apply_info_from_latest_apk(apps, apks) app = apps['info.guardianproject.urzip'] self.assertIsNone(app.Name)