コード例 #1
0
def main(argv):
    parser = _stbt.core.argparser()
    parser.prog = 'stbt record'
    parser.description = 'Create an stb-tester test script'
    parser.add_argument(
        '--control-recorder',
        default=stbt.get_config('record', 'control_recorder'),
        help='The source of remote control keypresses (default: %(default)s)')
    parser.add_argument(
        '-o',
        '--output-file',
        default=stbt.get_config('record', 'output_file'),
        help='The filename of the generated script (default: %(default)s)')
    args = parser.parse_args(argv[1:])
    stbt.debug("Arguments:\n" +
               "\n".join(["%s: %s" % (k, v)
                          for k, v in args.__dict__.items()]))

    try:
        script = open(args.output_file, 'w')
    except IOError as e:
        e.strerror = "Failed to write to output-file '%s': %s" % (
            args.output_file, e.strerror)
        raise

    with _stbt.core.new_device_under_test_from_config(args) as dut:
        record(dut, args.control_recorder, script)
コード例 #2
0
ファイル: stbt_record.py プロジェクト: stb-tester/stb-tester
def main(argv):
    parser = _stbt.core.argparser()
    parser.prog = 'stbt record'
    parser.description = 'Create an stb-tester test script'
    parser.add_argument(
        '--control-recorder',
        default=stbt.get_config('record', 'control_recorder'),
        help='The source of remote control keypresses (default: %(default)s)')
    parser.add_argument(
        '-o', '--output-file',
        default=stbt.get_config('record', 'output_file'),
        help='The filename of the generated script (default: %(default)s)')
    args = parser.parse_args(argv[1:])
    stbt.debug("Arguments:\n" + "\n".join([
        "%s: %s" % (k, v) for k, v in args.__dict__.items()]))

    try:
        script = open(args.output_file, 'w')
    except IOError as e:
        e.strerror = "Failed to write to output-file '%s': %s" % (
            args.output_file, e.strerror)
        raise

    with _stbt.core.new_device_under_test_from_config(args) as dut:
        record(dut, args.control_recorder, script)
コード例 #3
0
def test_that_set_config_creates_directories_if_required():
    with _directory_sandbox() as d:
        os.environ['XDG_CONFIG_HOME'] = d + '/.config'
        if 'STBT_CONFIG_FILE' in os.environ:
            del os.environ['STBT_CONFIG_FILE']
        _set_config('global', 'test', 'hello2')
        assert os.path.isfile(d + '/.config/stbt/stbt.conf')
        _config_init(force=True)
        assert get_config('global', 'test') == 'hello2'
コード例 #4
0
def test_that_set_config_creates_directories_if_required():
    with _directory_sandbox() as d:
        os.environ['XDG_CONFIG_HOME'] = d + '/.config'
        if 'STBT_CONFIG_FILE' in os.environ:
            del os.environ['STBT_CONFIG_FILE']
        _set_config('global', 'test', 'hello2')
        assert os.path.isfile(d + '/.config/stbt/stbt.conf')
        _config_init(force=True)
        assert get_config('global', 'test') == 'hello2'
コード例 #5
0
def test_youtube_keyboard():
    """Showcases the keyboard navigation APIs used in `youtube.Search`

    Precondition: Already at the YouTube Search page.
    """
    text = stbt.get_config("result.tags", "search_text", "Peppa Pig")

    page = Search()
    assert page, "Not at the YouTube Search page"
    page = page.clear()
    page = page.enter_text(text)
コード例 #6
0
def setup(source_pipeline):
    """If we haven't got a configured camera offer a list of cameras you might
    want to use.  In the future it could be useful to allow the user to select
    one from the list interactively."""
    if (source_pipeline == ''
            or stbt.get_config('global', 'v4l2_device', '') == ''):
        sys.stderr.write(
            'No camera configured in stbt.conf please add parameters '
            '"v4l2_device" and "source_pipeline" to section [global] of '
            'stbt.conf.\n\n')
        cameras = list(list_cameras())
        if len(cameras) == 0:
            sys.stderr.write("No Cameras Detected\n\n")
        else:
            sys.stderr.write("Detected cameras:\n\n")
        for n, (name, dev_file, source_pipeline) in enumerate(cameras):
            sys.stderr.write("    %i. %s\n"
                             "\n"
                             "        v4l2_device = %s\n"
                             "        source_pipeline = %s\n\n" %
                             (n, name, dev_file, source_pipeline))
        return None
    return stbt.get_config('global', 'v4l2_device')
コード例 #7
0
def main(argv):
    args = parse_args(argv)

    device = setup(args.source_pipeline)
    if device is None:
        return 1

    if args.skip_geometric:
        set_config('global', 'geometriccorrection_params', '')

    for k, v in defaults.iteritems():
        set_config('global', k, v)

    # Need to re-parse arguments as the settings above may have affected the
    # values we get out.
    args = parse_args(argv)

    transformation_pipeline = (
        'tee name=raw_undistorted '
        'raw_undistorted. ! queue leaky=upstream ! videoconvert ! '
        '    textoverlay text="Capture from camera" ! %s '
        'raw_undistorted. ! queue ! appsink drop=true sync=false qos=false'
        '    max-buffers=1 caps="video/x-raw,format=BGR"'
        '    name=undistorted_appsink '
        'raw_undistorted. ! queue leaky=upstream max-size-buffers=1 ! %s' %
        (args.sink_pipeline,
         stbt.get_config('global', 'transformation_pipeline')))

    args.sink_pipeline = ('textoverlay text="After correction" ! ' +
                          args.sink_pipeline)
    args.control = 'none'

    with _stbt.core.new_device_under_test_from_config(
            args, transformation_pipeline=transformation_pipeline) as dut:
        tv = tv_driver.create_from_args(args, videos)

        if not args.skip_geometric:
            geometric_calibration(dut,
                                  tv,
                                  device,
                                  interactive=args.interactive)
        if args.interactive:
            adjust_levels(dut, tv, device)
        if not args.skip_illumination:
            calibrate_illumination(dut, tv)

        if args.interactive:
            raw_input("Calibration complete.  Press <ENTER> to exit")
        return 0
コード例 #8
0
def setup(source_pipeline):
    """If we haven't got a configured camera offer a list of cameras you might
    want to use.  In the future it could be useful to allow the user to select
    one from the list interactively."""
    if (source_pipeline == ''
            or stbt.get_config('global', 'v4l2_device', '') == ''):
        sys.stderr.write(
            'No camera configured in stbt.conf please add parameters '
            '"v4l2_device" and "source_pipeline" to section [global] of '
            'stbt.conf.\n\n')
        cameras = list(list_cameras())
        if len(cameras) == 0:
            sys.stderr.write("No Cameras Detected\n\n")
        else:
            sys.stderr.write("Detected cameras:\n\n")
        for n, (name, dev_file, source_pipeline) in enumerate(cameras):
            sys.stderr.write(
                "    %i. %s\n"
                "\n"
                "        v4l2_device = %s\n"
                "        source_pipeline = %s\n\n"
                % (n, name, dev_file, source_pipeline))
        return None
    return stbt.get_config('global', 'v4l2_device')
コード例 #9
0
def main(argv):
    args = parse_args(argv)

    device = setup(args.source_pipeline)
    if device is None:
        return 1

    if args.skip_geometric:
        set_config('global', 'geometriccorrection_params', '')

    for k, v in defaults.iteritems():
        set_config('global', k, v)

    # Need to re-parse arguments as the settings above may have affected the
    # values we get out.
    args = parse_args(argv)

    transformation_pipeline = (
        'tee name=raw_undistorted '
        'raw_undistorted. ! queue leaky=upstream ! videoconvert ! '
        '    textoverlay text="Capture from camera" ! %s '
        'raw_undistorted. ! queue ! appsink drop=true sync=false qos=false'
        '    max-buffers=1 caps="video/x-raw,format=BGR"'
        '    name=undistorted_appsink '
        'raw_undistorted. ! queue leaky=upstream max-size-buffers=1 ! %s' %
        (args.sink_pipeline,
         stbt.get_config('global', 'transformation_pipeline')))

    sink_pipeline = ('textoverlay text="After correction" ! ' +
                     args.sink_pipeline)

    stbt.init_run(args.source_pipeline, sink_pipeline, 'none', False, False,
                  transformation_pipeline)

    tv = tv_driver.create_from_args(args, videos)

    if not args.skip_geometric:
        geometric_calibration(tv, device, interactive=args.interactive)
    if args.interactive:
        adjust_levels(tv, device)
    if not args.skip_illumination:
        calibrate_illumination(tv)

    if args.interactive:
        raw_input("Calibration complete.  Press <ENTER> to exit")
    return 0
コード例 #10
0
def adjust_levels(tv):
    tv.show("colours")
    happy = "no"
    device = stbt.get_config("global", "v4l2_device")
    with colour_graph() as update_graph:
        while not happy.startswith("y"):
            update_graph()

            # Allow adjustment
            subprocess.check_call(["v4l2-ctl", "-d", device, "-L"])
            cmd = raw_input("Happy? [Y/n/set] ").strip().lower()
            if cmd.startswith("set"):
                _, var, val = cmd.split()
                subprocess.check_call(["v4l2-ctl", "-d", device, "-c", "%s=%s" % (var, val)])
            if cmd.startswith("y") or cmd == "":
                break

    set_config("global", "v4l2_ctls", ",".join(["%s=%s" % (c, a["value"]) for c, a in dict(v4l2_ctls(device)).items()]))
コード例 #11
0
    def __init__(self, spreadsheet_id=None, credentials_file=None):
        import httplib2
        from apiclient import discovery

        if spreadsheet_id is None:
            from stbt import get_config
            spreadsheet_id = get_config("test_pack", "google_sheets_id")
        print "Using spreadsheet %r" % spreadsheet_id

        credentials = self._get_credentials(credentials_file)
        http = credentials.authorize(httplib2.Http())
        discoveryUrl = ('https://sheets.googleapis.com/$discovery/rest?'
                        'version=v4')
        self.service = discovery.build('sheets',
                                       'v4',
                                       http=http,
                                       discoveryServiceUrl=discoveryUrl)
        self.sheets = self.service.spreadsheets()  # pylint: disable=no-member
        self.spreadsheet_id = spreadsheet_id
コード例 #12
0
def get_bitmap(frame_object, filename):
    """Get the image from obect for comparison

    :param frame_object: Object for comparison
    :param filename: image for comparison
    :return:
    """
    module_dir = os.path.dirname(inspect.getfile(frame_object.__class__))
    folder = stbt.get_config('device_under_test', 'device_type')

    # return os.path.join(module_dir, "images", folder, filename)
    if os.path.exists(os.path.join(module_dir, "images")):
        if os.path.exists(os.path.join(module_dir, "images", filename)):
            return os.path.join(module_dir, "images", filename)
        elif os.path.exists(os.path.join(module_dir, "images", folder, filename)):
            return os.path.join(module_dir, "images", folder, filename)
        assert False, "File {} does not exist".format(filename)
    else:
        assert False, "The <images> folder does not exist"
コード例 #13
0
def adjust_levels(tv):
    tv.show("colours")
    happy = "no"
    device = stbt.get_config('global', 'v4l2_device')
    with colour_graph() as update_graph:
        while not happy.startswith('y'):
            update_graph()

            # Allow adjustment
            subprocess.check_call(['v4l2-ctl', '-d', device, '-L'])
            cmd = raw_input("Happy? [Y/n/set] ").strip().lower()
            if cmd.startswith('set'):
                _, var, val = cmd.split()
                subprocess.check_call(
                    ['v4l2-ctl', '-d', device, "-c", "%s=%s" % (var, val)])
            if cmd.startswith('y') or cmd == '':
                break

    set_config('global', 'v4l2_ctls', ','.join(
        ["%s=%s" % (c, a['value'])
         for c, a in dict(v4l2_ctls(device)).items()]))
コード例 #14
0
def adjust_levels(tv):
    tv.show("colours")
    happy = "no"
    device = stbt.get_config('global', 'v4l2_device')
    with colour_graph() as update_graph:
        while not happy.startswith('y'):
            update_graph()

            # Allow adjustment
            subprocess.check_call(['v4l2-ctl', '-d', device, '-L'])
            cmd = raw_input("Happy? [Y/n/set] ").strip().lower()
            if cmd.startswith('set'):
                _, var, val = cmd.split()
                subprocess.check_call(
                    ['v4l2-ctl', '-d', device, "-c", "%s=%s" % (var, val)])
            if cmd.startswith('y') or cmd == '':
                break

    set_config('global', 'v4l2_ctls', ','.join(
        ["%s=%s" % (c, a['value'])
         for c, a in dict(v4l2_ctls(device)).items()]))
コード例 #15
0
def test_that_set_config_creates_new_sections_if_required():
    with set_config_test():
        _set_config('non_existent_section', 'test', 'goodbye')
        assert get_config('non_existent_section', 'test', 'goodbye')
        _config_init(force=True)
        assert get_config('non_existent_section', 'test', 'goodbye')
コード例 #16
0
def test_that_set_config_modifies_config_value():
    with set_config_test():
        _set_config('global', 'test', 'goodbye')
        assert get_config('global', 'test', 'goodbye')
        _config_init(force=True)
        assert get_config('global', 'test', 'goodbye')
コード例 #17
0
    def __exit__(self, exc_type, exc_val, exc_tb):
        if self.file:
            self.file.close()


def load_project_config(project):
    """
    :param project: device type defined in the <*.conf file>
    :return: profile specific configurations
   """
    with FileLoader(os.path.join("config", 'config.yaml')) as yaml_file:
        data = yaml.safe_load(yaml_file.read())
        return data[project]


device = stbt.get_config('device_under_test', 'device_type')
profile = load_project_config(device)


def wait(duration=2, unit='seconds'):
    """Sleep for a duration

    :param duration: Integer/float value
    :param unit: sleep unit
   """
    stbt.draw_text('Action                           : Wait for %s %s',
                   duration, unit)
    time.sleep(durationToSeconds(duration, unit))


def get_randomized_item(target_list):
コード例 #18
0
def test_that_set_config_creates_new_sections_if_required():
    with set_config_test():
        _set_config('non_existent_section', 'test', 'goodbye')
        assert get_config('non_existent_section', 'test', 'goodbye')
        _config_init(force=True)
        assert get_config('non_existent_section', 'test', 'goodbye')
コード例 #19
0
def test_that_set_config_modifies_config_value():
    with set_config_test():
        _set_config('global', 'test', 'goodbye')
        assert get_config('global', 'test', 'goodbye')
        _config_init(force=True)
        assert get_config('global', 'test', 'goodbye')