• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Lint as: python2, python3
2# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6from __future__ import absolute_import
7from __future__ import division
8from __future__ import print_function
9
10import logging
11import sys
12import time
13
14from autotest_lib.client.cros.cellular.pseudomodem import client
15from autotest_lib.client.cros.cellular.pseudomodem import pseudomodem
16from autotest_lib.client.cros.cellular.pseudomodem import pseudomodem_context
17
18def main():
19    """ Entry function to run pseudomodem standalone. """
20    pmc = None
21    flags = sys.argv[1:]
22    cli_flag = (pseudomodem.CLI_FLAG in flags)
23
24    # When run from the command line, override autotest logging defaults.
25    root = logging.getLogger()
26    for handler in root.handlers:
27        root.removeHandler(handler)
28    logging.basicConfig(
29        format='%(asctime)s %(levelname)-5.5s|%(module)10.10s:%(lineno)4.4d| '
30               '%(message)s',
31        datefmt='%H:%M:%S')
32
33    try:
34        pmc = pseudomodem_context.PseudoModemManagerContext(
35                True,
36                block_output=cli_flag)
37        pmc.cmd_line_flags = flags
38        pmc.Start()
39        if cli_flag:
40            cli = client.PseudoModemClient()
41            cli.Begin()  # Blocking
42        else:
43            # Block quietly till user interrupt.
44            while True:
45                time.sleep(30)
46    except KeyboardInterrupt:
47        print('Terminating on user request.')
48    finally:
49        # This is always hit, even when SIGINT is received.
50        if pmc:
51            pmc.Stop()
52
53
54if __name__ == '__main__':
55    main()
56