]> arthur.barton.de Git - bup.git/blob - cmd-newliner.py
Move python library files to lib/bup/
[bup.git] / cmd-newliner.py
1 #!/usr/bin/env python
2 import sys, os, re
3 from bup import options
4
5 optspec = """
6 bup newliner
7 """
8 o = options.Options('bup newliner', optspec)
9 (opt, flags, extra) = o.parse(sys.argv[1:])
10
11 if extra:
12     o.fatal("no arguments expected")
13
14 r = re.compile(r'([\r\n])')
15 lastlen = 0
16 all = ''
17 while 1:
18     l = r.split(all, 1)
19     if len(l) <= 1:
20         try:
21             b = os.read(sys.stdin.fileno(), 4096)
22         except KeyboardInterrupt:
23             break
24         if not b:
25             break
26         all += b
27     else:
28         assert(len(l) == 3)
29         (line, splitchar, all) = l
30         #splitchar = '\n'
31         sys.stdout.write('%-*s%s' % (lastlen, line, splitchar))
32         if splitchar == '\r':
33             lastlen = len(line)
34         else:
35             lastlen = 0
36         sys.stdout.flush()
37
38 if lastlen or all:
39     sys.stdout.write('%-*s\n' % (lastlen, all))