1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-30 03:18:20 +00:00
trezor-firmware/python/helper-scripts/relicence.py

70 lines
1.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
LICENSE_NOTICE = """\
# This file is part of the Trezor project.
#
2019-05-29 16:44:09 +00:00
# Copyright (C) 2012-2019 SatoshiLabs and contributors
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
"""
2019-05-29 16:44:09 +00:00
SHEBANG_HEADER = """\
#!/usr/bin/env python3
"""
EXCLUDE_FILES = ["trezorlib/__init__.py", "trezorlib/_ed25519.py"]
def one_file(fp):
lines = list(fp)
new = lines[:]
2019-05-29 16:44:09 +00:00
shebang_header = False
if new[0].startswith("#!"):
shebang_header = True
new.pop(0)
if not new[0].strip():
new.pop(0)
while new and new[0][0] == "#":
new.pop(0)
while new and new[0].strip() == "":
new.pop(0)
2019-05-29 16:44:09 +00:00
new.insert(0, LICENSE_NOTICE)
if shebang_header:
new.insert(0, SHEBANG_HEADER)
data = "".join(new)
fp.seek(0)
fp.write(data)
fp.truncate()
import glob
import os
for fn in glob.glob("trezorlib/**/*.py", recursive=True):
2019-05-29 16:44:09 +00:00
if fn.startswith("trezorlib/messages/"):
continue
if fn in EXCLUDE_FILES:
continue
statinfo = os.stat(fn)
if statinfo.st_size == 0:
continue
with open(fn, "r+") as fp:
one_file(fp)