Skip to content

Commit

Permalink
[LINT] handle more file types in ASF header (#3235)
Browse files Browse the repository at this point in the history
* Update add_asf_header.py

* Update add_asf_header.py
  • Loading branch information
eqy authored and tqchen committed May 24, 2019
1 parent 28e8eca commit b2f8b96
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tests/lint/add_asf_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
""".strip()

FMT_MAP = {
"sh" : header_pystyle,
"cc" : header_cstyle,
"h" : header_cstyle,
"py" : header_pystyle,
Expand All @@ -128,6 +129,7 @@
"cmake" : header_pystyle,
"rst" : header_rststyle,
"gradle" : header_groovystyle,
"xml": header_mdstyle,
}

def add_header(fname, header):
Expand All @@ -142,8 +144,23 @@ def add_header(fname, header):
return

with open(fname, "w") as outfile:
outfile.write(header + "\n\n")
outfile.write(orig)
skipline = False
lines = orig.split('\n')
ext = os.path.splitext(fname)[1][1:]
if ext == 'sh' and lines[0][:2] == '#!':
skipline = True
elif ext == 'xml' and lines[0][:2] == '<?':
skipline = True

if skipline:
outfile.write(lines[0] + "\n")
outfile.write(header + "\n\n")
outfile.write("\n".join(lines[1:]))
outfile.write(header + "\n\n")
outfile.write(orig)
else:
outfile.write(header + "\n\n")
outfile.write(orig)
print("Add header to %s" % fname)


Expand All @@ -160,6 +177,8 @@ def main(args):
suffix = fname.split(".")[-1]
if suffix in FMT_MAP:
add_header(fname, FMT_MAP[suffix])
elif os.path.basename(fname) == 'gradle.properties':
add_header(fname, FMT_MAP['h'])
else:
print("Cannot handle %s ..." % fname)

Expand Down

0 comments on commit b2f8b96

Please sign in to comment.