-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexport_schematic.py
executable file
·106 lines (84 loc) · 3.12 KB
/
export_schematic.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
#!/usr/bin/env python
# Copyright 2015-2016 Scott Bezek and the splitflap contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import os
import subprocess
import sys
import time
from contextlib import contextmanager
repo_root = os.path.dirname(os.path.abspath(__file__))
project_root = os.getcwd()
sys.path.append(repo_root)
from util import file_util
from export_util import (
PopenContext,
xdotool,
wait_for_window,
recorded_xvfb,
)
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
def eeschema_plot_schematic(output_name, wait_init):
"""Send keystrokes for printing schematic
Keyword arguments:
output_name -- The output pdf file name
"""
# Give enough time to load the libraries
time.sleep(float(wait_init))
logger.info('Open File->Print')
xdotool(['key', 'alt+f'])
xdotool(['key', 'p'])
wait_for_window('print', 'Print')
logger.info('Set color output')
xdotool(['key', 'alt+b'])
logger.info('Open Print dialog')
xdotool(['key', 'Tab'])
xdotool(['key', 'Tab'])
xdotool(['key', 'Tab'])
xdotool(['key', 'Return'])
logger.info('Enter build output directory')
xdotool(['key', 'Tab'])
xdotool(['key', 'alt+n'])
xdotool(['type', output_name])
wait_for_window('print', 'Print')
logger.info('Print!')
xdotool(['key', 'alt+p'])
logger.info('Wait before shutdown')
time.sleep(10)
def export_schematic(prjfile, wait_init):
"""Print schematics to file in PDF format
Keyword arguments:
prjfile -- The project file name including relative path
from project_root WITHOUT extension.
"""
sch_file_path = os.path.dirname(prjfile)
sch_file_name = os.path.basename(prjfile)
schematic_file = os.path.join(project_root, prjfile+'.sch')
output_dir = os.path.join(project_root,'CI-BUILD/'+sch_file_name+'/SCH')
file_util.mkdir_p(output_dir)
#TODO: Remove when stable or add debug flag
screencast_output_file = os.path.join(output_dir, 'export_schematic_screencast.ogv')
schematic_output_pdf_file = os.path.join(output_dir, sch_file_name+'.pdf')
with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24):
with PopenContext(['eeschema', schematic_file], close_fds=True) as eeschema_proc:
eeschema_plot_schematic(schematic_output_pdf_file, wait_init)
eeschema_proc.terminate()
if __name__ == '__main__':
wait = 10
if len(sys.argv) < 2:
raise ValueError('Project file was not provided!')
elif len(sys.argv) > 2:
wait = sys.argv[2]
export_schematic(sys.argv[1], wait)