eliminate app.builds everywhere, it should be app['Builds']

The .txt format was the last place where the lowercase "builds" was used,
this converts references everywhere to be "Builds".  This makes it possible
to load metadata YAML files with any YAML parser, then have it possible to
use fdroidserver methods on that data, like metadata.write_metadata().

The test files in tests/metadata/dump/*.yaml were manually edited by cutting
the builds: block and putting it the sort order for Builds: so the contents
should be unchanged.

```
sed -i \
 -e 's/app\.builds/app.get('Builds', \[\])/g' \
 -e "s/app\.get(Builds, \[\]) =/app\['Builds'] =/g" \
 -e "s/app\.get(Builds, \[\]) =/app\['Builds'] =/g" \
 -e "s/app\.get(Builds, \[\])/app.get('Builds', \[\])/g" \
 -e "s/app\.get('Builds', \[\])\.append/app\['Builds'\].append/g" \
 -e "s/app\['builds'\]/app.get('Builds', [])/g" \
 */*.*
```
This commit is contained in:
Hans-Christoph Steiner 2020-12-09 16:01:21 +01:00
parent 877779195f
commit bf25b4ca03
18 changed files with 275 additions and 279 deletions

View file

@ -1017,7 +1017,7 @@ def main():
apps = common.read_app_args(options.appid, allapps, True)
for appid, app in list(apps.items()):
if (app.Disabled and not options.force) or not app.RepoType or not app.builds:
if (app.get('Disabled') and not options.force) or not app.get('RepoType') or not app.get('Builds', []):
del apps[appid]
if not apps:
@ -1038,10 +1038,10 @@ def main():
if options.latest:
for app in apps.values():
for build in reversed(app.builds):
for build in reversed(app.get('Builds', [])):
if build.disable and not options.force:
continue
app.builds = [build]
app['Builds'] = [build]
break
if options.wiki:
@ -1062,7 +1062,7 @@ def main():
first = True
for build in app.builds:
for build in app.get('Builds', []):
if time.time() > endtime:
max_build_time_reached = True
break

View file

@ -221,8 +221,8 @@ def check_repomanifest(app, branch=None):
vcs.gotorevision(None)
last_build = metadata.Build()
if len(app.builds) > 0:
last_build = app.builds[-1]
if len(app.get('Builds', [])) > 0:
last_build = app.get('Builds', [])[-1]
try_init_submodules(app, last_build, vcs)
@ -506,7 +506,7 @@ def checkupdates_app(app):
gotcur = False
latest = None
for build in app.builds:
for build in app.get('Builds', []):
if int(build.versionCode) >= int(app.CurrentVersionCode):
gotcur = True
if not latest or int(build.versionCode) > int(latest.versionCode):
@ -524,7 +524,7 @@ def checkupdates_app(app):
commit = pattern.replace('%v', app.CurrentVersion)
commit = commit.replace('%c', newbuild.versionCode)
newbuild.commit = commit
app.builds.append(newbuild)
app['Builds'].append(newbuild)
name = _getappname(app)
ver = _getcvname(app)
commitmsg = "Update %s to %s" % (name, ver)

View file

@ -641,10 +641,10 @@ def read_app_args(appid_versionCode_pairs, allapps, allow_vercodes=False):
vc = vercodes[appid]
if not vc:
continue
app.builds = [b for b in app.builds if b.versionCode in vc]
if len(app.builds) != len(vercodes[appid]):
app['Builds'] = [b for b in app.get('Builds', []) if b.versionCode in vc]
if len(app.get('Builds', [])) != len(vercodes[appid]):
error = True
allvcs = [b.versionCode for b in app.builds]
allvcs = [b.versionCode for b in app.get('Builds', [])]
for v in vercodes[appid]:
if v not in allvcs:
logging.critical(_("No such versionCode {versionCode} for app {appid}")
@ -1538,8 +1538,8 @@ def parse_androidmanifests(paths, app):
flavour = None
temp_app_id = None
temp_version_name = None
if app.builds and 'gradle' in app.builds[-1] and app.builds[-1].gradle:
flavour = app.builds[-1].gradle[-1]
if len(app.get('Builds', [])) > 0 and 'gradle' in app['Builds'][-1] and app['Builds'][-1].gradle:
flavour = app['Builds'][-1].gradle[-1]
if path.endswith('.gradle') or path.endswith('.gradle.kts'):
with open(path, 'r') as f:

View file

@ -238,7 +238,7 @@ def main():
metadata.post_metadata_parse(app)
app.builds.append(build)
app['Builds'].append(build)
if write_local_file:
metadata.write_metadata('.fdroid.yml', app)

View file

@ -158,7 +158,7 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
for k, v in sorted(appdict.items()):
if not v:
continue
if k in ('builds', 'comments', 'metadatapath',
if k in ('Builds', 'comments', 'metadatapath',
'ArchivePolicy', 'AutoUpdateMode', 'MaintainerNotes',
'Provides', 'Repo', 'RepoType', 'RequiresRoot',
'UpdateCheckData', 'UpdateCheckIgnore', 'UpdateCheckMode',
@ -201,7 +201,7 @@ def make_v1(apps, packages, repodir, repodict, requestsdict, fdroid_signing_key_
if not package.get('versionName'):
app = apps[packageName]
versionCodeStr = str(package['versionCode']) # TODO build.versionCode should be int!
for build in app['builds']:
for build in app.get('Builds', []):
if build['versionCode'] == versionCodeStr:
versionName = build.get('versionName')
logging.info(_('Overriding blank versionName in {apkfilename} from metadata: {version}')
@ -477,7 +477,7 @@ def make_v0(apps, apks, repodir, repodict, requestsdict, fdroid_signing_key_fing
versionName = apk.get('versionName')
if not versionName:
versionCodeStr = str(apk['versionCode']) # TODO build.versionCode should be int!
for build in app.builds:
for build in app.get('Builds', []):
if build['versionCode'] == versionCodeStr and 'versionName' in build:
versionName = build['versionName']
break

View file

@ -234,7 +234,7 @@ def check_vercode_operation(app):
def check_ucm_tags(app):
lastbuild = get_lastbuild(app.builds)
lastbuild = get_lastbuild(app.get('Builds', []))
if (lastbuild is not None
and lastbuild.commit
and app.UpdateCheckMode == 'RepoManifest'
@ -389,7 +389,7 @@ def check_bulleted_lists(app):
def check_builds(app):
supported_flags = set(metadata.build_flags)
# needed for YAML and JSON
for build in app.builds:
for build in app.get('Builds', []):
if build.disable:
if build.disable.startswith('Generated by import.py'):
yield _("Build generated by `fdroid import` - remove disable line once ready")
@ -424,7 +424,7 @@ def check_files_dir(app):
files.add(name)
used = {'signatures', }
for build in app.builds:
for build in app.get('Builds', []):
for fname in build.patch:
if fname not in files:
yield _("Unknown file '{filename}' in build '{versionName}'")\
@ -466,7 +466,7 @@ def check_extlib_dir(apps):
used = set()
for app in apps:
for build in app.builds:
for build in app.get('Builds', []):
for path in build.extlibs:
if path not in unused_extlib_files:
yield _("{appid}: Unknown extlib {path} in build '{versionName}'")\
@ -494,7 +494,7 @@ def check_app_field_types(app):
t = metadata.fieldtype(field)
if v is None:
continue
elif field == 'builds':
elif field == 'Builds':
if not isinstance(v, list):
yield(_("{appid}: {field} must be a '{type}', but it is a '{fieldtype}'!")
.format(appid=app.id, field=field,
@ -544,7 +544,7 @@ def check_current_version_code(app):
if cv is not None and int(cv) == 0:
return
builds = app.get('builds')
builds = app.get('Builds')
active_builds = 0
min_versionCode = None
if builds:
@ -617,7 +617,7 @@ def main():
# run yamllint on srclib metadata
srclibs = set()
for build in app.builds:
for build in app.get('Builds', []):
for srclib in build.srclibs:
srclibs.add(srclib)
for srclib in srclibs:

View file

@ -158,7 +158,7 @@ class App(dict):
self.id = None
self.metadatapath = None
self.builds = []
self.Builds = []
self.comments = {}
self.added = None
self.lastUpdated = None
@ -179,8 +179,8 @@ class App(dict):
raise AttributeError("No such attribute: " + name)
def get_last_build(self):
if len(self.builds) > 0:
return self.builds[-1]
if len(self.Builds) > 0:
return self.Builds[-1]
else:
return Build()
@ -633,9 +633,6 @@ def post_metadata_parse(app):
if type(v) in (float, int):
app[k] = str(v)
if 'Builds' in app:
app['builds'] = app.pop('Builds')
if 'flavours' in app and app['flavours'] == [True]:
app['flavours'] = 'yes'
@ -664,8 +661,8 @@ def post_metadata_parse(app):
_bool_allowed = ('maven', 'buildozer')
builds = []
if 'builds' in app:
for build in app['builds']:
if 'Builds' in app:
for build in app.get('Builds', []):
if not isinstance(build, Build):
build = Build(build)
for k, v in build.items():
@ -693,7 +690,7 @@ def post_metadata_parse(app):
build[k] = str(v)
builds.append(build)
app.builds = sorted_builds(builds)
app['Builds'] = sorted_builds(builds)
# Parse metadata for a single application.
@ -710,8 +707,6 @@ def post_metadata_parse(app):
#
# Known keys not originating from the metadata are:
#
# 'builds' - a list of dictionaries containing build information
# for each defined build
# 'comments' - a list of comments from the metadata file. Each is
# a list of the form [field, comment] where field is
# the name of the field it preceded in the metadata
@ -771,8 +766,8 @@ def parse_metadata(metadatapath, check_vcs=False, refresh=True):
post_metadata_parse(app)
if not app.id:
if app.builds:
build = app.builds[-1]
if app.get('Builds'):
build = app['Builds'][-1]
if build.subdir:
root_dir = build.subdir
else:
@ -925,9 +920,8 @@ def write_yaml(mf, app):
insert_newline = True
else:
if app.get(field) or field == 'Builds':
# .txt called it 'builds' internally, everywhere else its 'Builds'
if field == 'Builds':
if app.get('builds'):
if app.get('Builds'):
cm.update({field: _builds_to_yaml(app)})
elif field == 'CurrentVersionCode':
cm.update({field: _field_to_yaml(TYPE_INT, getattr(app, field))})
@ -945,7 +939,7 @@ def write_yaml(mf, app):
def _builds_to_yaml(app):
builds = ruamel.yaml.comments.CommentedSeq()
for build in app.builds:
for build in app.get('Builds', []):
b = ruamel.yaml.comments.CommentedMap()
for field in build_flags:
value = getattr(build, field)

View file

@ -78,7 +78,7 @@ def main():
continue
newbuilds = []
for build in app.builds:
for build in app.get('Builds', []):
new = metadata.Build()
for k in metadata.build_flags:
v = build[k]
@ -86,7 +86,7 @@ def main():
continue
new[k] = v
newbuilds.append(new)
app.builds = newbuilds
app['Builds'] = newbuilds
# rewrite to temporary file before overwriting existsing
# file in case there's a bug in write_metadata

View file

@ -420,7 +420,7 @@ def main():
else:
build_dir = os.path.join('build', appid)
if app.builds:
if app.get('Builds'):
logging.info(_("Processing {appid}").format(appid=appid))
# Set up vcs interface and make sure we have the latest code...
vcs = common.getvcs(app.RepoType, app.Repo, build_dir)
@ -434,9 +434,9 @@ def main():
logging.warning(_('Scanner found {count} problems in {appid}:')
.format(count=count, appid=appid))
probcount += count
app.builds = []
app['Builds'] = []
for build in app.builds:
for build in app.get('Builds', []):
json_per_build = DEFAULT_JSON_PER_BUILD
json_per_appid[build.versionCode] = json_per_build

View file

@ -157,9 +157,8 @@ def status_update_json(apps, apks):
for apk in apks:
if apk['packageName'] == appid:
apklist.append(apk)
builds = app.get('builds', [])
validapks = 0
for build in builds:
for build in app.get('Builds', []):
if not build.get('disable'):
builtit = False
for apk in apklist:
@ -252,7 +251,7 @@ def update_wiki(apps, apks):
gotcurrentver = True
apklist.append(apk)
# Include ones we can't build, as a special case...
for build in app.builds:
for build in app.get('Builds', []):
if build.disable:
if build.versionCode == app.CurrentVersionCode:
cantupdate = True
@ -411,7 +410,7 @@ def delete_disabled_builds(apps, apkcache, repodirs):
:param repodirs: the repo directories to process
"""
for appid, app in apps.items():
for build in app['builds']:
for build in app.get('Builds', []):
if not build.disable:
continue
apkfilename = common.get_release_filename(app, build)
@ -742,7 +741,7 @@ def translate_per_build_anti_features(apps, apks):
antiFeatures = dict()
for packageName, app in apps.items():
d = dict()
for build in app['builds']:
for build in app.get('Builds', []):
afl = build.get('antifeatures')
if afl:
d[int(build.versionCode)] = afl
@ -1022,8 +1021,8 @@ def copy_triple_t_store_metadata(apps):
if os.path.exists(p):
gradle_subdirs.add(p)
flavors = set()
if app.builds:
flavors = app.builds[0].gradle
if app.get('Builds'):
flavors = app['Builds'][0].gradle
for flavor in flavors:
if flavor not in ('yes', 'no'):
p = os.path.join('build', packageName, gradle_path, 'src', flavor, 'play')
@ -1148,9 +1147,12 @@ def insert_localized_app_metadata(apps):
# flavours specified in build receipt
build_flavours = ""
if apps[packageName] and 'builds' in apps[packageName] and len(apps[packageName].builds) > 0\
and 'gradle' in apps[packageName].builds[-1]:
build_flavours = apps[packageName].builds[-1].gradle
if (
apps[packageName]
and len(apps[packageName].get('Builds', [])) > 0
and 'gradle' in apps[packageName]['Builds'][-1]
):
build_flavours = apps[packageName]['Builds'][-1]['gradle']
if len(segments) >= 5 and segments[4] == "fastlane" and segments[3] not in build_flavours:
logging.debug("ignoring due to wrong flavour")