Ejemplo n.º 1
0
def main():
    logging.basicConfig(level=logging.INFO)

    parser = argparse.ArgumentParser(
        description='Serves web GUI for interacting with multiple OpenHTF '
        'stations.')
    parser.add_argument('--discovery-interval-s',
                        type=int,
                        default=1,
                        help='Seconds between station discovery attempts.')
    parser.add_argument('--launch-web-gui',
                        default=True,
                        action='store_true',
                        help='Whether to automatically open web GUI.')
    parser.add_argument('--no-launch-web-gui',
                        dest='launch_web_gui',
                        action='store_false',
                        help='Whether to automatically open web GUI.')
    parser.add_argument('--dashboard-server-port',
                        type=int,
                        default=12000,
                        help='Port on which to serve the dashboard server.')

    # These have default values in openhtf.util.multicast.py.
    parser.add_argument('--station-discovery-address', type=str)
    parser.add_argument('--station-discovery-port', type=int)
    parser.add_argument('--station-discovery-ttl', type=int)
    parser.add_argument('--no-local-only',
                        action='store_false',
                        default=True,
                        dest='station_discovery_local_only',
                        help=('Whether to discover only local stations.'))

    args = parser.parse_args()

    with DashboardServer(args.dashboard_server_port) as server:

        if args.launch_web_gui:
            url = 'http://localhost:%s' % (server.port, )
            try:
                web_launcher.launch(url)
            except Exception:  # pylint: disable=broad-except
                _LOG.exception('Problem launching web gui')

        # Make kwargs from command line arguments.
        multicast_kwargs = {
            attr: getattr(args, 'station_discovery_%s' % attr)
            for attr in ('address', 'port', 'ttl', 'local_only')
            if getattr(args, 'station_discovery_%s' % attr) is not None
        }

        _LOG.info('Starting station discovery.')

        # Exit on CTRL+C.
        while True:
            stations = _discover(**multicast_kwargs)
            DashboardPubSub.update_stations(list(stations))
            DashboardPubSub.publish_if_new()
            time.sleep(args.discovery_interval_s)
Ejemplo n.º 2
0
def main():
    conf.load(station_server_port='4444')
    with station_server.StationServer() as server:
        web_launcher.launch('http://localhost:4444')
        for _ in range(5):
            test = htf.Test(hello_world)
            test.add_output_callbacks(server.publish_final_state)
            test.execute(test_start=user_input.prompt_for_test_start())
Ejemplo n.º 3
0
def main():
  logging.basicConfig(level=logging.INFO)

  parser = argparse.ArgumentParser(
      description='Serves web GUI for interacting with multiple OpenHTF '
                  'stations.')
  parser.add_argument('--discovery-interval-s', type=int, default=1,
                      help='Seconds between station discovery attempts.')
  parser.add_argument('--launch-web-gui', default=True, action="store_true",
                      help='Whether to automatically open web GUI.')
  parser.add_argument('--no-launch-web-gui', dest="launch_web_gui",
                      action="store_false",
                      help='Whether to automatically open web GUI.')
  parser.add_argument('--dashboard-server-port', type=int, default=12000,
                      help='Port on which to serve the dashboard server.')

  # These have default values in openhtf.util.multicast.py.
  parser.add_argument('--station-discovery-address', type=str)
  parser.add_argument('--station-discovery-port', type=int)
  parser.add_argument('--station-discovery-ttl', type=int)
  parser.add_argument(
      '--no-local-only',
      action='store_false',
      default=True,
      dest='station_discovery_local_only',
      help=('Whether to discover only local stations.'))

  args = parser.parse_args()

  with DashboardServer(args.dashboard_server_port) as server:

    if args.launch_web_gui:
      url = 'http://localhost:%s' % (server.port,)
      try:
        web_launcher.launch(url)
      except Exception:  # pylint: disable=broad-except
        _LOG.exception('Problem launching web gui')

    # Make kwargs from command line arguments.
    multicast_kwargs = {
        attr: getattr(args, 'station_discovery_%s' % attr)
        for attr in ('address', 'port', 'ttl', 'local_only')
        if getattr(args, 'station_discovery_%s' % attr) is not None
    }

    _LOG.info('Starting station discovery.')

    # Exit on CTRL+C.
    while True:
      stations = _discover(**multicast_kwargs)
      DashboardPubSub.update_stations(list(stations))
      DashboardPubSub.publish_if_new()
      time.sleep(args.discovery_interval_s)
Ejemplo n.º 4
0
# 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.


"""Simple OpenHTF test which launches the web GUI client."""

import openhtf as htf
from openhtf.util import conf

from openhtf.output.servers import station_server
from openhtf.output.web_gui import web_launcher
from openhtf.plugs import user_input


@htf.measures(htf.Measurement('hello_world_measurement'))
def hello_world(test):
  test.logger.info('Hello World!')
  test.measurements.hello_world_measurement = 'Hello Again!'


if __name__ == '__main__':
  conf.load(station_server_port='4444')
  with station_server.StationServer() as server:
    web_launcher.launch('http://localhost:4444')
    for i in range(5):
      test = htf.Test(hello_world)
      test.add_output_callbacks(server.publish_final_state)
      test.execute(test_start=user_input.prompt_for_test_start())