From 8191716868084a8fd28c4447a6aa97c32ce25db2 Mon Sep 17 00:00:00 2001 From: AffectedArc07 Date: Mon, 13 Jan 2020 11:53:36 +0000 Subject: [PATCH] CI to check for wrong line ending --- .travis.yml | 1 + tools/travis/check_line_endings.py | 47 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tools/travis/check_line_endings.py diff --git a/.travis.yml b/.travis.yml index ab3b1003c3..3082e1a18e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,7 @@ matrix: - find . -name "*.json" -not -path "./tgui/node_modules/*" -print0 | xargs -0 python3 ./tools/json_verifier.py - tools/travis/build_tgui.sh - tools/travis/check_grep.sh + - python3 tools/travis/check_line_endings.py - ~/dreamchecker - name: "Compile All Maps" diff --git a/tools/travis/check_line_endings.py b/tools/travis/check_line_endings.py new file mode 100644 index 0000000000..3ee7baf7aa --- /dev/null +++ b/tools/travis/check_line_endings.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +import os +import sys +import glob + +WINDOWS_NEWLINE = b'\r\n' + +FILES_TO_READ = [] +FILES_TO_READ.extend(glob.glob(r"**\*.dm", recursive=True)) +FILES_TO_READ.extend(glob.glob(r"**\*.dmm", recursive=True)) +FILES_TO_READ.extend(glob.glob(r"*.dme")) +#for i in FILES_TO_READ: +# if os.path.isdir(i): +# FILES_TO_READ.remove(i) + +def _reader(filepath): + data = open(filepath, "rb") + return data + +def main(): + filelist = [] + foundfiles = False + + for file in FILES_TO_READ: + data = _reader(file) + lines = data.readlines() + for line in lines: + if line.endswith(WINDOWS_NEWLINE): + filelist.append(file) + foundfiles = True + break + data.close() + + if not foundfiles: + print("No CRLF files found.") + sys.exit(0) + else: + print("Found files with suspected CRLF type.") + for i in filelist: + print(i) + sys.exit(1) + + + +if __name__ == "__main__": + main()