Converts all .py and .sh files in the given directory (recursively) to use unix line endings
(directory)
| 26 | |
| 27 | |
| 28 | def dos2unix(directory): |
| 29 | ''' Converts all .py and .sh files in the given directory (recursively) to use unix line endings ''' |
| 30 | pathlist = list(Path(directory).glob("**/*.py")) |
| 31 | pathlist += list(Path(directory).glob("**/*.sh")) |
| 32 | |
| 33 | for path in pathlist: |
| 34 | try: |
| 35 | with open(str(path), 'r') as f: |
| 36 | x = f.read() |
| 37 | except UnicodeDecodeError as e: |
| 38 | try: |
| 39 | print("Trying Latin encoding...") |
| 40 | with open(str(path), 'r', encoding='ISO-8859-1') as f: |
| 41 | x = f.read() |
| 42 | except Exception as e2: |
| 43 | print(e2) |
| 44 | x = 'echo "Unable to read file (please encode as unicode)."' |
| 45 | |
| 46 | with open(str(path), 'w') as f: |
| 47 | f.write(x.replace('\r\n', '\n')) |
| 48 | |
| 49 | |
| 50 | class AbstractPlayer: |