2014-11-19 23:30:47 -06:00
|
|
|
from __future__ import print_function
|
2011-06-21 21:18:49 +00:00
|
|
|
import os.path
|
|
|
|
|
2015-01-24 15:29:52 -06:00
|
|
|
def fix_source_eol(path, is_dry_run = True, verbose = True, eol = '\n'):
|
2011-06-21 21:18:49 +00:00
|
|
|
"""Makes sure that all sources have the specified eol sequence (default: unix)."""
|
2015-01-24 15:29:52 -06:00
|
|
|
if not os.path.isfile(path):
|
|
|
|
raise ValueError('Path "%s" is not a file' % path)
|
2011-06-21 21:18:49 +00:00
|
|
|
try:
|
|
|
|
f = open(path, 'rb')
|
2014-11-19 23:10:02 -06:00
|
|
|
except IOError as msg:
|
2014-11-19 23:30:47 -06:00
|
|
|
print("%s: I/O Error: %s" % (file, str(msg)), file=sys.stderr)
|
2011-06-21 21:18:49 +00: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-19 23:30:47 -06:00
|
|
|
print('%s =>' % path, end=' ')
|
2011-06-21 21:18:49 +00:00
|
|
|
if not is_dry_run:
|
|
|
|
f = open(path, "wb")
|
|
|
|
try:
|
|
|
|
f.writelines(fixed_lines)
|
|
|
|
finally:
|
|
|
|
f.close()
|
|
|
|
if verbose:
|
2014-11-19 23:30:47 -06:00
|
|
|
print(is_dry_run and ' NEED FIX' or ' FIXED')
|
2011-06-21 21:18:49 +00:00
|
|
|
return True
|
|
|
|
##
|
|
|
|
##
|
|
|
|
##
|
2015-01-24 15:29:52 -06:00
|
|
|
##def _do_fix(is_dry_run = True):
|
2011-06-21 21:18:49 +00:00
|
|
|
## from waftools import antglob
|
2015-01-24 15:29:52 -06:00
|
|
|
## python_sources = antglob.glob('.',
|
2011-06-21 21:18:49 +00:00
|
|
|
## includes = '**/*.py **/wscript **/wscript_build',
|
|
|
|
## excludes = antglob.default_excludes + './waf.py',
|
2015-01-24 15:29:52 -06:00
|
|
|
## prune_dirs = antglob.prune_dirs + 'waf-* ./build')
|
2011-06-21 21:18:49 +00:00
|
|
|
## for path in python_sources:
|
2015-01-24 15:29:52 -06:00
|
|
|
## _fix_python_source(path, is_dry_run)
|
2011-06-21 21:18:49 +00:00
|
|
|
##
|
2015-01-24 15:29:52 -06:00
|
|
|
## cpp_sources = antglob.glob('.',
|
2011-06-21 21:18:49 +00:00
|
|
|
## includes = '**/*.cpp **/*.h **/*.inl',
|
2015-01-24 15:29:52 -06:00
|
|
|
## prune_dirs = antglob.prune_dirs + 'waf-* ./build')
|
2011-06-21 21:18:49 +00:00
|
|
|
## for path in cpp_sources:
|
2015-01-24 15:29:52 -06:00
|
|
|
## _fix_source_eol(path, is_dry_run)
|
2011-06-21 21:18:49 +00:00
|
|
|
##
|
|
|
|
##
|
|
|
|
##def dry_fix(context):
|
2015-01-24 15:29:52 -06:00
|
|
|
## _do_fix(is_dry_run = True)
|
2011-06-21 21:18:49 +00:00
|
|
|
##
|
|
|
|
##def fix(context):
|
2015-01-24 15:29:52 -06:00
|
|
|
## _do_fix(is_dry_run = False)
|
2011-06-21 21:18:49 +00: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()
|