forked from vanepp/FritzingCheckPart
-
Notifications
You must be signed in to change notification settings - Fork 4
/
PP.py
executable file
·107 lines (62 loc) · 2.46 KB
/
PP.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
# A python xml pretty_print script written to pretty print svg files from
# Inkscape, but should work on pretty much any xml.
# Set Debug to 0 for normal operation (rename the input file and write the
# pretty printed output to the input file name.
#
# Set Debug to 1 to not rename the input file and send the output to the
# console rather than write it to the file, but no other debug messages.
# Set Debug to 2 for debug messages on entry and exit from subroutines and
# to not rename the input file iand write the output to the console rather
# than the file for debugging.
# Set Debug to 3 for very verbose debug messages.
import logging
import re
import sys
import os
import PPTools as PP
Debug = 0
Version = '0.0.2' # Version number of this file.
# Import os and sys to get file rename and the argv stuff, re for regex and
# logging to get logging support and the various svg routines from LxmlTools.
# Set up the requested debug level
if Debug == 3:
logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
elif Debug == 2:
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
else:
# Debug set to 0 or 1
logging.basicConfig(stream=sys.stderr, level=logging.WARNING)
# End of if Debug == 3:
# The logging level needs to be set before we import this library.
# Start of the main script
# Create an empty Errors, Warnings and Info (Warnings and Info not used) array
Errors = []
Warnings = []
Info = []
InFile = PP.ProcessArgs(sys.argv, Errors)
if len(InFile) > 0:
for File in InFile:
print('Process {0:s}\n'.format(str(File)))
Doc, Root = PP.ParseFile(File, Errors)
if Root != None:
# If we managed to parse the file, then set up to pretty print it
# as if it was a svg (to pretty print to the element level).
# As we don't have a path broken out of the file name, set it to
# nothing (Fritzing processing needs the path when using these
# routines).
FileType = 'SVG'
Path = ''
PP.OutputTree(Doc, Root, FileType, Path, File,
Errors, Warnings, Info, Debug)
# End of if Root != None:
# End of for Files in InFile:
# Print any error messages found.
PP.PrintErrors(Errors)
# End of if len(InFile) > 0:
# Set the return code depending on whether there were errors or not.
if len(Errors) > 0:
sys.exit(1)
else:
sys.exit(0)
# end of if len(Errors) > 0: