Exemplo n.º 1
0
def main(argv=sys.argv):
    if argv.count('install'):
        settings.setQ2Qusername('')
        settings.setQ2Qpassword('')
        #init(False).addCallback(
        init(True).addBoth(
                lambda x: reactor.stop())
#        install().addBoth(
#                lambda x: reactor.stop())
        reactor.run()
        
    elif argv.count('receive'):
        init(False).addCallback(
            lambda x: receive())
        reactor.run()
        
    elif argv.count('send'):
        def doSend(x):
            def sent(x):
                print 'CONNECTED!'
            def fail(x):
                print 'fail'
                reactor.stop()
            send(argv[2], argv[3]).addCallbacks(sent, fail)
        init(False).addCallback(doSend)
        reactor.run()
        
    else:
        usage()
Exemplo n.º 2
0
def install():
    dhnio.Dprint(4, 'transport_q2q.install')
       
    def done(x, resultDefer): 
        dhnio.Dprint(4, 'transport_q2q.install.done')
        settings.setQ2Quserathost(str(dhnvertex.getFrom()))
        resultDefer.callback(x)
        return x
        
    def failed(x, resultDefer):
        dhnio.Dprint(4, 'transport_q2q.install.failed: ' + x.getErrorMessage())
        resultDefer.errback(x)
        return x

    result = Deferred()
    username = misc.getIDName() + time.strftime('%Y%m%d%H%M%S') + '@' + settings.DefaultQ2QServer()
    password = settings.getQ2Qpassword()
    if password.strip() == '':
        password = misc.rndstr(NEW_USER_PASSWORD_LENGTH)
        settings.setQ2Qpassword(password)

    d = dhnvertex.register(username, password)
    d.addCallback(done, result)
    d.addErrback(failed, result)

    return result