Пример #1
0
def login():
    """ login an to a login endpoint """ 

    parser = OptionParser(usage="usage: %prog [options] firstname lastname")

    logger = logging.getLogger("client.example")

    parser.add_option("-l", "--loginuri", dest="loginuri", default="https://login.aditi.lindenlab.com/cgi-bin/login.cgi",
                      help="specified the target loginuri")
    parser.add_option("-r", "--region", dest="region", default=None,
                      help="specifies the region (regionname/x/y/z) to connect to")
    parser.add_option("-q", "--quiet", dest="verbose", default=True, action="store_false",
                    help="enable verbose mode")
    parser.add_option("-s", "--search", dest="search", default=None,
                    help="inventory item to search for an rez (optional)")
    parser.add_option("-p", "--password", dest="password", default=None,
                      help="specifies password instead of being prompted for one")

    (options, args) = parser.parse_args()

    if len(args) != 2:
        parser.error("Expected arguments: firstname lastname")

    if options.verbose:
        console = logging.StreamHandler()
        console.setLevel(logging.DEBUG) # seems to be a no op, set it for the logger
        formatter = logging.Formatter('%(asctime)-30s%(name)-30s: %(levelname)-8s %(message)s')
        console.setFormatter(formatter)
        logging.getLogger('').addHandler(console)

        # setting the level for the handler above seems to be a no-op
        # it needs to be set for the logger, here the root logger
        # otherwise it is NOTSET(=0) which means to log nothing.
        logging.getLogger('').setLevel(logging.DEBUG)
    else:
        print "Attention: This script will print nothing if you use -q. So it might be boring to use it like that ;-)"

    # example from a pure agent perspective

    #grab a password!
    #grab a password!
    if options.password:
        password = options.password
    else:
        password = getpass.getpass()

    # let's disable object tracking for this example
    settings = Settings()
    settings.ENABLE_OBJECT_TRACKING = False

    #First, initialize the agent
    client = Agent(settings = settings)

    # Now let's log it in
    api.spawn(client.login, options.loginuri, args[0], args[1], password, start_location = options.region, connect_region = True)

    # wait for the agent to connect to it's region
    while client.connected == False:
        api.sleep(0)

    while client.region.connected == False:
        api.sleep(0)

    # for folders whose parent = root folder aka My Inventory, request their contents
    [client.inventory._request_folder_contents(folder.FolderID) for folder in client.inventory.folders if folder.ParentID == client.inventory.inventory_root.FolderID]

    #while client.running:
        #api.sleep(0)

    # next, let's wait 30 seconds and FetchInventory for items we know about
    now = time.time()
    start = now
    while now - start < 5 and client.running:
        api.sleep()
        now = time.time()


    if options.search != None:
        # and next, let's search the inventory by name
        matches = client.inventory.search_inventory(name = options.search)

        # now, if we have a match, let's try and rez the first matching object
        item_to_rez = matches[0]
        print item_to_rez.__dict__
        print dir(item_to_rez)

        item_to_rez.rez_object(client)

    # next, let's wait another 30 seconds then bail
    now = time.time()
    start = now
    while now - start < 30 and client.running:
        api.sleep()

    client.logout()

    print ''
    print ''
    print 'At this point, we have an Agent object, Inventory dirs, and with a Region attribute'
    print 'Agent attributes:'
    for attr in client.__dict__:
        print attr, ':\t\t\t',  client.__dict__[attr]
    print ''
    print ''
    print 'Inventory: %s folders' % len(client.inventory.folders)
    for inv_folder in client.inventory.folders:
        print 'Inventory Folder', ':\t\t\t',  inv_folder.Name
        for item in inv_folder.inventory:
            print '    ', item.Name
    print ''
    print ''
    print 'Region attributes:'
    for attr in client.region.__dict__:
        print attr, ':\t\t\t',  client.region.__dict__[attr]
Пример #2
0
def login():
    """ login an to a login endpoint """

    parser = OptionParser(usage="usage: %prog [options] firstname lastname")

    logger = logging.getLogger("client.example")

    parser.add_option(
        "-l",
        "--loginuri",
        dest="loginuri",
        default="https://login.aditi.lindenlab.com/cgi-bin/login.cgi",
        help="specified the target loginuri")
    parser.add_option(
        "-r",
        "--region",
        dest="region",
        default=None,
        help="specifies the region (regionname/x/y/z) to connect to")
    parser.add_option("-q",
                      "--quiet",
                      dest="quiet",
                      default=False,
                      action="store_true",
                      help="log warnings and above (default is debug)")
    parser.add_option("-d",
                      "--verbose",
                      dest="verbose",
                      default=False,
                      action="store_true",
                      help="log info and above (default is debug)")
    parser.add_option(
        "-p",
        "--password",
        dest="password",
        default=None,
        help="specifies password instead of being prompted for one")

    (options, args) = parser.parse_args()

    if len(args) != 2:
        parser.error("Expected 2 arguments")

    (firstname, lastname) = args

    console = logging.StreamHandler()
    formatter = logging.Formatter(
        '%(asctime)-30s%(name)-30s: %(levelname)-8s %(message)s')
    console.setFormatter(formatter)
    logging.getLogger('').addHandler(console)

    # setting the level for the handler above seems to be a no-op
    # it needs to be set for the logger, here the root logger
    # otherwise it is NOTSET(=0) which means to log nothing.
    if options.verbose:
        logging.getLogger('').setLevel(logging.INFO)
    elif options.quiet:
        logging.getLogger('').setLevel(logging.WARNING)
    else:
        logging.getLogger('').setLevel(logging.DEBUG)

    # example from a pure agent perspective

    #grab a password!
    if options.password:
        password = options.password
    else:
        password = getpass.getpass()

    # prep instance settings
    settings = Settings()

    settings.ENABLE_INVENTORY_MANAGEMENT = False
    settings.ENABLE_COMMUNICATIONS_TRACKING = False
    settings.ENABLE_OBJECT_TRACKING = False
    settings.ENABLE_UDP_LOGGING = True
    settings.ENABLE_EQ_LOGGING = True
    settings.ENABLE_CAPS_LOGGING = True
    settings.MULTIPLE_SIM_CONNECTIONS = False

    #First, initialize the agent
    client = Agent(settings)

    # Now let's log it in
    api.spawn(client.login,
              options.loginuri,
              firstname,
              lastname,
              password,
              start_location=options.region,
              connect_region=True)

    # wait for the agent to connect to it's region
    while client.connected == False:
        api.sleep(0)

    while client.region.connected == False:
        api.sleep(0)

    fetch_voice_info(client, callback=lambda x, y: client.logout())

    while client.running:
        api.sleep(0)
def login():
    """ login an to a login endpoint """

    parser = OptionParser(usage="usage: %prog [options] firstname lastname")

    logger = logging.getLogger("client.example")

    parser.add_option(
        "-l",
        "--loginuri",
        dest="loginuri",
        default="https://login.aditi.lindenlab.com/cgi-bin/login.cgi",
        help="specified the target loginuri")
    parser.add_option(
        "-r",
        "--region",
        dest="region",
        default=None,
        help="specifies the region (regionname/x/y/z) to connect to")
    parser.add_option("-q",
                      "--quiet",
                      dest="verbose",
                      default=True,
                      action="store_false",
                      help="enable verbose mode")
    parser.add_option(
        "-p",
        "--password",
        dest="password",
        default=None,
        help="specifies password instead of being prompted for one")

    (options, args) = parser.parse_args()

    if len(args) != 2:
        parser.error("Expected arguments: firstname lastname")

    if options.verbose:
        console = logging.StreamHandler()
        console.setLevel(
            logging.DEBUG)  # seems to be a no op, set it for the logger
        formatter = logging.Formatter(
            '%(asctime)-30s%(name)-30s: %(levelname)-8s %(message)s')
        console.setFormatter(formatter)
        logging.getLogger('').addHandler(console)

        # setting the level for the handler above seems to be a no-op
        # it needs to be set for the logger, here the root logger
        # otherwise it is NOTSET(=0) which means to log nothing.
        logging.getLogger('').setLevel(logging.DEBUG)
    else:
        print "Attention: This script will print nothing if you use -q. So it might be boring to use it like that ;-)"

    # example from a pure agent perspective

    #grab a password!
    if options.password:
        password = options.password
    else:
        password = getpass.getpass()

    # let's disable inventory handling and object tracking for this example
    settings = Settings()
    settings.ENABLE_INVENTORY_MANAGEMENT = False
    settings.ENABLE_OBJECT_TRACKING = False

    #First, initialize the agent
    client = Agent(settings=settings)

    # Now let's log it in
    api.spawn(client.login,
              options.loginuri,
              args[0],
              args[1],
              password,
              start_location=options.region,
              connect_region=True)

    # wait for the agent to connect to it's region
    while client.connected == False:
        api.sleep(0)

    while client.region.connected == False:
        api.sleep(0)

    # do sample script specific stuff here
    print "This is not at all working yet, please come back later. (Hint. Ctrl-C)"
    client.logout()

    # Not yet working it seems, what's up?
    # client.appearance.request_agent_wearables()

    while client.running:
        api.sleep(0)

    print ''
    print ''
    print 'At this point, we have an Agent object, Inventory dirs, and with a Region attribute'
    print 'Agent attributes:'
    for attr in client.__dict__:
        print attr, ':\t\t\t', client.__dict__[attr]
    print ''
    print ''
    '''