コード例 #1
0
def main():
    from config import ErosConfig
    config = ErosConfig()
    from optparse import OptionParser
    usage = "\n\
  %prog               : shows the currently set ros platform\n\
  %prog clear         : clear the currently set ros platform\n\
  %prog create        : create a user-defined platform configuration\n\
  %prog delete        : delete a platform configuration\n\
  %prog help          : print this help information\n\
  %prog list          : list available eros and user-defined platforms\n\
  %prog select        : interactively select a platform configuration\n\
  %prog select <str>  : directly select the specified platform configuration\n\
  %prog validate      : attempt to validate a platform (not yet implemented)\n\
\n\
Description: \n\
  Create/delete and manage the platform configuration for this ros environment\n\
  Location of the user platform directory can be modified via --dir or more \n\
  permanently via " + core.eros_config() + "."
    parser = OptionParser(usage=usage)
    parser.add_option("-d","--dir", action="store", default=config.user_platforms_dir(), help="location of the user platforms directory.")
    #parser.add_option("-v","--validate", action="store_true", dest="validate", help="when creating, attempt to validate the configuration")
    options, args = parser.parse_args()
    
    # Configure the user platform directory.
    user_platform_dir(options.dir)

    ###################
    # Show current
    ###################
    if not args:
        show_current_platform()
        return 0

    command = args[0]
        
    ###################
    # Help
    ###################
    if command == 'help':
        parser.print_help()
        return 0
    
    ###################
    # List
    ###################
    if command == 'list':
        list_platforms()
        return 0
    
    ###################
    # Clear
    ###################
    if command == 'clear':
        if os.path.exists(core.rosconfig_cmake()):
            os.remove(core.rosconfig_cmake())
            print
            print "-- Platform configuration cleared."
            print
        else:
            print
            print "-- Nothing to do (no rosconfig.cmake)."
            print
        return 0
    ###################
    # Create
    ###################
    if command == 'create':
        return create_platform()

    ###################
    # Delete
    ###################
    if command == 'delete':
        return delete_platform()

    ###################
    # Select
    ###################
    if command == 'select':
        if len(args) == 1: # interactive selection
            if not select_platform():
                return 1
        else:
            if not select_platform_by_name(args[1]):
                return 1
        print
        return 0
    
    ###################
    # Validate
    ###################
    if command == 'validate':
        print
        print "-- This command is not yet available."
        print
        return 0 
    
    # If we reach here, we have not received a valid command.
    print
    print "-- Not a valid command [" + command + "]."
    print
    parser.print_help()
    print
    return 1