PEP8 radio/util/copyright.py

Remove unused imports, fix whitespace, fix comments
This commit is contained in:
Sean Vig
2015-12-13 18:32:54 -06:00
parent be154140b3
commit 9d13484291
+12 -10
View File
@@ -2,11 +2,10 @@
from __future__ import print_function from __future__ import print_function
import os
import re
import sys import sys
def writeheader(filename,header):
def writeheader(filename, header):
""" """
write a header to filename, write a header to filename,
skip files where first line after optional shebang matches the skip regex skip files where first line after optional shebang matches the skip regex
@@ -19,7 +18,7 @@ def writeheader(filename,header):
f.close() f.close()
output = [] output = []
#comment out the next 3 lines if you don't wish to preserve shebangs # comment out the next 3 lines if you don't wish to preserve shebangs
if len(inpt) > 0 and inpt[0].startswith("#!"): if len(inpt) > 0 and inpt[0].startswith("#!"):
output.append(inpt[0]) output.append(inpt[0])
inpt = inpt[1:] inpt = inpt[1:]
@@ -27,22 +26,23 @@ def writeheader(filename,header):
if inpt[0].strip().startswith("/*"): if inpt[0].strip().startswith("/*"):
for i, line in enumerate(inpt): for i, line in enumerate(inpt):
if line.strip().endswith("*/"): if line.strip().endswith("*/"):
inpt = inpt[i+1:] inpt = inpt[i + 1:]
break break
while not inpt[0].strip(): while not inpt[0].strip():
inpt = inpt[1:] inpt = inpt[1:]
output.extend(header) #add the header output.extend(header) # add the header
for line in inpt: for line in inpt:
output.append(line) output.append(line)
try: try:
f = open(filename,'w') f = open(filename,'w')
f.writelines(output) f.writelines(output)
f.close() f.close()
print("added header to %s" %filename) print("added header to %s" % filename)
except IOError as err: except IOError as err:
print("something went wrong trying to add header to %s: %s" % (filename,err)) print("something went wrong trying to add header to %s: %s" % (filename, err))
def main(args=sys.argv): def main(args=sys.argv):
headerfile = open(args[1]) headerfile = open(args[1])
@@ -50,5 +50,7 @@ def main(args=sys.argv):
headerfile.close() headerfile.close()
writeheader(args[2], header) writeheader(args[2], header)
#call the main method
main() if __name__ == '__main__':
# call the main method
main()