2017-07-21 12:44:36 +02:00
|
|
|
# Copyright 2010 Baptiste Lepilleur and The JsonCpp Authors
|
2015-04-10 03:01:33 +02:00
|
|
|
# Distributed under MIT license, or public domain if desired and
|
|
|
|
# recognized in your jurisdiction.
|
|
|
|
# See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
|
|
|
|
|
2014-11-20 06:30:47 +01:00
|
|
|
from __future__ import print_function
|
2011-06-21 23:18:49 +02:00
|
|
|
import os.path
|
2015-07-04 00:47:00 +02:00
|
|
|
import sys
|
2011-06-21 23:18:49 +02:00
|
|
|
|
2015-01-24 22:29:52 +01:00
|
|
|
def fix_source_eol(path, is_dry_run = True, verbose = True, eol = '\n'):
|
2011-06-21 23:18:49 +02:00
|
|
|
"""Makes sure that all sources have the specified eol sequence (default: unix)."""
|
2015-01-24 22:29:52 +01:00
|
|
|
if not os.path.isfile(path):
|
|
|
|
raise ValueError('Path "%s" is not a file' % path)
|
2011-06-21 23:18:49 +02:00
|
|
|
try:
|
|
|
|
f = open(path, 'rb')
|
2014-11-20 06:10:02 +01:00
|
|
|
except IOError as msg:
|
2014-11-20 06:30:47 +01:00
|
|
|
print("%s: I/O Error: %s" % (file, str(msg)), file=sys.stderr)
|
2011-06-21 23:18:49 +02:00
|
|
|
return False
|
|
|
|
try:
|
|
|
|
raw_lines = f.readlines()
|
|
|
|
finally:
|
|
|
|
f.close()
|
|
|
|
fixed_lines = [line.rstrip('\r\n') + eol for line in raw_lines]
|
|
|
|
if raw_lines != fixed_lines:
|
2014-11-20 06:30:47 +01:00
|
|
|
print('%s =>' % path, end=' ')
|
2011-06-21 23:18:49 +02:00
|
|
|
if not is_dry_run:
|
|
|
|
f = open(path, "wb")
|
|
|
|
try:
|
|
|
|
f.writelines(fixed_lines)
|
|
|
|
finally:
|
|
|
|
f.close()
|
|
|
|
if verbose:
|
2014-11-20 06:30:47 +01:00
|
|
|
print(is_dry_run and ' NEED FIX' or ' FIXED')
|
2011-06-21 23:18:49 +02:00
|
|
|
return True
|
2021-01-10 05:39:07 +01:00
|
|
|
##
|
|
|
|
##
|
2011-06-21 23:18:49 +02:00
|
|
|
##
|
2015-01-24 22:29:52 +01:00
|
|
|
##def _do_fix(is_dry_run = True):
|
2011-06-21 23:18:49 +02:00
|
|
|
## from waftools import antglob
|
2015-01-24 22:29:52 +01:00
|
|
|
## python_sources = antglob.glob('.',
|
2011-06-21 23:18:49 +02:00
|
|
|
## includes = '**/*.py **/wscript **/wscript_build',
|
|
|
|
## excludes = antglob.default_excludes + './waf.py',
|
2015-01-24 22:29:52 +01:00
|
|
|
## prune_dirs = antglob.prune_dirs + 'waf-* ./build')
|
2011-06-21 23:18:49 +02:00
|
|
|
## for path in python_sources:
|
2015-01-24 22:29:52 +01:00
|
|
|
## _fix_python_source(path, is_dry_run)
|
2011-06-21 23:18:49 +02:00
|
|
|
##
|
2015-01-24 22:29:52 +01:00
|
|
|
## cpp_sources = antglob.glob('.',
|
2011-06-21 23:18:49 +02:00
|
|
|
## includes = '**/*.cpp **/*.h **/*.inl',
|
2015-01-24 22:29:52 +01:00
|
|
|
## prune_dirs = antglob.prune_dirs + 'waf-* ./build')
|
2011-06-21 23:18:49 +02:00
|
|
|
## for path in cpp_sources:
|
2015-01-24 22:29:52 +01:00
|
|
|
## _fix_source_eol(path, is_dry_run)
|
2011-06-21 23:18:49 +02:00
|
|
|
##
|
|
|
|
##
|
|
|
|
##def dry_fix(context):
|
2015-01-24 22:29:52 +01:00
|
|
|
## _do_fix(is_dry_run = True)
|
2011-06-21 23:18:49 +02:00
|
|
|
##
|
|
|
|
##def fix(context):
|
2015-01-24 22:29:52 +01:00
|
|
|
## _do_fix(is_dry_run = False)
|
2011-06-21 23:18:49 +02:00
|
|
|
##
|
|
|
|
##def shutdown():
|
|
|
|
## pass
|
|
|
|
##
|
|
|
|
##def check(context):
|
|
|
|
## # Unit tests are run when "check" target is used
|
|
|
|
## ut = UnitTest.unit_test()
|
|
|
|
## ut.change_to_testfile_dir = True
|
|
|
|
## ut.want_to_see_test_output = True
|
|
|
|
## ut.want_to_see_test_error = True
|
|
|
|
## ut.run()
|
|
|
|
## ut.print_results()
|