1 # -*- coding: utf-8 -*-
3 from itertools import chain
6 /* WARNING: This is auto-generated file. Do not modify, since changes will
7 * be lost! Modify the generating script instead.
9 * Generated from {registryName} revision {revision}.
13 def genInlHeader (registryName, revision):
14 return INL_HEADER_TMPL.format(
15 registryName = registryName,
16 revision = str(revision))
18 def genInlHeaderForSource (registrySource):
19 return genInlHeaderForSource(registrySource.getFilename(), registrySource.getRevision())
21 def nextMod (val, mod):
25 return int(val/mod)*mod + mod
27 def indentLines (lines):
31 lineColumns = [line.split("\t") for line in lines if line is not None]
32 if len(lineColumns) == 0:
35 numColumns = max(len(line) for line in lineColumns)
37 # Figure out max length per column
38 columnLengths = [nextMod(max(len(line[ndx]) for line in lineColumns if len(line) > ndx), tabSize) for ndx in range(numColumns)]
40 for line in lineColumns:
42 for columnNdx, col in enumerate(line[:-1]):
44 while colLen < columnLengths[columnNdx]:
46 colLen = nextMod(colLen, tabSize)
50 indented.append(line[-1])
51 yield "".join(indented)
53 def writeLines (filename, lines):
54 with open(filename, 'wb') as f:
61 def writeInlFile (filename, header, source):
62 writeLines(filename, chain([header], source))