Mercurial > hg > Feedworm
annotate prettyprint.py @ 259:304917762618 default tip
implementation of feed updates
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Tue, 12 Mar 2019 02:41:22 +0100 |
parents | 7c719c4f5655 |
children |
rev | line source |
---|---|
217
bb3c851b18b1
add source file endcoding header
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
8
diff
changeset
|
1 # -*- coding: utf-8 -*- |
8
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
2 import sys |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
3 |
233
e34c53a3e407
fixes from eric's style check
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
217
diff
changeset
|
4 newlineAfter = ['{', '[', ','] |
246
7c719c4f5655
Fix all remaining code style bugs
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
233
diff
changeset
|
5 newlineBefore = ['}', ']'] |
8
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
6 |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
7 def prettyPrint(file): |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
8 indent = 0 |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
9 doIndent = False |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
10 printCommand = None |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
11 for line in file: |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
12 for char in line: |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
13 if char in newlineAfter: |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
14 if char is not ',': |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
15 indent = indent + 1 |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
16 doIndent = True |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
17 printCommand = p_nl |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
18 elif char in newlineBefore: |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
19 indent = indent - 1 |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
20 doIndent = True |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
21 printCommand = nl_p |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
22 else: |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
23 printCommand = p |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
24 doIndent = False |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
25 |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
26 printCommand(char) |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
27 if doIndent: |
246
7c719c4f5655
Fix all remaining code style bugs
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
233
diff
changeset
|
28 for x in range(indent): |
8
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
29 sys.stdout.write(" ") |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
30 doIndent = False |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
31 |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
32 def p(char): |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
33 sys.stdout.write(char) |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
34 |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
35 def p_nl(char): |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
36 sys.stdout.write(char) |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
37 sys.stdout.write("\n") |
246
7c719c4f5655
Fix all remaining code style bugs
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
233
diff
changeset
|
38 |
8
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
39 def nl_p(char): |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
40 sys.stdout.write("\n") |
233
e34c53a3e407
fixes from eric's style check
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
217
diff
changeset
|
41 sys.stdout.write(char) |
8
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
42 |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
43 if __name__ == "__main__": |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
44 if len(sys.argv) < 2: |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
45 print("usage: %s <file>" % (sys.argv[0])) |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
46 sys.exit(1) |
246
7c719c4f5655
Fix all remaining code style bugs
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
233
diff
changeset
|
47 |
8
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
48 filename = sys.argv[1] |
2da2b691345d
unfinished pretty printer for feed's plain text representation
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
49 with open(filename) as file: |
217
bb3c851b18b1
add source file endcoding header
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
8
diff
changeset
|
50 prettyPrint(file) |