Mercurial > dottes
comparison abcfirstline.py @ 589:5db7e72d4219 build-default-240
Automated merge with ssh://hg.cryhavoc.org.uk/dottes
author | Jim Hague <jim.hague@acm.org> |
---|---|
date | Wed, 02 Nov 2016 00:21:30 +0000 |
parents | 1b79867b4f35 |
children |
comparison
equal
deleted
inserted
replaced
583:de2122c78ea0 | 589:5db7e72d4219 |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python3 |
2 # | 2 # |
3 # Write out a modified version of a .abc file with just the data | 3 # Write out a modified version of a .abc file with just the data |
4 # to print the first line of the music only. | 4 # to print the first line of the music only. |
5 # | 5 # |
6 | 6 |
7 import sys | 7 import sys |
8 | 8 |
9 def process(inf): | 9 def process(inf): |
10 continued = False | 10 continued = False |
11 print "X:1" | 11 print("X:1") |
12 for line in inf: | 12 for line in inf: |
13 line = line.strip() | 13 line = line.strip() |
14 # If it is empty or starts "%", ignore it. | 14 # If it is empty or starts "%", ignore it. |
15 if len(line) == 0 or line[0] == "%": | 15 if len(line) == 0 or line[0] == "%": |
16 continue | 16 continue |
17 | 17 |
18 # Is it a header line? I.e. does it start LETTER COLON? | 18 # Is it a header line? I.e. does it start LETTER (or +) COLON? |
19 # If so, output only ones we need. | 19 # If so, output only ones we need. |
20 start = line[:2] | 20 start = line[:2] |
21 if len(start) > 1 and start[1] == ":" and start[0].isalpha(): | 21 if len(start) > 1 and start[1] == ":" and (start[0].isalpha() or start[0] == '+'): |
22 if start[0] in ["M", "K", "L"]: | 22 if start[0] in ["M", "K", "L"]: |
23 print line | 23 print(line) |
24 # Output line. If it is a continuation, output at most one | 24 # Output line. If it is a continuation, output at most one |
25 # continuation. | 25 # continuation. |
26 else: | 26 else: |
27 print line | 27 print(line) |
28 if continued or line[-1] != "\\": | 28 if continued or line[-1] != "\\": |
29 break | 29 break |
30 else: | 30 else: |
31 continued = True | 31 continued = True |
32 | 32 |