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