MCPcopy Create free account
hub / github.com/battlecode/battlecode-2018 / dos2unix

Function dos2unix

battlecode-manager/player_abstract.py:28–47  ·  view source on GitHub ↗

Converts all .py and .sh files in the given directory (recursively) to use unix line endings

(directory)

Source from the content-addressed store, hash-verified

26
27
28def 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
50class AbstractPlayer:

Callers 1

__init__Method · 0.85

Calls 2

readMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected