source: remote_control/puzzlebox_brainstorms_client_thinkgear.py @ 49

Last change on this file since 49 was 49, checked in by sc, 11 years ago

client_thinkgear:

  • minor cleanup
  • authentication process not functioning
File size: 3.1 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Puzzlebox - Brainstorms - Client - ThinkGear Connector
5#
6# Copyright Puzzlebox Productions, LLC (2010)
7#
8# This code is released under the GNU Pulic License (GPL) version 2
9# For more information please refer to http://www.gnu.org/copyleft/gpl.html
10#
11# Last Update: 2010.06.16
12#
13#####################################################################
14
15import os, sys
16import simplejson as json
17
18from twisted.internet import reactor, protocol, defer
19
20import puzzlebox_brainstorms_configuration as configuration
21import puzzlebox_brainstorms_client as client
22
23#####################################################################
24# Globals
25#####################################################################
26
27DEBUG = 1
28
29SERVER_HOST = configuration.THINKGEAR_SERVER_HOST
30SERVER_PORT = configuration.THINKGEAR_SERVER_PORT
31
32MAX_CONNECTION_ATTEMPTS = configuration.MAX_CONNECTION_ATTEMPTS
33NO_REPLY_WAIT = configuration.NO_REPLY_WAIT
34
35AUTHORIZATION_REQUEST = configuration.THINKGEAR_AUTHORIZATION_REQUEST
36
37PARAMETERS = {"enableRawOutput": False, "format": "Json"}
38
39#####################################################################
40# Classes
41#####################################################################
42
43class puzzlebox_brainstorms_client_thinkgear(client.puzzlebox_brainstorms_client):
44       
45        def __init__(self, log, \
46                          authorization_request, \
47                          server_host=SERVER_HOST, \
48                          server_port=SERVER_PORT, \
49                          DEBUG=DEBUG):
50               
51                self.log = log
52                self.DEBUG=DEBUG
53               
54                self.authorization_request = authorization_request
55                self.server_host = server_host
56                self.server_port = server_port
57                self.max_connection_attempts = MAX_CONNECTION_ATTEMPTS
58       
59       
60        ##################################################################
61       
62        def send_command_and_print_response(self, command):
63
64                if self.DEBUG:
65                        print "---> [Client] Sending:",
66                        print command
67
68                       
69                d = self.send_command(command)
70                d.addCallback(self.print_response)
71       
72       
73        ##################################################################
74       
75        def print_response(self, response):
76               
77                if self.DEBUG:
78                        print "---> [Client] Server Response:",
79                        print response
80
81                reactor.stop()
82       
83
84#####################################################################
85# Main
86#####################################################################
87
88if __name__ == '__main__':
89       
90        #log = puzzlebox_logger.puzzlebox_logger(logfile='client')
91        log = None
92       
93        #authorization_request = AUTHORIZATION_REQUEST
94        authorization_request = None # Sending JSON not working
95       
96        #log.info("Command parameters: %s" % command_parameters)
97
98        thinkgear_client = puzzlebox_brainstorms_client_thinkgear( \
99                    log, \
100                    authorization_request, \
101                    server_host=SERVER_HOST, \
102                    server_port=SERVER_PORT, \
103                    DEBUG=DEBUG)
104
105        reactor.callWhenRunning( \
106                thinkgear_client.send_command_and_print_response, \
107                        thinkgear_client.authorization_request)
108
109
110        reactor.run()
111
Note: See TracBrowser for help on using the repository browser.