Package rosmaster :: Module main

Source Code for Module rosmaster.main

  1  # Software License Agreement (BSD License) 
  2  # 
  3  # Copyright (c) 2008, Willow Garage, Inc. 
  4  # All rights reserved. 
  5  # 
  6  # Redistribution and use in source and binary forms, with or without 
  7  # modification, are permitted provided that the following conditions 
  8  # are met: 
  9  # 
 10  #  * Redistributions of source code must retain the above copyright 
 11  #    notice, this list of conditions and the following disclaimer. 
 12  #  * Redistributions in binary form must reproduce the above 
 13  #    copyright notice, this list of conditions and the following 
 14  #    disclaimer in the documentation and/or other materials provided 
 15  #    with the distribution. 
 16  #  * Neither the name of Willow Garage, Inc. nor the names of its 
 17  #    contributors may be used to endorse or promote products derived 
 18  #    from this software without specific prior written permission. 
 19  # 
 20  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 21  # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 22  # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 23  # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 24  # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
 25  # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
 26  # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
 27  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 28  # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 29  # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 30  # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  # POSSIBILITY OF SUCH DAMAGE. 
 32  # 
 33  # Revision $Id$ 
 34   
 35  """Command-line handler for ROS zenmaster (Python Master)""" 
 36   
 37  import logging 
 38  import os 
 39  import sys 
 40  import time 
 41  import optparse 
 42   
 43  import rosmaster.master 
 44   
45 -def configure_logging():
46 """ 47 Setup filesystem logging for the master 48 """ 49 filename = 'master.log' 50 # #988 __log command-line remapping argument 51 import rosgraph.names 52 import rosgraph.roslogging 53 mappings = rosgraph.names.load_mappings(sys.argv) 54 if '__log' in mappings: 55 logfilename_remap = mappings['__log'] 56 filename = os.path.abspath(logfilename_remap) 57 _log_filename = rosgraph.roslogging.configure_logging('rosmaster', logging.DEBUG, filename=filename)
58
59 -def rosmaster_main(argv=sys.argv, stdout=sys.stdout, env=os.environ):
60 parser = optparse.OptionParser(usage="usage: zenmaster [options]") 61 parser.add_option("--core", 62 dest="core", action="store_true", default=False, 63 help="run as core") 64 parser.add_option("-p", "--port", 65 dest="port", default=0, 66 help="override port", metavar="PORT") 67 options, args = parser.parse_args(argv[1:]) 68 69 # only arg that zenmaster supports is __log remapping of logfilename 70 for arg in args: 71 if not arg.startswith('__log:='): 72 parser.error("unrecognized arg: %s"%arg) 73 configure_logging() 74 75 port = rosmaster.master.DEFAULT_MASTER_PORT 76 if options.port: 77 port = int(options.port) 78 79 if not options.core: 80 print """ 81 82 83 ACHTUNG WARNING ACHTUNG WARNING ACHTUNG 84 WARNING ACHTUNG WARNING ACHTUNG WARNING 85 86 87 Standalone zenmaster has been deprecated, please use 'roscore' instead 88 89 90 ACHTUNG WARNING ACHTUNG WARNING ACHTUNG 91 WARNING ACHTUNG WARNING ACHTUNG WARNING 92 93 94 """ 95 96 logger = logging.getLogger("rosmaster.main") 97 logger.info("initialization complete, waiting for shutdown") 98 try: 99 logger.info("Starting ROS Master Node") 100 master = rosmaster.master.Master(port) 101 master.start() 102 103 import time 104 while master.ok(): 105 time.sleep(.1) 106 except KeyboardInterrupt: 107 logger.info("keyboard interrupt, will exit") 108 finally: 109 logger.info("stopping master...") 110 master.stop()
111 112 if __name__ == "__main__": 113 main() 114