blob: 4fed6ce4b01f3f7b5bd9cfdeac0ce02612c54c8b [file] [log] [blame]
Christopher Dunndc0f7362011-06-21 21:18:49 +00001import os.path
2
3def fix_source_eol( path, is_dry_run = True, verbose = True, eol = '\n' ):
4 """Makes sure that all sources have the specified eol sequence (default: unix)."""
5 if not os.path.isfile( path ):
6 raise ValueError( 'Path "%s" is not a file' % path )
7 try:
8 f = open(path, 'rb')
9 except IOError, msg:
10 print >> sys.stderr, "%s: I/O Error: %s" % (file, str(msg))
11 return False
12 try:
13 raw_lines = f.readlines()
14 finally:
15 f.close()
16 fixed_lines = [line.rstrip('\r\n') + eol for line in raw_lines]
17 if raw_lines != fixed_lines:
18 print '%s =>' % path,
19 if not is_dry_run:
20 f = open(path, "wb")
21 try:
22 f.writelines(fixed_lines)
23 finally:
24 f.close()
25 if verbose:
26 print is_dry_run and ' NEED FIX' or ' FIXED'
27 return True
28##
29##
30##
31##def _do_fix( is_dry_run = True ):
32## from waftools import antglob
33## python_sources = antglob.glob( '.',
34## includes = '**/*.py **/wscript **/wscript_build',
35## excludes = antglob.default_excludes + './waf.py',
36## prune_dirs = antglob.prune_dirs + 'waf-* ./build' )
37## for path in python_sources:
38## _fix_python_source( path, is_dry_run )
39##
40## cpp_sources = antglob.glob( '.',
41## includes = '**/*.cpp **/*.h **/*.inl',
42## prune_dirs = antglob.prune_dirs + 'waf-* ./build' )
43## for path in cpp_sources:
44## _fix_source_eol( path, is_dry_run )
45##
46##
47##def dry_fix(context):
48## _do_fix( is_dry_run = True )
49##
50##def fix(context):
51## _do_fix( is_dry_run = False )
52##
53##def shutdown():
54## pass
55##
56##def check(context):
57## # Unit tests are run when "check" target is used
58## ut = UnitTest.unit_test()
59## ut.change_to_testfile_dir = True
60## ut.want_to_see_test_output = True
61## ut.want_to_see_test_error = True
62## ut.run()
63## ut.print_results()