Commits

Shinya Okano committed 3fa4b08

最初のコミット

Comments (0)

Files changed (6)

+syntax: glob
+*.pyc
+*.swp
+*.orig
Add a comment to this file

skypelaunchd/__init__.py

Empty file added.

skypelaunchd/launch_skype

+#!/bin/bash
+
+USERNAME=$1
+PASSWORD=$2
+DAEMON_USER=skype
+PROGNAME=`basename $0`
+PIDFILE=/var/run/skype/$USERNAME.pid
+XSERVERNUM=$3
+XAUTHFILE=/var/run/skype/Xauthority
+LOGFILE=/var/log/skype/error.log
+DBPATH=/srv/skype/conf
+XAUTHPROTO=.
+SKYPE=/usr/bin/skype
+
+
+sudo -u "$DAEMON_USER" env XAUTHORITY=$XAUTHFILE sh -c "xauth add \":$XSERVERNUM\" \"$XAUTHPROTO\" \"$MCOOKIE\" >> \"$LOGFILE\" 2>&1" && \
+sudo -u "$DAEMON_USER" env XAUTHORITY=$XAUTHFILE sh -c "Xvfb :$XSERVERNUM -screen 0 800x600x8 -nolisten tcp >> \"$LOGFILE\" 2>&1 & echo \$!" >"$PIDFILE" &&
+sleep 3 && \
+(sudo -u "$DAEMON_USER" env DISPLAY=:$XSERVERNUM XAUTHORITY=$XAUTHFILE SKYPE="$SKYPE" sh -c "echo \"$USERNAME $PASSWORD\" | nohup \"$SKYPE\" --dbpath=\"$DBPATH\" --pipelogin &") >> "$LOGFILE" 2>&1

skypelaunchd/launcher.py

+# coding: utf-8
+import os
+import logging
+import subprocess
+
+SCRIPT_NAME = 'launch_skype'
+PIDFILE = '/var/run/skype/%s.pid'
+
+
+class Launcher(object):
+    def __init__(self):
+        self.notifiers = []
+
+    def get_script_path(self):
+        """起動スクリプトのパスを返す
+        """
+        base_dir = os.path.dirname(os.path.abspath(__file__))
+        return os.path.join(base_dir, SCRIPT_NAME)
+
+    def get_pid_file_path(self, username):
+        """pidfileのパス
+        """
+        return PIDFILE % username
+
+    def connect_notifier(self, notifier):
+        """通知を追加
+        """
+        self.notifiers.append(notifier)
+
+    def launch_skype(self, username, password, dispnum):
+        """skypeを起動する
+        """
+        logging.info('launch skype username=%s, dispnum=%d' % (
+            username, dispnum))
+        return_code = subprocess.call(
+            [self.get_script_path(), username, password, dispnum])
+        self.launched(username, password, dispnum, return_code)
+        return return_code
+
+    def launched(self, username, dispnum, return_code):
+        """通知
+        """
+        for notifier in self.notifiers:
+            notifier(username, dispnum, return_code,
+                self.get_pid_file_path(username))

skypelaunchd/notifier.py

+# coding: utf-8
+import time
+import logging
+
+def logging_notifier(username, dispnum, return_code, pidpath):
+    """logging
+    """
+    try:
+        f = open(pidpath)
+        pid = int(f.read())
+    except IOError:
+        pid = None
+    logging.info('[%s]username=%s, dispnum=%s, pid=%s, ' % (
+        time.localtime(),
+        dispnum,
+        pid)

skypelaunchd/server.py

+# coding: utf-8
+import cgi
+from optparse import OptionParser
+from wsgiref import simple_server
+
+from skypelaunchd.launcher import Launcher
+
+
+class Application(object):
+    def __init__(self):
+        self.launcher = Launcher()
+
+    def __call__(self, environ, start_response):
+        """entry point
+        """
+        http_method = environ.get('HTTP_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):
+        if http_method != 'GET':
+            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]
+        pid = self.launch(username, password, dispnum)
+        return self.ok(pid, start_response)
+
+    def launch(self, username, password, dispnum):
+        """skype起動
+        """
+        return_code = self.launcher.launch_skype(username, password, dispnum)
+        pidpath = self.launcher.get_pid_file_path(username)
+        try:
+            f = open(pidpath)
+            pid = int(f.read())
+        except IOError:
+            pid = None
+        return pid
+
+    def ok(self, pid, start_response):
+        start_response('200 OK', [
+            ('Content-Type', 'application/json')
+        ])
+        return '{"status": "OK"}'
+
+    def badrequest(self, start_response):
+        start_response('400 BadRequest', [
+            ('Content-Type', 'application/json')
+        ])
+        return '{"status": ""}'
+
+
+
+def run(host, port, app):
+    server = simple_server.make_server(host, port, app)
+    server.serve_forever()
+
+
+if __name__ == '__main__':
+    parser = OptionParser()
+    parser.add_option('--host', dest='host', default='localhost', help='hostname')
+    parser.add_option('--port', dest='port', default=4300,
+        type='int', help='port number')
+
+    options, args = parser.parse_args()
+
+    app = Application()
+
+    print "Serving skype-launchd on", options.host, "port", options.port, "..."
+
+    run(options.host, options.port, app)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.