~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/scripts/_twistw.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- test-case-name: twisted.test.test_twistd -*-
 
2
# Copyright (c) 2001-2008 Twisted Matrix Laboratories.
 
3
# See LICENSE for details.
 
4
 
 
5
from twisted.python import log
 
6
from twisted.application import app, service, internet
 
7
from twisted import copyright
 
8
import sys, os
 
9
 
 
10
 
 
11
 
 
12
class ServerOptions(app.ServerOptions):
 
13
    synopsis = "Usage: twistd [options]"
 
14
 
 
15
    optFlags = [['nodaemon','n',  "(for backwards compatability)."],
 
16
                ]
 
17
 
 
18
    def opt_version(self):
 
19
        """Print version information and exit.
 
20
        """
 
21
        print 'twistd (the Twisted Windows runner) %s' % copyright.version
 
22
        print copyright.copyright
 
23
        sys.exit()
 
24
 
 
25
 
 
26
 
 
27
class WindowsApplicationRunner(app.ApplicationRunner):
 
28
    """
 
29
    An ApplicationRunner which avoids unix-specific things. No
 
30
    forking, no PID files, no privileges.
 
31
    """
 
32
 
 
33
    def preApplication(self):
 
34
        """
 
35
        Do pre-application-creation setup.
 
36
        """
 
37
        self.oldstdout = sys.stdout
 
38
        self.oldstderr = sys.stderr
 
39
        os.chdir(self.config['rundir'])
 
40
 
 
41
 
 
42
    def postApplication(self):
 
43
        """
 
44
        Start the application and run the reactor.
 
45
        """
 
46
        service.IService(self.application).privilegedStartService()
 
47
        app.startApplication(self.application, not self.config['no_save'])
 
48
        app.startApplication(internet.TimerService(0.1, lambda:None), 0)
 
49
        self.startReactor(None, self.oldstdout, self.oldstderr)
 
50
        log.msg("Server Shut Down.")