2018-12-29 19:14:41 +00:00
|
|
|
#! /usr/bin/python3
|
2010-07-09 19:02:04 +00:00
|
|
|
|
2015-03-11 19:54:28 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2010-07-09 19:02:04 +00:00
|
|
|
import sys
|
|
|
|
from getopt import getopt
|
|
|
|
|
|
|
|
usage = '''
|
|
|
|
python cat.py -o OUTFILE FILE1 FILE2 .... FILEn
|
|
|
|
|
|
|
|
Replacement for:
|
|
|
|
cat FILE1 FILE2 ... .FILEn > OUTFILE
|
|
|
|
If the -o argument is not given, writes to stdout.
|
|
|
|
'''
|
|
|
|
|
|
|
|
outfile = ""
|
|
|
|
|
|
|
|
(options, args) = getopt(sys.argv[1:], "ho:")
|
|
|
|
for (opt, param) in options:
|
|
|
|
if opt == "-o":
|
|
|
|
outfile = param
|
|
|
|
elif opt == "-h":
|
2015-03-11 19:54:28 +00:00
|
|
|
print(usage)
|
2010-07-09 19:02:04 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
out = sys.stdout
|
|
|
|
if outfile:
|
2016-05-10 05:03:54 +00:00
|
|
|
# always write unix line endings, even on windows
|
|
|
|
out = open(outfile, "wb")
|
2010-07-09 19:02:04 +00:00
|
|
|
|
|
|
|
for f in args:
|
2020-03-19 22:22:16 +00:00
|
|
|
if sys.version_info[0] < 3:
|
|
|
|
# accept both windows and unix line endings, since it can
|
|
|
|
# happen that we are on unix, but the file has been written on
|
|
|
|
# windows or vice versa.
|
|
|
|
mode = "rU"
|
|
|
|
else:
|
|
|
|
# The default behavior of Python 3 is to enable universal
|
|
|
|
# newlines in text mode. Adding "U" gives a deprecation
|
|
|
|
# warning.
|
|
|
|
mode = "r"
|
|
|
|
fil = open(f, mode)
|
2010-07-09 19:02:04 +00:00
|
|
|
for l in fil:
|
2016-05-10 05:03:54 +00:00
|
|
|
# this does always write unix line endings since the file has
|
|
|
|
# been opened in binary mode. This is needed since both gettext
|
|
|
|
# and our .pot file manipulation scripts assume unix line ends.
|
2010-07-09 19:02:04 +00:00
|
|
|
out.write(l)
|
|
|
|
fil.close()
|
|
|
|
|
|
|
|
if outfile:
|
|
|
|
out.close()
|