aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/cat.py
blob: 875050cac67a41b949512e4c5899e1b0a7bbf421 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env python
import sys
from shutil import copyfileobj as copy
import os.path


PY3 = sys.version_info[0] == 3


if __name__ == '__main__':
    for filename in sys.argv[1:] or ["-"]:
        if filename == "-":
            copy(sys.stdin, sys.stdout)
        else:
            if os.path.exists(filename):
                with open(filename, 'r' if PY3 else 'rb') as file:
                    copy(file, sys.stdout)
            else:
                sys.stderr.write('cat.py: {0}: No such file or directory\n'.format(filename))