def dismiss_heirachical_sheet_not_found_warning():
    try:
        logger.info('dismiss_heirachical_sheet_not_found_warning')
        wait_for_window('schematic ', 'Error', 3)

        xdotool(['key', 'Return'])
    except RuntimeError:
        pass
def dismiss_newer_version():
    try:
        logger.info('Dismiss schematic version notification')
        wait_for_window('Newer schematic version notification', 'Info', 3)

        xdotool(['key', 'Return'])
    except RuntimeError:
        pass
def dismiss_configure_global_footprint_upgrade():
    try:
        nf_title = 'Configure Global Footprint Library'
        wait_for_window(nf_title, nf_title, 3)

        logger.info('Dismiss Configure Global Footprint Library Table')
        xdotool(['search', '--name', nf_title, 'windowfocus'])
        xdotool(['key', 'Down', 'Return'])
    except RuntimeError:
        pass
def dismiss_enable_graphics_acceleration():
    try:
        nf_title = 'Enable Graphics Acceleration'
        wait_for_window(nf_title, nf_title, 3)

        logger.info('Enable Graphics Acceleration')
        xdotool(['search', '--name', nf_title, 'windowfocus'])
        xdotool(['key', 'Escape'])
    except RuntimeError:
        pass
Example #5
0
def dismiss_newer_version():
    # The "Not Found" window pops up if libraries required by the schematic have
    # not been found. This can be ignored as all symbols are placed inside the
    # *-cache.lib file:
    try:
        logger.info('Dismiss schematic version notification')
        wait_for_window('Newer schematic version notification', 'Info', 3)

        xdotool(['key', 'Return'])
    except RuntimeError:
        pass
Example #6
0
def dismiss_remap_helper():
    # The "Remap Symbols" windows pop up if the uses the project symbol library 
    # the older list look up method for loading library symbols.
    # This can be ignored as we're just trying to output data and don't 
    # want to mess with the actual project.
    try:
        logger.info('Dismiss schematic symbol remapping')
        wait_for_window('Remap Symbols', 'Remap', 3)

        xdotool(['key', 'Escape'])
    except RuntimeError:
        pass
def dismiss_library_warning():
    # The "Not Found" window pops up if libraries required by the schematic have
    # not been found. This can be ignored as all symbols are placed inside the
    # *-cache.lib file:
    try:
        nf_title = 'Project Rescue Helper'
        wait_for_window(nf_title, nf_title, 3)

        logger.info('Dismiss eeschema library warning window')
        xdotool(['search', '--name', nf_title, 'windowfocus'])
        xdotool(['key', 'Return'])
    except RuntimeError:
        pass
def dismiss_configure_global_symbol_upgrade():
    # The "Not Found" window pops up if libraries required by the schematic have
    # not been found. This can be ignored as all symbols are placed inside the
    # *-cache.lib file:
    try:
        nf_title = 'Configure Global Symbol Library Table'
        wait_for_window(nf_title, nf_title, 3)

        logger.info('Dismiss Configure Global Symbol Library Table')
        xdotool(['search', '--name', nf_title, 'windowfocus'])
        xdotool(['key', 'Down', 'Return'])
    except RuntimeError:
        pass
Example #9
0
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
Example #10
0
def dismiss_library_error():
    # The "Error" modal pops up if libraries required by the schematic have
    # not been found. This can be ignored as all symbols are placed inside the
    # *-cache.lib file:
    # There -should- be a way to disable it, but I haven't the magic to drop in the config file yet
    try:
        nf_title = 'Error'
        wait_for_window(nf_title, nf_title, 3)

        logger.info('Dismiss eeschema library warning modal')
        xdotool(['search', '--onlyvisible', '--name', nf_title, 'windowfocus'])
        xdotool(['key', 'Escape'])
    except RuntimeError:
        pass
def eeschema_export_bom(output_directory):
    wait_for_window('eeschema', '\[')

    logger.info('Focus main eeschema window')
    xdotool(['search', '--name', '\[', 'windowfocus'])

    logger.info('Open Tools->Generate Bill Of Materials')
    xdotool(['key', 'alt+t'])
    xdotool(['key', 'm'])

    logger.info('Run generate')
    wait_for_window('plot', 'Bill of Material')
    xdotool(['search', '--name', 'Bill of Material', 'windowfocus'])
    xdotool(['key', 'Return'])

    logger.info('Wait before shutdown')
    time.sleep(2)
def eeschema_plot_schematic(output_directory, file_format, all_pages):
    if file_format not in ('pdf', 'svg'):
        raise ValueError("file_format should be 'pdf' or 'svg'")

    clipboard_store(output_dir)
    dismiss_configure_global_symbol_upgrade()
    dismiss_configure_global_footprint_upgrade()

    dismiss_newer_version()
    dismiss_library_warning()
    dismiss_heirachical_sheet_not_found_warning()
    dismiss_library_warning()
    # dismiss_newer_version()

    wait_for_window('eeschema', '\[')

    logger.info('Focus main eeschema window')
    xdotool(['search', '--name', '\[', 'windowfocus'])

    logger.info('Open File->Plot')
    xdotool(['key', 'alt+f'])
    xdotool(['key', 'Up', 'Up', 'KP_Enter'])

    wait_for_window('plot', 'Plot')

    logger.info('Paste output directory')
    xdotool(['key', 'ctrl+v'])

    command_list = ['key', 'Tab', 'Tab', 'space']
    if file_format == 'pdf':
        logger.info('Select PDF plot format')
        for i in range(3):
            command_list.insert(3, 'Up')
    else:
        logger.info('Select SVG plot format')
        for i in range(2):
            command_list.insert(3, 'Up')

    if not all_pages:  # all pages is default option
        command_list.extend(['Tab', 'Tab', 'Tab', 'Tab', 'Tab'])
    xdotool(command_list)

    logger.info('Plot')
    xdotool(['key', 'Return'])
def eeschema_plot_schematic(output_directory, file_format, all_pages,
                            default_directory):
    if file_format not in ('pdf', 'svg'):
        raise ValueError("file_format should be 'pdf' or 'svg'")

    clipboard_store(output_dir)

    dismiss_library_warning()
    # dismiss_newer_version()

    wait_for_window('eeschema', '\[')

    logger.info('Focus main eeschema window')
    xdotool(['search', '--name', '\[', 'windowfocus'])

    logger.info('Open File->Plot')
    xdotool(['key', 'alt+f', 'l'])

    wait_for_window('plot', 'Plot')

    # Kicad defaults to project directory when given no output directory
    if not default_directory:
        logger.info('Paste output directory')
        xdotool(['key', 'ctrl+v'])

    command_list = ['key', 'Tab', 'Tab', 'space']
    if file_format == 'pdf':
        logger.info('Select PDF plot format')
        for i in range(3):
            command_list.insert(3, 'Up')
    else:
        logger.info('Select SVG plot format')
        for i in range(2):
            command_list.insert(3, 'Up')

    if not all_pages:  # all pages is default option
        command_list.extend(['Tab', 'Tab', 'Tab', 'Tab', 'Tab'])
    xdotool(command_list)

    logger.info('Plot')
    xdotool(['key', 'Return'])
Example #14
0
def eeschema_run_erc(schematic, output_dir, warning_as_error, screencast_dir=None):
    os.environ['EDITOR'] = '/bin/cat'

    if screencast_dir:
    	screencast_output_file = os.path.join(screencast_dir, 'run_erc_schematic_screencast.ogv')
    # TODO: refactor this to make it easier to toggle the screencast
    with Xvfb(width=800, height=600, colordepth=24):
        with PopenContext(['eeschema', schematic], close_fds=True) as eeschema_proc:
            dismiss_newer_version()
            dismiss_remap_helper()
            dismiss_library_warning()
    	    dismiss_library_error()

            logger.info('Focus main eeschema window')
            wait_for_window('eeschema', '.sch')

            logger.info('Open Tools->Electrical Rules Checker')
            xdotool(['key',
                'alt+t',
                '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)
Example #15
0
def eeschema_plot_schematic(output_dir, file_format, all_pages):
    if file_format not in ('pdf', 'svg'):
        raise ValueError("file_format should be 'pdf' or 'svg'")

    clipboard_store(output_dir)

    dismiss_newer_version()
    dismiss_remap_helper();
    dismiss_library_warning()
    dismiss_library_error()

    wait_for_window('eeschema', '.sch')

    logger.info('Focus main eeschema window')
    xdotool(['search', '--onlyvisible', '--name', '.sch', 'windowfocus'])

    logger.info('Open File->pLot')
    xdotool(['key', 'alt+f',
        'l'
    ])

    wait_for_window('plot', 'Plot')

    logger.info('Paste output directory')
    xdotool(['key', 'ctrl+v'])

    logger.info('Move to the "plot" button')

    command_list = ['key',
        'Tab',
        'Tab',
        'Tab',
        'Tab',
        'Tab',
        'Tab',
        'Tab',
        'Tab',
        'Tab',
        'Tab',
        'Tab',
        'Tab',
        'Tab',
        'Tab',
    ]

    if not all_pages:   # all pages is default option
        command_list.extend(['Tab'])
    xdotool(command_list)

    logger.info('Plot')
    xdotool(['key', 'Return'])
    logger.info('Quitting eeschema')
    xdotool(['key', 'Escape'])
    wait_for_window('eeschema', '.sch')
    logger.info('Focus main eeschema window')
    xdotool(['search', '--onlyvisible', '--name', '.sch', 'windowfocus'])
    xdotool(['key', 'Ctrl+q'])
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 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)
Example #18
0
def eeschema_export_bom(output_dir, eeschema_proc):
    bom_file = output_dir + "bom.csv"
    clipboard_store('xsltproc -o "' + bom_file +
                    '" "/usr/share/kicad/plugins/bom2grouped_csv.xsl" "%I"')

    dismiss_newer_version()
    dismiss_remap_helper()
    dismiss_library_warning()
    dismiss_library_error()

    wait_for_window('eeschema', '.sch')

    logger.info('Focus main eeschema window')
    xdotool(['search', '--onlyvisible', '--name', '.sch', 'windowfocus'])

    logger.info('Open Tools->Generate Bill Of Materials')
    xdotool(['key', 'alt+t'])
    xdotool(['key', 'm'])

    logger.info('Run generate')
    wait_for_window('plot', 'Bill of Material')
    xdotool(['search', '--name', 'Bill of Material', 'windowfocus'])
    logger.info("Select commandline window")
    xdotool(['key', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab', 'Tab'])

    logger.info('Paste xslt command')
    xdotool(['key', 'ctrl+v'])
    xdotool(['key', 'Tab'])
    xdotool(['key', 'space'])
    logger.info("Waiting for bom file")
    # this might take a moment. Wait for the bom.csv to appear
    file_util.wait_for_file_created_by_process(eeschema_proc.pid, bom_file)
    # Seems to be a bit of a delay here
    sleep(2)
    logger.info('Closing BOM dialog')
    xdotool(['key', 'Tab'])
    xdotool(['key', 'Tab'])
    xdotool(['key', 'Escape'])
    logger.info('Quitting eeschema')
    wait_for_window('eeschema', '.sch')
    logger.info('Focus main eeschema window')
    xdotool(['search', '--onlyvisible', '--name', '.sch', 'windowfocus'])
    logger.info('Pressing Control+q')
    xdotool(['key', 'Ctrl+q'])
    logger.info('Done!')
Example #19
0
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
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