aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorunknown <crupest@outlook.com>2019-08-07 17:38:56 +0800
committerunknown <crupest@outlook.com>2019-08-07 17:38:56 +0800
commite283a3e745bad05a55c572646d7b20fbaaeb522d (patch)
treedf5d1325c3b73b17f4f86b71097775e9ce3fa122 /tools
parent5f5458518df0475fa36af754cae52eb31eb92fa3 (diff)
downloadtimeline-e283a3e745bad05a55c572646d7b20fbaaeb522d.tar.gz
timeline-e283a3e745bad05a55c572646d7b20fbaaeb522d.tar.bz2
timeline-e283a3e745bad05a55c572646d7b20fbaaeb522d.zip
Add script to convert encoding and eof. And of course run it.
Diffstat (limited to 'tools')
-rw-r--r--tools/convert-eol.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/convert-eol.py b/tools/convert-eol.py
new file mode 100644
index 00000000..3ea8ed7c
--- /dev/null
+++ b/tools/convert-eol.py
@@ -0,0 +1,35 @@
+# This is a python script that converts all text source codes into
+# CRLF (Windows line ending) eol format and UTF-8 with NO BOM encoding.
+
+import glob
+import os.path
+
+project_root = os.path.relpath(os.path.join(os.path.dirname(__file__), '..'))
+
+
+def convert(file_path):
+ with open(file_path, 'r', encoding='utf-8') as open_file:
+ content = open_file.read()
+
+ #if there is BOM, remove BOM
+ if content[0] == '\ufeff':
+ content = content[1:]
+
+ with open(file_path, 'w', encoding='utf-8', newline='\r\n') as open_file:
+ open_file.write(content)
+
+
+glob_list = [
+ './nuget.config',
+ '**/*.sln',
+ '**/*.cs',
+ '**/*.csproj',
+ '**/appsettings*.json'
+]
+
+for glob_pattern in glob_list:
+ for f in glob.glob(glob_pattern, recursive=True):
+ print('Converting {}'.format(f))
+ convert(f)
+
+print('Done!!!')