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