mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-11 23:23:27 +02:00
Some more readability/performance tweaks
* Use set() instead of dict() * No 'if foo: True else: False' * Don't check for invalid fields twice
This commit is contained in:
parent
b1a9180d12
commit
cd4e43c3c2
@ -975,10 +975,7 @@ def parse_xml_metadata(metadatapath):
|
|||||||
|
|
||||||
# TODO handle this using <xsd:element type="xsd:boolean> in a schema
|
# TODO handle this using <xsd:element type="xsd:boolean> in a schema
|
||||||
if not isinstance(app.RequiresRoot, bool):
|
if not isinstance(app.RequiresRoot, bool):
|
||||||
if app.RequiresRoot == 'true':
|
app.RequiresRoot = app.RequiresRoot == 'true'
|
||||||
app.RequiresRoot = True
|
|
||||||
else:
|
|
||||||
app.RequiresRoot = False
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
||||||
@ -1064,7 +1061,7 @@ def parse_txt_metadata(metadatapath):
|
|||||||
multiline_lines = []
|
multiline_lines = []
|
||||||
curcomments = []
|
curcomments = []
|
||||||
build = None
|
build = None
|
||||||
vc_seen = {}
|
vc_seen = set()
|
||||||
|
|
||||||
c = 0
|
c = 0
|
||||||
for line in metafile:
|
for line in metafile:
|
||||||
@ -1099,8 +1096,6 @@ def parse_txt_metadata(metadatapath):
|
|||||||
f, v = line.split(':', 1)
|
f, v = line.split(':', 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise MetaDataException("Invalid metadata in " + linedesc)
|
raise MetaDataException("Invalid metadata in " + linedesc)
|
||||||
if f != f.strip() or v != v.strip():
|
|
||||||
raise MetaDataException("Extra spacing found in " + linedesc)
|
|
||||||
|
|
||||||
# Translate obsolete fields...
|
# Translate obsolete fields...
|
||||||
if f == 'Market Version':
|
if f == 'Market Version':
|
||||||
@ -1129,23 +1124,23 @@ def parse_txt_metadata(metadatapath):
|
|||||||
app.builds.append(build)
|
app.builds.append(build)
|
||||||
add_comments('build:' + app.builds[-1].vercode)
|
add_comments('build:' + app.builds[-1].vercode)
|
||||||
elif ftype == TYPE_BUILD_V2:
|
elif ftype == TYPE_BUILD_V2:
|
||||||
build = Build()
|
|
||||||
vv = v.split(',')
|
vv = v.split(',')
|
||||||
if len(vv) != 2:
|
if len(vv) != 2:
|
||||||
raise MetaDataException('Build should have comma-separated version and vercode, not "{0}", in {1}'
|
raise MetaDataException('Build should have comma-separated version and vercode, not "{0}", in {1}'
|
||||||
.format(v, linedesc))
|
.format(v, linedesc))
|
||||||
|
build = Build()
|
||||||
build.version = vv[0]
|
build.version = vv[0]
|
||||||
build.vercode = vv[1]
|
build.vercode = vv[1]
|
||||||
if build.vercode in vc_seen:
|
if build.vercode in vc_seen:
|
||||||
raise MetaDataException('Duplicate build recipe found for vercode %s in %s' % (
|
raise MetaDataException('Duplicate build recipe found for vercode %s in %s' % (
|
||||||
build.vercode, linedesc))
|
build.vercode, linedesc))
|
||||||
vc_seen[build.vercode] = True
|
vc_seen.add(build.vercode)
|
||||||
del buildlines[:]
|
del buildlines[:]
|
||||||
mode = 3
|
mode = 3
|
||||||
elif ftype == TYPE_OBSOLETE:
|
elif ftype == TYPE_OBSOLETE:
|
||||||
pass # Just throw it away!
|
pass # Just throw it away!
|
||||||
else:
|
else:
|
||||||
raise MetaDataException("Unrecognised field type for " + f + " in " + linedesc)
|
raise MetaDataException("Unrecognised field '" + f + "' in " + linedesc)
|
||||||
elif mode == 1: # Multiline field
|
elif mode == 1: # Multiline field
|
||||||
if line == '.':
|
if line == '.':
|
||||||
mode = 0
|
mode = 0
|
||||||
|
Loading…
Reference in New Issue
Block a user