• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
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
6import logging
7import sys
8import time
9
10import client
11import pseudomodem
12import pseudomodem_context
13
14def main():
15    """ Entry function to run pseudomodem standalone. """
16    pmc = None
17    flags = sys.argv[1:]
18    cli_flag = (pseudomodem.CLI_FLAG in flags)
19
20    # When run from the command line, override autotest logging defaults.
21    root = logging.getLogger()
22    for handler in root.handlers:
23        root.removeHandler(handler)
24    logging.basicConfig(
25        format='%(asctime)s %(levelname)-5.5s|%(module)10.10s:%(lineno)4.4d| '
26               '%(message)s',
27        datefmt='%H:%M:%S')
28
29    try:
30        pmc = pseudomodem_context.PseudoModemManagerContext(
31                True,
32                block_output=cli_flag)
33        pmc.cmd_line_flags = flags
34        pmc.Start()
35        if cli_flag:
36            cli = client.PseudoModemClient()
37            cli.Begin()  # Blocking
38        else:
39            # Block quietly till user interrupt.
40            while True:
41                time.sleep(30)
42    except KeyboardInterrupt:
43        print 'Terminating on user request.'
44    finally:
45        # This is always hit, even when SIGINT is received.
46        if pmc:
47            pmc.Stop()
48
49
50if __name__ == '__main__':
51    main()
52