diff --git a/pyogp/lib/base/OGPLogin.py b/pyogp/lib/base/OGPLogin.py new file mode 100644 index 0000000..7d083fe --- /dev/null +++ b/pyogp/lib/base/OGPLogin.py @@ -0,0 +1,70 @@ +from pyogp.lib.base.credentials import PlainPasswordCredential +from pyogp.lib.base.agentdomain import AgentDomain +from pyogp.lib.base.regiondomain import Region + +from pyogp.lib.base.interfaces import IPlaceAvatarAdapter + +import getpass, sys +from optparse import OptionParser + +import pprint + +class OGPLogin(object): + """ This class can be used to log in to an agent domain and start communicating with a region domain """ + + def __init__(self, credents, loginuri, regionuri): + self.credentials = credents #PlainPasswordCredential(credents.firstname, credents.lastname, credents.password) + self.loginuri = loginuri + self.regionuri = regionuri + + def login(self): + + print "login to the agent domain: " + self.loginuri + agentd, agent = self.loginToAgentD() + print "logged in, we now have an agent: ", agent + print "and a domain: ", agentd + + print "now we try to place the avatar on a region" + avatar = self.placeAvatarCap() + print "placed avatar cap, got back: ", avatar + + #avatar.establish_presence() + + def loginToAgentD(self): + """ Logs into the agent domain, getting the agentd seed cap """ + self.agentdomain = AgentDomain(self.loginuri) + self.agent = self.agentdomain.login(self.credentials) + return self.agentdomain, self.agent + + def getCapabilities(self, seed_cap, caps): + """ This is the method that SHOULD be used (but isn't) to get capabilities from the seedcap """ + pass + + def placeAvatarCap(self): + """ actually gets the place_avatar cap and posts to it """ + region = Region(self.regionuri) + place = IPlaceAvatarAdapter(self.agent) + self.avatar = place(region) + return self.avatar + +def main(): + parser = OptionParser() + + parser.add_option("-a", "--agentdomain", dest="loginuri", default="https://login1.aditi.lindenlab.com/cgi-bin/auth.cgi", + help="URI of Agent Domain") + parser.add_option("-r", "--region", dest="regionuri", default="http://sim1.vaak.lindenlab.com:13000", + help="URI of Region to connect to") + + (options, args) = parser.parse_args() + + options.firstname = args[0] + options.lastname = args[1] + options.password = getpass.getpass() + + pprint.pprint(options) + credents = PlainPasswordCredential(options.firstname, options.lastname, options.password) + + return OGPLogin(credents, options.loginuri, options.regionuri).login() + +if __name__=="__main__": + main() diff --git a/pyogp/lib/base/tests/__init__.py b/pyogp/lib/base/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyogp/lib/base/tests/test_ogplogin.py b/pyogp/lib/base/tests/test_ogplogin.py new file mode 100644 index 0000000..eb6eeb0 --- /dev/null +++ b/pyogp/lib/base/tests/test_ogplogin.py @@ -0,0 +1,28 @@ +import unittest, doctest +from pyogp.lib.base.credentials import PlainPasswordCredential +from pyogp.lib.base.agentdomain import AgentDomain +from pyogp.lib.base.regiondomain import Region + +from pyogp.lib.base.interfaces import IPlaceAvatarAdapter + +from pyogp.lib.base.OGPLogin import OGPLogin + +class TestOGPLogin(unittest.TestCase): + def test_login(self): + credentials = PlainPasswordCredential('firstname', 'lastname', 'password') + #create a login, giving it the credentials, the loginuri, and the regionuri + ogpLogin = OGPLogin(credentials, 'https://login1.aditi.lindenlab.com/cgi-bin/auth.cgi', 'http://sim1.vaak.lindenlab.com:13000') + + #gets seedcap, and an agent that can be placed in a region + agentdomain, agent = ogpLogin.loginToAgentD() + assert agentdomain.seed_cap != None or agentdomain.seed_cap != {}, "Login to agent domain failed" + + #attempts to place the agent in a region + avatar = ogpLogin.placeAvatarCap() + assert avatar['connect'] == True, "Place avatar failed" + +def test_suite(): + from unittest import TestSuite, makeSuite + suite = TestSuite() + suite.addTest(makeSuite(TestOGPLogin)) + return suite diff --git a/setup.py b/setup.py index ff384e5..53e9387 100644 --- a/setup.py +++ b/setup.py @@ -31,6 +31,7 @@ setup(name='pyogp.lib.base', entry_points={ 'console_scripts': [ 'login = pyogp.lib.base.example:main', + 'OGPlogin = pyogp.lib.base.OGPLogin:main' ], },