Rework app into a class

This simplifies usage, goes from

	app['Foo']
to
	app.Foo

Also makes static analyzers able to detect invalid attributes as the set
is now limited in the class definition.

As a bonus, setting of the default field values is now done in the
constructor, not separately and manually.
This commit is contained in:
Daniel Martí 2015-11-28 13:09:47 +01:00
parent de12cfdbe1
commit ab614ab442
18 changed files with 515 additions and 433 deletions

View file

@ -116,8 +116,8 @@ class CommonTest(unittest.TestCase):
config['sdk_path'] = os.getenv('ANDROID_HOME')
config['build_tools'] = 'FAKE_BUILD_TOOLS_VERSION'
fdroidserver.common.config = config
app = dict()
app['id'] = 'org.fdroid.froid'
app = fdroidserver.metadata.App()
app.id = 'org.fdroid.froid'
build = dict(fdroidserver.metadata.flag_defaults)
build['commit'] = 'master'
build['forceversion'] = True

View file

@ -30,12 +30,12 @@ class ImportTest(unittest.TestCase):
fdroidserver.common.config['sdk_path'] = '/fake/path/to/android-sdk'
url = 'https://gitlab.com/fdroid/fdroidclient'
appid, app = fdroidserver.metadata.get_default_app_info()
app['Update Check Mode'] = "Tags"
app = fdroidserver.metadata.get_default_app_info()
app.UpdateCheckMode = "Tags"
root_dir, src_dir = import_proxy.get_metadata_from_url(app, url)
self.assertEquals(app['Repo Type'], 'git')
self.assertEquals(app['Web Site'], 'https://gitlab.com/fdroid/fdroidclient')
self.assertEquals(app['Repo'], 'https://gitlab.com/fdroid/fdroidclient.git')
self.assertEquals(app.RepoType, 'git')
self.assertEquals(app.WebSite, 'https://gitlab.com/fdroid/fdroidclient')
self.assertEquals(app.Repo, 'https://gitlab.com/fdroid/fdroidclient.git')
if __name__ == "__main__":

View file

@ -39,10 +39,15 @@ class MetadataTest(unittest.TestCase):
apps = fdroidserver.metadata.read_metadata(xref=True)
for appid in ('org.smssecure.smssecure', 'org.adaway', 'net.osmand.plus', 'org.videolan.vlc'):
with open(os.path.join('metadata', appid + '.pickle'), 'r') as f:
app = apps[appid]
savepath = os.path.join('metadata', appid + '.pickle')
self.assertTrue(appid in apps)
with open(savepath, 'r') as f:
frompickle = pickle.load(f)
self.assertTrue(appid in apps.keys())
self.assertEquals(apps[appid], frompickle)
frommeta = app.field_dict()
self.assertEquals(frommeta, frompickle)
# with open(savepath, 'wb') as f:
# pickle.dump(app, f)
if __name__ == "__main__":

View file

@ -491,12 +491,16 @@ S'metadata/net.osmand.plus.xml'
p178
sS'Disabled'
p179
NsS'Update Check Name'
NsS'added'
p180
NsS'Vercode Operation'
NsS'lastupdated'
p181
NsS'Current Version'
NsS'Update Check Name'
p182
S'1.9.5'
NsS'Vercode Operation'
p183
NsS'Current Version'
p184
S'1.9.5'
p185
s.

View file

@ -2290,4 +2290,8 @@ NsS'Update Check Name'
p483
NsS'Vercode Operation'
p484
Ns.
NsS'added'
p485
NsS'lastupdated'
p486
Ns.

View file

@ -772,4 +772,8 @@ NsS'Update Check Name'
p227
NsS'Vercode Operation'
p228
Ns.
NsS'added'
p229
NsS'lastupdated'
p230
Ns.

View file

@ -5610,14 +5610,18 @@ S'metadata/org.videolan.vlc.yaml'
p1519
sS'Disabled'
p1520
NsS'Update Check Name'
NsS'added'
p1521
NsS'Vercode Operation'
NsS'lastupdated'
p1522
S'%c + 5'
NsS'Update Check Name'
p1523
sS'Current Version'
NsS'Vercode Operation'
p1524
S'1.2.6'
S'%c + 5'
p1525
sS'Current Version'
p1526
S'1.2.6'
p1527
s.