def eeschema_export_schematic(schematic, output_dir, file_format="svg", all_pages=False): screencast_output_file = os.path.join(output_dir, 'export_schematic_screencast.ogv') file_format = file_format.lower() output_file = os.path.join( output_dir, os.path.splitext(os.path.basename(schematic))[0] + '.' + file_format) if os.path.exists(output_file): logging.info('Removing old file') os.remove(output_file) set_default_plot_option() os.path.basename('/root/dir/sub/file.ext') with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24): with PopenContext(['eeschema', schematic], close_fds=True) as eeschema_proc: eeschema_plot_schematic(output_dir, file_format, all_pages) file_util.wait_for_file_created_by_process(eeschema_proc.pid, output_file) eeschema_proc.terminate() return output_file
def run_drc(pcb_file, output_dir, record=True): file_util.mkdir_p(output_dir) recording_file = os.path.join(output_dir, 'run_drc_screencast.ogv') drc_output_file = os.path.join(os.path.abspath(output_dir), 'drc_result.rpt') xvfb_kwargs = { 'width': 800, 'height': 600, 'colordepth': 24, } with recorded_xvfb(recording_file, **xvfb_kwargs) if record else Xvfb(**xvfb_kwargs): with PopenContext(['pcbnew', pcb_file], close_fds=True) as pcbnew_proc: clipboard_store(drc_output_file) window = wait_for_window('pcbnew', 'Pcbnew', 10, False) logger.info('Focus main pcbnew window') wait_for_window('pcbnew', 'Pcbnew') # Needed to rebuild the menu, making sure it is actually built xdotool(['windowsize', '--sync', window, '750', '600']) wait_for_window('pcbnew', 'Pcbnew') logger.info('Open Inspect->DRC') xdotool(['key', 'alt+i', 'd']) logger.info('Focus DRC modal window') wait_for_window('DRC modal window', 'DRC Control') xdotool(['key', 'Tab', 'Tab', 'Tab', # Refill zones on DRC gets saved in /root/.config/kicad/pcbnew as RefillZonesBeforeDrc 'key', 'Tab', 'space', # Enable reporting all errors for tracks 'Tab', 'Tab', 'Tab', 'space', 'Tab' ]) logger.info('Pasting output dir') xdotool(['key', 'ctrl+v']) xdotool(['key', 'Return']) wait_for_window('Report completed dialog', 'Disk File Report Completed') xdotool(['key', 'Return']) pcbnew_proc.terminate() return drc_output_file
def eeschema_run_erc(schematic, output_dir, warning_as_error, generate_junit_xml=False): os.environ['EDITOR'] = '/bin/cat' screencast_output_file = os.path.join(output_dir, 'run_erc_schematic_screencast.ogv') with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24): with PopenContext(['eeschema', schematic], close_fds=True) as eeschema_proc: dismiss_configure_global_symbol_upgrade() dismiss_library_warning() dismiss_heirachical_sheet_not_found_warning() # dismiss_newer_version() logger.info(xwininfo(['-root', '-tree'])) logger.info('Focus main eeschema window') wait_for_window('eeschema', '\[') logger.info('Inspect->Electrical Rules Checker') xdotool(['key', 'alt+i', 'c']) # Do this now since we have to wait for KiCad anyway clipboard_store(output_dir) logger.info('Focus Electrical Rules Checker window') wait_for_window('Electrical Rules Checker', 'Electrical Rules Checker') xdotool(['key', 'Tab', 'Tab', 'Tab', 'Tab', 'space', 'Return']) wait_for_window('ERC File save dialog', 'ERC File') xdotool(['key', 'Home']) logger.info('Pasting output dir') xdotool(['key', 'ctrl+v']) logger.info('Copy full file path') xdotool(['key', 'ctrl+a', 'ctrl+c']) erc_file = clipboard_retrieve() if os.path.exists(erc_file): os.remove(erc_file) logger.info('Run ERC') xdotool(['key', 'Return']) logger.info('Wait for ERC file creation') file_util.wait_for_file_created_by_process(eeschema_proc.pid, erc_file) eeschema_proc.terminate() return eeschema_parse_erc(erc_file, warning_as_error, generate_junit_xml)
def run_interactive_bom(pcb_file, output_dir, record=True): file_util.mkdir_p(output_dir) recording_file = os.path.join(output_dir, 'run_interactive_bom.ogv') drc_output_file = os.path.abspath(output_dir) xvfb_kwargs = { 'width': 1024, 'height': 786, 'colordepth': 24, } with recorded_xvfb(recording_file, **xvfb_kwargs) if record else Xvfb( **xvfb_kwargs): with PopenContext(['pcbnew', pcb_file], close_fds=True) as pcbnew_proc: clipboard_store(drc_output_file) dismiss_configure_global_footprint_upgrade() dismiss_enable_graphics_acceleration() #logger.info(xwininfo(['-root', '-tree'])) window = wait_for_window('pcbnew', 'Pcbnew', 10, False) logger.info('Focus main pcbnew window') wait_for_window('pcbnew', 'Pcbnew') # Needed to rebuild the menu, making sure it is actually built xdotool(['windowsize', '--sync', window, '1024', '786']) wait_for_window('pcbnew', 'Pcbnew') logger.info('Open Inspect->DRC') xdotool(['key', 'alt+t', 'Up', 'Right', 'Up', 'KP_Enter']) logger.info('Focus DRC modal window') wait_for_window('DRC modal window', 'InteractiveHtmlBom v2.3') xdotool( ['search', '--name', 'InteractiveHtmlBom v2.3', 'windowfocus']) logger.info('first..') logger.info('Pasting output dir') xdotool(['key', 'ctrl+v']) logger.info('return + sleep') xdotool(['key', 'Return']) time.sleep(10) pcbnew_proc.terminate() return drc_output_file
def export_bom(schematic_file, output_dir, screencast_dir): if screencast_dir: screencast_output_file = os.path.join(screencast_dir, 'export_bom_screencast.ogv') with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24): with PopenContext(['eeschema', schematic_file], close_fds=True) as eeschema_proc: eeschema_export_bom(output_dir, eeschema_proc) else: with Xvfb(width=800, height=600, colordepth=24): with PopenContext(['eeschema', schematic_file], close_fds=True) as eeschema_proc: eeschema_export_bom(output_dir, eeschema_proc)
def export_bom(): schematic_file = os.path.join(electronics_root, 'splitflap.sch') output_dir = os.path.join(electronics_root, 'build') file_util.mkdir_p(output_dir) screencast_output_file = os.path.join(output_dir, 'export_bom_screencast.ogv') with recorded_xvfb(screencast_output_file, width=800, height=600, colordepth=24): with PopenContext(['eeschema-nightly', schematic_file], close_fds=True) as eeschema_proc: eeschema_export_bom(output_dir) eeschema_proc.terminate() logger.info('Convert component XML to useful BOM CSV file...') subprocess.check_call([ 'python', '-u', os.path.join(electronics_root, 'bom', 'generate_bom_csv.py'), os.path.join(electronics_root, 'splitflap.xml'), os.path.join(output_dir, 'bom.csv'), ])
def run_drc(pcb_file, output_dir, record=True): file_util.mkdir_p(output_dir) recording_file = os.path.join(output_dir, 'run_drc_screencast.ogv') drc_output_file = os.path.join(os.path.abspath(output_dir), 'drc_result.rpt') xvfb_kwargs = { 'width': 1024, 'height': 786, 'colordepth': 24, } with recorded_xvfb(recording_file, **xvfb_kwargs) if record else Xvfb( **xvfb_kwargs): with PopenContext(['pcbnew', pcb_file], close_fds=True) as pcbnew_proc: clipboard_store(drc_output_file) dismiss_configure_global_footprint_upgrade() dismiss_enable_graphics_acceleration() #logger.info(xwininfo(['-root', '-tree'])) window = wait_for_window('pcbnew', 'Pcbnew', 10, False) logger.info('Focus main pcbnew window') wait_for_window('pcbnew', 'Pcbnew') # Needed to rebuild the menu, making sure it is actually built xdotool(['windowsize', '--sync', window, '1024', '786']) wait_for_window('pcbnew', 'Pcbnew') logger.info('Open Inspect->DRC') xdotool(['key', 'alt+i', 'Up', 'KP_Enter']) logger.info('Focus DRC modal window') wait_for_window('DRC modal window', 'DRC Control') xdotool(['search', '--name', 'DRC Control', 'windowfocus']) logger.info('first..') xdotool([ 'key', 'Tab', 'Tab', 'Tab', 'Tab', 'space', 'Tab', 'space', 'Tab', 'space', 'Tab', 'space', ]) logger.info('Pasting output dir') xdotool(['key', 'ctrl+v']) logger.info('return + sleep') xdotool(['key', 'Return']) #time.sleep(1) wait_for_window('Zone fills are out-of-date. Refill?', 'Confirmation', 10, True, False) xdotool(['key', 'Down', 'KP_Enter']) wait_for_window('Report completed dialog', 'Disk File Report Completed', 10, True, False) xdotool(['key', 'Return']) pcbnew_proc.terminate() return drc_output_file
def run_export_step(pcb_file, output_dir, record=True): file_util.mkdir_p(output_dir) recording_file = os.path.join(output_dir, 'run_export_step.ogv') board = ''.join(map(str, pcb_file.split('.')[0:-1])) step_file = os.path.join(os.path.abspath(output_dir), board + ".step") xvfb_kwargs = { 'width': 800, 'height': 600, 'colordepth': 24, } with recorded_xvfb(recording_file, **xvfb_kwargs) if record else Xvfb( **xvfb_kwargs): with PopenContext(['pcbnew', pcb_file], close_fds=True) as pcbnew_proc: print(step_file) clipboard_store(step_file.encode()) window = wait_for_window('pcbnew', 'Pcbnew', 10, False) logger.info('Focus main pcbnew window') wait_for_window('pcbnew', 'Pcbnew') # Needed to rebuild the menu, making sure it is actually built xdotool(['windowsize', '--sync', window, '750', '600']) wait_for_window('pcbnew', 'Pcbnew') logger.info('Open File->Export->Step') xdotool([ 'key', 'alt+f', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Down', 'Right', 'Down', 'Down', 'Down', 'Down', 'Return' ]) logger.info('Focus Export STEP modal window') wait_for_window('Export STEP modal window', 'Export STEP') logger.info('Pasting output file') logger.info(step_file) xdotool(['key', 'ctrl+v']) xdotool([ 'key', 'Tab', 'Tab', 'Down', 'Down', 'Down', 'Down', # Board center origin 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Return' ]) try: wait_for_window('STEP Export override dialog', 'STEP Export') xdotool(['key', 'Return']) except: print("Timeout") logger.info('Close Export STEP modal window') xdotool(['key', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Return']) pcbnew_proc.terminate() return step_file