~opensos/opensos/pythonAutomation

« back to all changes in this revision

Viewing changes to PythonAutomation/SOSServer.py

  • Committer: slick666 at gmail
  • Date: 2012-04-29 15:42:40 UTC
  • Revision ID: slick666@gmail.com-20120429154240-bizt4qie3y8rpahp
cleaned up some comments and fixed some character encoding issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
        self.value = radians(degrees + ((minutes + (seconds / 60.0)) / 60.0))
81
81
        
82
82
    def __repr__(self):
 
83
        """Returns the sexagesimal (deg, min, sec) formated string"""
83
84
        sexagesimal = self.degrees()
84
85
        if sexagesimal[0] <0 or \
85
86
           sexagesimal[1] <0 or \
88
89
        else:
89
90
            direction = "E"
90
91
            
91
 
        return (str(abs(sexagesimal[0])) + "° " +  str(sexagesimal[1]) + "′ " +
 
92
        return (str(abs(sexagesimal[0])) + unichr(0x00B0) + " " +  str(sexagesimal[1]) + "' " +
92
93
                str(sexagesimal[2]) + "\" " + str(direction))
93
94
    
94
95
    def __print__(self):
 
96
        """Returns the sexagesimal (deg, min, sec) formated string"""
95
97
        return self.__repr__()
96
98
    
97
99
    def degrees(self):
 
100
        """Returns the sexagesimal (deg, min, sec) format in a list"""
98
101
        degree = degrees(self.value)
99
102
        minutes = (degrees%1) * 60
100
103
        seconds = (minues%1) * 60
102
105
        return [int(degree), int(minutes), seconds]
103
106
    
104
107
    def radians(self):
 
108
        """Returns the radian value"""
105
109
        return self.value
106
110
            
107
111
class Latitude(object):
135
139
        self.value = radians(degrees + ((minutes + (seconds / 60.0)) / 60.0))
136
140
        
137
141
    def __repr__(self):
 
142
        """Returns the sexagesimal (deg, min, sec) formated string"""
138
143
        sexagesimal = self.degrees()
139
144
        if sexagesimal[0] <0 or \
140
145
           sexagesimal[1] <0 or \
143
148
        else:
144
149
            direction = "N"
145
150
            
146
 
        return (str(abs(sexagesimal[0])) + "° " +  str(sexagesimal[1]) + "′ " +
 
151
        return (str(abs(sexagesimal[0])) + unichr(0x00B0) + " " +  str(sexagesimal[1]) + "' " +
147
152
                str(sexagesimal[2]) + "\" " + str(direction))
148
153
    
149
154
    def __print__(self):
 
155
        """Returns the sexagesimal (deg, min, sec) formated string"""
150
156
        return self.__repr__()
151
157
    
152
158
    def degrees(self):
 
159
        """Returns the sexagesimal (deg, min, sec) format in a list"""
153
160
        degree = degrees(self.value)
154
161
        minutes = (degree%1) * 60
155
162
        seconds = (minue%1) * 60
156
163
        return [int(degree), int(minutes), seconds]
157
164
    
158
165
    def radians(self):
 
166
        """Returns the radian value"""
159
167
        return self.value        
160
168
 
161
169
#Base Server where all communication arguments are set
166
174
                 host="localhost",
167
175
                 port=DEFAULT_PORT,
168
176
                 timeout=DEFAULT_TIMEOUT):
 
177
        """Base initializer"""
169
178
        self.telnetConnection = telnetlib.Telnet(host, port, timeout)
170
179
        self.version = None
171
180
 
173
182
             host="localhost",
174
183
             port=DEFAULT_PORT,
175
184
             timeout=DEFAULT_TIMEOUT):
 
185
        """Opens a new connection to the SOSServer.
 
186
        host: the hostname or ip address of the server
 
187
        port: the port number to connect on
 
188
        timeout: the timeout period for communications"""
 
189
        
 
190
        #TODO: handle case where the function is trying to open an already opend connection
176
191
        self.telnetConnection(host=host, port=port, timeout=timeout)
177
192
 
178
193
    def close(self):
 
194
        """Closes the connection to the SOSServer"""
179
195
        self.telnetConnection.close()
180
196
 
181
197
    def Command(self, command, arguments=None):
182
 
        commandString = command
 
198
        """The Command function takes telnet commands for the SOSServer and
 
199
        executes them
 
200
        command: a string representing the command
 
201
        arguments: an iterable containing all arguments in the order that they
 
202
                   need to appear"""
 
203
        
 
204
        commandString = str(command)
183
205
 
184
206
        for arg in arguments:
185
207
            commandString += " " + str(arg)