ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/WEBTOOLS/cmsWeb.py
(Generate patch)

Comparing COMP/WEBTOOLS/cmsWeb.py (file contents):
Revision 1.6 by eulisse, Thu Jan 31 18:08:33 2008 UTC vs.
Revision 1.7 by eulisse, Mon Mar 3 11:52:39 2008 UTC

# Line 15 | Line 15 | class Cfg:
15          self.installRoot = __file__.rsplit ("/", 1)[0]
16  
17   class CommandFactory (object):
18 <    def __init__ (self, context):
18 >    def __init__ (self, context, opts, args):
19          self.context = context
20          self.registry = {"start": StartCommand,
21                           "status": StatusCommand,
22                           "stop": StopCommand}
23 <        self.opts, self.args = self.context.OptionParser ().parse_args ()
23 >        self.opts, self.args = opts, args
24      
25      def createByName (self, name):
26          try:
# Line 73 | Line 73 | class StatusCommand (Command):
73   class StopCommand (Command):
74      def run (self):
75          filename = abspath (self.opts.pidFile)
76 <        username = getpass.getuser()
76 >        username = getpass.getuser ()
77          
78          try:
79              pid = getPidFromFile (filename)
# Line 98 | Line 98 | class StopCommand (Command):
98   class StartCommand (Command):
99      def run (self):
100          app = BonsaiServer (self.context)
101 +        opts, args = self.context.OptionParser ().parse_args ()
102          filename = abspath (self.opts.pidFile)
103          try:
104              pid = getPidFromFile (filename)
# Line 112 | Line 113 | class StartCommand (Command):
113              print "File %s does not exists. Will be created." % filename
114          
115          open (filename, 'w').write (str (os.getpid ()))
116 <        self.context.addService (CmdLineArgs (context.OptionParser ()))
116 >        self.context.addService (CmdLineArgs (self.context.OptionParser ()))
117          self.context.addService (Cfg ())
118          if opts.profile:
119              import pstats
# Line 138 | Line 139 | def getValidOptions (args):
139      validArguments = ["start",
140                        "stop",
141                        "restart"]
142 <    validOptions = ["--cfg"]
142 >    validOptions = ["--cfg", "--force-kill", "--pid-file"]
143  
144      result = []
145      for i in range (0, len (args)):
# Line 151 | Line 152 | def getValidOptions (args):
152          if option in validOptions:
153              result.append (option)
154              result.append (args[i+1])
155 +    return result
156  
157 < if __name__ == '__main__':
158 <    context = Context ()
159 <    context.addService (OptionParser ())
160 <    parser = context.OptionParser ()
161 <    parser.add_option ("--profile",
162 <                       help="start server in profiler mode",
161 <                       default=False,
162 <                       action="store_true",
163 <                       dest="profile")
164 <    def stripTrailingSlash (option, opt_str, value, parser, *args, **kwargs):
165 <        setattr(parser.values, option.dest, value.rstrip ("/"))
157 > class CmsWebApplication (object):
158 >    def __init__ (self):
159 >        self.context = Context ()
160 >        self.context.addService (OptionParser ())
161 >        self.parser = self.context.OptionParser ()
162 >        self.__addOptions ()
163          
164 <    parser.add_option ("--base-url",
165 <                       help="Base URL for the server (for usage behind a proxy).",
166 <                       default="http://localhost:8030",
167 <                       dest="baseUrl",
168 <                       action="callback",
169 <                       callback=stripTrailingSlash,
170 <                       type="str",
171 <                       nargs=1)
164 >    def __addOptions (self):
165 >        self.parser.add_option ("--profile",
166 >                           help="start server in profiler mode",
167 >                           default=False,
168 >                           action="store_true",
169 >                           dest="profile")
170 >
171 >        self.parser.add_option ("--pid-file",
172 >                           help="File in which it is specified the pid of wanted instance",
173 >                           default="pid.txt",
174 >                           dest="pidFile",
175 >                           metavar="FILE")
176 >
177 >        self.parser.add_option ("--force-kill",
178 >                           help="Uses SIGKILL rather than SIGTERM",
179 >                           default=False,
180 >                           action="store_true",
181 >                           dest="forceKill",
182 >                           metavar="FILE")
183      
184 <    parser.add_option ("--pid-file",
185 <                       help="File in which it is specified the pid of wanted instance",
178 <                       default="pid.txt",
179 <                       dest="pidFile",
180 <                       metavar="FILE")
181 <
182 <    parser.add_option ("--force-kill",
183 <                       help="Uses SIGKILL rather than SIGTERM",
184 <                       default=False,
185 <                       action="store_true",
186 <                       dest="forceKill",
187 <                       metavar="FILE")
184 >    def run (self):
185 >        validOptions = getValidOptions (sys.argv)
186  
187 +        print "parse"
188 +        opts, args = self.parser.parse_args (args=validOptions)
189 +        print opts, args
190 +        print "parsed"
191  
192 <    validOptions = getValidOptions (sys.argv)
193 <    
194 <    opts, args = parser.parse_args (args=validOptions)
195 <    if not len (args):
196 <        args = ["start"]
197 <    factory = CommandFactory (context)
198 <    startCommand = factory.createByName (args[0])
199 <    if not startCommand:
200 <        print "Command %s not known." % args[0]
201 <        sys.exit (1)
202 <    startCommand.run ()
203 <    startCommand.finish ()
192 >        if not len (args):
193 >            args = ["start"]
194 >        
195 >        factory = CommandFactory (self.context, opts, args)
196 >        startCommand = factory.createByName (args[0])
197 >        if not startCommand:
198 >            print "Command %s not known." % args[0]
199 >            sys.exit (1)
200 >        startCommand.run ()
201 >        startCommand.finish ()
202 >
203 > if __name__ == '__main__':
204 >    app = CmsWebApplication ()
205 >    app.run ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines