chiark / gitweb /
convert App to subclass of dict to support parsing/dumping libs
authorHans-Christoph Steiner <hans@eds.org>
Wed, 23 Nov 2016 16:25:59 +0000 (17:25 +0100)
committerHans-Christoph Steiner <hans@eds.org>
Fri, 24 Feb 2017 10:01:01 +0000 (11:01 +0100)
commitb7fc7f2228986d0210e221c9ec8ddcc2ad9b93bc
treebf732e8b9aacee25e2ebdce203fde4d7b9ba4733
parent4625651192e6b1f619df89e93b2062bb7270409a
convert App to subclass of dict to support parsing/dumping libs

Python is heavily based on its core data types, and dict is one of the more
important ones.  Even classes are basically a wrapper around a dict. This
converts metadata.App to be a subclass of dict so it can behave like a dict
when being dumped and loaded.  This makes its drastically easier to use
different data formats for build metadata and for sending data to the
client.  This approach will ultimately mean we no longer have to maintain
custom parsing and dumping code.

This also means then that the YAML/JSON field names will not have spaces in
them, and they will match exactly what it used as the dict keys once the
data is parsed, as well as matching exactly the instance attribute names:

* CurrentVersion: 1.2.6
* app['CurrentVersion'] == '1.2.6'
* app.CurrentVersion == '1.2.6'

Inspired by:
https://goodcode.io/articles/python-dict-object/
fdroidserver/lint.py
fdroidserver/metadata.py
fdroidserver/update.py
tests/import.TestCase
tests/metadata.TestCase
tests/metadata/dump/org.adaway.yaml
tests/metadata/dump/org.smssecure.smssecure.yaml
tests/metadata/dump/org.videolan.vlc.yaml
tests/metadata/org.adaway.json
tests/metadata/org.videolan.vlc.yml