Avoids typos, such as one I just found which was 'strsng' isntead of
'string'. The static analyzer can catch those if they are constants.
Comparing ints is also faster than strings, which adds up in readmeta.
for m, r in checks:
v = app.get_field(f)
t = metadata.metafieldtype(f)
for m, r in checks:
v = app.get_field(f)
t = metadata.metafieldtype(f)
+ if t == metadata.TYPE_MULTILINE:
for l in v.splitlines():
if m.match(l):
yield "%s at line '%s': %s" % (f, l, r)
for l in v.splitlines():
if m.match(l):
yield "%s at line '%s': %s" % (f, l, r)
else:
self.set_field(f, v)
else:
self.set_field(f, v)
+TYPE_UNKNOWN = 0
+TYPE_OBSOLETE = 1
+TYPE_STRING = 2
+TYPE_BOOL = 3
+TYPE_LIST = 4
+TYPE_SCRIPT = 5
+TYPE_MULTILINE = 6
+TYPE_BUILD = 7
+TYPE_BUILD_V2 = 8
+
def metafieldtype(name):
if name in ['Description', 'Maintainer Notes']:
def metafieldtype(name):
if name in ['Description', 'Maintainer Notes']:
if name in ['Categories', 'AntiFeatures']:
if name in ['Categories', 'AntiFeatures']:
if name == 'Build Version':
if name == 'Build Version':
- return 'string'
- return 'unknown'
+ return TYPE_STRING
+ return TYPE_UNKNOWN
# In the order in which they are laid out on files
# In the order in which they are laid out on files
def flagtype(name):
if name in list_flags:
def flagtype(name):
if name in list_flags:
- return 'bool'
- return 'string'
+ return TYPE_BOOL
+ return TYPE_STRING
# Designates a metadata field type and checks that it matches
# Designates a metadata field type and checks that it matches
continue
ftype = flagtype(k)
continue
ftype = flagtype(k)
+ if ftype == TYPE_SCRIPT:
build.__dict__[k] = re.sub(esc_newlines, '', v).lstrip().rstrip()
build.__dict__[k] = re.sub(esc_newlines, '', v).lstrip().rstrip()
+ elif ftype == TYPE_BOOL:
# TODO handle this using <xsd:element type="xsd:boolean> in a schema
if isinstance(v, basestring) and v == 'true':
build.__dict__[k] = True
# TODO handle this using <xsd:element type="xsd:boolean> in a schema
if isinstance(v, basestring) and v == 'true':
build.__dict__[k] = True
- elif ftype == 'string':
+ elif ftype == TYPE_BOOL:
if isinstance(v, bool) and v:
build.__dict__[k] = 'yes'
if isinstance(v, bool) and v:
build.__dict__[k] = 'yes'
pk, pv = bv
pk = pk.lstrip()
t = flagtype(pk)
pk, pv = bv
pk = pk.lstrip()
t = flagtype(pk)
pv = split_list_values(pv)
build.set_flag(pk, pv)
pv = split_list_values(pv)
build.set_flag(pk, pv)
- elif t == 'string' or t == 'script':
+ elif t == TYPE_STRING or t == TYPE_SCRIPT:
if pv == 'yes':
build.set_flag(pk, True)
if pv == 'yes':
build.set_flag(pk, True)
f = 'Current Version Code'
ftype = metafieldtype(f)
f = 'Current Version Code'
ftype = metafieldtype(f)
- if ftype not in ['build', 'buildv2']:
+ if ftype not in [TYPE_BUILD, TYPE_BUILD_V2]:
- if ftype == 'multiline':
+ if ftype == TYPE_MULTILINE:
mode = 1
if v:
raise MetaDataException("Unexpected text on same line as " + f + " in " + linedesc)
mode = 1
if v:
raise MetaDataException("Unexpected text on same line as " + f + " in " + linedesc)
- elif ftype == 'string':
+ elif ftype == TYPE_STRING:
+ elif ftype == TYPE_LIST:
app.set_field(f, split_list_values(v))
app.set_field(f, split_list_values(v))
+ elif ftype == TYPE_BUILD:
if v.endswith("\\"):
mode = 2
del buildlines[:]
if v.endswith("\\"):
mode = 2
del buildlines[:]
build = parse_buildline([v])
app.builds.append(build)
add_comments('build:' + app.builds[-1].vercode)
build = parse_buildline([v])
app.builds.append(build)
add_comments('build:' + app.builds[-1].vercode)
- elif ftype == 'buildv2':
+ elif ftype == TYPE_BUILD_V2:
build = Build()
vv = v.split(',')
if len(vv) != 2:
build = Build()
vv = v.split(',')
if len(vv) != 2:
vc_seen[build.vercode] = True
del buildlines[:]
mode = 3
vc_seen[build.vercode] = True
del buildlines[:]
mode = 3
- elif ftype == 'obsolete':
+ elif ftype == TYPE_OBSOLETE:
pass # Just throw it away!
else:
raise MetaDataException("Unrecognised field type for " + f + " in " + linedesc)
pass # Just throw it away!
else:
raise MetaDataException("Unrecognised field type for " + f + " in " + linedesc)
def w_field(f, v):
t = metafieldtype(f)
def w_field(f, v):
t = metafieldtype(f)
+ elif t == TYPE_MULTILINE:
v = '\n' + v + '\n.'
mf.write("%s:%s\n" % (f, v))
v = '\n' + v + '\n.'
mf.write("%s:%s\n" % (f, v))
t = flagtype(f)
out = ' %s=' % f
t = flagtype(f)
out = ' %s=' % f
out += '&& \\\n '.join([s.lstrip() for s in v.split('&& ')])
out += '&& \\\n '.join([s.lstrip() for s in v.split('&& ')])
out += ','.join(v) if type(v) == list else v
mf.write(out)
out += ','.join(v) if type(v) == list else v
mf.write(out)
if t is None:
t = metafieldtype(f)
v = ''
if t is None:
t = metafieldtype(f)
v = ''
v = '\n'
for e in v:
v += prefix + ' - ' + escape(e) + '\n'
v = '\n'
for e in v:
v += prefix + ' - ' + escape(e) + '\n'
+ elif t == TYPE_MULTILINE:
v = ' |\n'
for l in v.splitlines():
if l:
v += prefix + ' ' + l + '\n'
else:
v += '\n'
v = ' |\n'
for l in v.splitlines():
if l:
v += prefix + ' ' + l + '\n'
else:
v += '\n'
cmds = [s + '&& \\' for s in v.split('&& ')]
if len(cmds) > 0:
cmds[-1] = cmds[-1][:-len('&& \\')]
cmds = [s + '&& \\' for s in v.split('&& ')]
if len(cmds) > 0:
cmds[-1] = cmds[-1][:-len('&& \\')]
mf.write("builds:\n")
first_build = False
mf.write("builds:\n")
first_build = False
- w_field('versionName', build.version, ' - ', 'string')
- w_field('versionCode', build.vercode, ' ', 'strsng')
+ w_field('versionName', build.version, ' - ', TYPE_STRING)
+ w_field('versionCode', build.vercode, ' ', TYPE_STRING)
for f in build_flags_order:
v = build.get_flag(f)
if not v:
for f in build_flags_order:
v = build.get_flag(f)
if not v: