#!/usr/bin/env cobra """ le.cobra "line endings" - Report the line endings of text files as 'dos', 'unix', 'oldmac', 'both' or '?'. Skips binary files and reports files with unknown extensions. Also, can convert to dos or unix line endings. This is a console/command-line utility. Run with -h for usage help. Notes * The program looks at the extension of a file to determine if it is text or binary. While this is less technically accurate than examining file contents and also requires the extension lists to be occasionally augmented, it is very efficient--many files do not have to be opened. Future * Permissions are lost when a file is modified because a new file is created and then moved in place of the existing after it is deleted. """ use System.Text.RegularExpressions enum Action None ToUnix ToDos class LineEndings var _excludeNamesSpec = '.svn _svn .hg .git .bzr' var _binExtensionsSpec = 'dll exe pdb mdb snk ' + _ 'pyc pyo ' + _ 'gif ico jpg jpeg png tif tiff ' + _ 'doc docx ppt pptx xls xlsx ' + _ 'gz tar tgz zip ' + _ 'pdf ' + _ 'ds_store' var _textExtensionsSpec = _ 'bash bat c cmd cobra cobratext cobraproj config cpp cs css cxx ' + _ 'dif diff h htaccess htm html java js kv m ' + _ 'patch py rb sh shtml sln sql svg targets text txt xhtml xaml xml' var _excludeNamesCache = List() var _binExtensionsCache = List() var _textExtensionsCache = List() var _action as Action var _crLfRegEx = Regex(r'\r\n') # dos / windows var _notCrLfRegEx = Regex(r'[^\r]\n') # unix / mac / linux / etc var _crRegEx = Regex(r'\r') # old mac var _exts = Set() get excludeNames as IList if not _excludeNamesCache.count, _excludeNamesCache = _excludeNamesSpec.split.toList return _excludeNamesCache get binExtensions as IList if not _binExtensionsCache.count, _binExtensionsCache = _binExtensionsSpec.split.toList return _binExtensionsCache get textExtensions as IList if not _textExtensionsCache.count, _textExtensionsCache = _textExtensionsSpec.split.toList return _textExtensionsCache def main is shared LineEndings().run(CobraCore.commandLineArgs) def printHelp print 'le