fix-header.py: Preserve shebang

Preserve shebang at start of file. Also ran fix-header.py on itself.
This commit is contained in:
Philipp Wolfer
2020-02-21 21:04:10 +01:00
committed by Laurent Monin
parent 5a0abcf156
commit a319513410

View File

@@ -4,6 +4,7 @@
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2020 Laurent Monin
# Copyright (C) 2020 Philipp Wolfer
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -19,6 +20,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import argparse
from collections import defaultdict
import glob
@@ -114,6 +116,9 @@ def parse_file(path):
with open(path) as f:
lines = f.readlines()
found = defaultdict(lambda: None)
if lines[0].startswith('#!'):
found["shebang"] = lines[0].rstrip()
del lines[0]
for num, line in enumerate(lines):
if line.startswith("# Automatically generated"):
found['autogenerated'] = num
@@ -232,6 +237,7 @@ def fix_header(path):
has_content = bool(before + after)
parts = list(filter(None, [
found["shebang"],
CODING_TEXT.strip(),
LICENSE_TOP.strip(),
new_copyright.strip(),