comparison DEPENDENCIES/mingw32/Python27/Lib/site-packages/numpy/distutils/line_endings.py @ 87:2a2c65a20a8b

Add Python libs and headers
author Chris Cannam
date Wed, 25 Feb 2015 14:05:22 +0000
parents
children
comparison
equal deleted inserted replaced
86:413a9d26189e 87:2a2c65a20a8b
1 """ Functions for converting from DOS to UNIX line endings
2
3 """
4 from __future__ import division, absolute_import, print_function
5
6 import sys, re, os
7
8 def dos2unix(file):
9 "Replace CRLF with LF in argument files. Print names of changed files."
10 if os.path.isdir(file):
11 print(file, "Directory!")
12 return
13
14 data = open(file, "rb").read()
15 if '\0' in data:
16 print(file, "Binary!")
17 return
18
19 newdata = re.sub("\r\n", "\n", data)
20 if newdata != data:
21 print('dos2unix:', file)
22 f = open(file, "wb")
23 f.write(newdata)
24 f.close()
25 return file
26 else:
27 print(file, 'ok')
28
29 def dos2unix_one_dir(modified_files, dir_name, file_names):
30 for file in file_names:
31 full_path = os.path.join(dir_name, file)
32 file = dos2unix(full_path)
33 if file is not None:
34 modified_files.append(file)
35
36 def dos2unix_dir(dir_name):
37 modified_files = []
38 os.path.walk(dir_name, dos2unix_one_dir, modified_files)
39 return modified_files
40 #----------------------------------
41
42 def unix2dos(file):
43 "Replace LF with CRLF in argument files. Print names of changed files."
44 if os.path.isdir(file):
45 print(file, "Directory!")
46 return
47
48 data = open(file, "rb").read()
49 if '\0' in data:
50 print(file, "Binary!")
51 return
52 newdata = re.sub("\r\n", "\n", data)
53 newdata = re.sub("\n", "\r\n", newdata)
54 if newdata != data:
55 print('unix2dos:', file)
56 f = open(file, "wb")
57 f.write(newdata)
58 f.close()
59 return file
60 else:
61 print(file, 'ok')
62
63 def unix2dos_one_dir(modified_files, dir_name, file_names):
64 for file in file_names:
65 full_path = os.path.join(dir_name, file)
66 unix2dos(full_path)
67 if file is not None:
68 modified_files.append(file)
69
70 def unix2dos_dir(dir_name):
71 modified_files = []
72 os.path.walk(dir_name, unix2dos_one_dir, modified_files)
73 return modified_files
74
75 if __name__ == "__main__":
76 dos2unix_dir(sys.argv[1])