Commits

Shinya Okano committed c57b4f7

修正

Comments (0)

Files changed (3)

+#!/bin/bash
+
+export PYTHONPATH=`pwd`
+
+python skypelaunchd/server.py

skypelaunchd/launcher.py

     def launch_skype(self, username, password, dispnum):
         """skypeを起動する
         """
-        logging.info('launch skype username=%s, dispnum=%d' % (
+        logging.info('launch skype username=%s, dispnum=%s' % (
             username, dispnum))
         return_code = subprocess.call(
-            [self.get_script_path(), username, password, dispnum])
-        self.launched(username, password, dispnum, return_code)
+            [self.get_script_path(), username, password, str(dispnum)])
+        self.launched(username, dispnum, return_code)
         return return_code
 
     def launched(self, username, dispnum, return_code):

skypelaunchd/server.py

     def __call__(self, environ, start_response):
         """entry point
         """
-        http_method = environ.get('HTTP_METHOD')
+        http_method = environ.get('REQUEST_METHOD')
         path = environ.get('PATH_INFO')
         params = cgi.parse_qs(environ.get('QUERY_STRING', ''))
         self.dispatch(path, http_method, params, environ, start_response)
 
-    def dispatch(path, http_method, params, environ, start_response):
+    def dispatch(self, path, http_method, params, environ, start_response):
         if http_method != 'GET':
             return self.badrequest(start_response)
+        if path != '/':
+            return self.badrequest(start_response)
         username = params.get('username') and params['username'][0]
         password = params.get('password') and params['password'][0]
         dispnum = params.get('dispnum') and params['dispnum'][0]
+        try:
+            dispnum = int(dispnum)
+        except ValueError:
+            return self.badrequest(start_response)
         pid = self.launch(username, password, dispnum)
         return self.ok(pid, start_response)
 
         start_response('400 BadRequest', [
             ('Content-Type', 'application/json')
         ])
-        return '{"status": ""}'
+        return '{"status": "NG"}'