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.7 by eulisse, Mon Mar 3 11:52:39 2008 UTC vs.
Revision 1.9 by eulisse, Tue Mar 4 11:59:34 2008 UTC

# Line 1 | Line 1
1   #!/usr/bin/env python
2   from Framework import BonsaiServer
3   from Framework import Context
4 + from Framework.Logger import Logger
5 + from Framework.Logger import g_Logger
6   from optparse import OptionParser
7   from Framework import CmdLineArgs
8   import sys
# Line 90 | Line 92 | class StopCommand (Command):
92              else:
93                  print "Pid %s does not exists. Please remove the lock file %s." % (pid, filename)
94          except IOError:
95 <            print "File %s does not exists." % opts.pidFile
95 >            print "File %s does not exists." % self.opts.pidFile
96              print "Cannot detect status."
97              sys.exit (2)
98          
# Line 110 | Line 112 | class StartCommand (Command):
112                  os.unlink (filename)
113          except IOError:
114              # TODO: this should be a warning.
115 <            print "File %s does not exists. Will be created." % filename
115 >            g_Logger.trace ("File %s does not exists. Will be created." % filename)
116          
117          open (filename, 'w').write (str (os.getpid ()))
118          self.context.addService (CmdLineArgs (self.context.OptionParser ()))
# Line 139 | Line 141 | def getValidOptions (args):
141      validArguments = ["start",
142                        "stop",
143                        "restart"]
144 <    validOptions = ["--cfg", "--force-kill", "--pid-file"]
144 >    validOptions = ["--cfg", "--force-kill", "--pid-file",
145 >                    "--log-file", "--log-level"]
146  
147      result = []
148      for i in range (0, len (args)):
# Line 180 | Line 183 | class CmsWebApplication (object):
183                             action="store_true",
184                             dest="forceKill",
185                             metavar="FILE")
186 +                          
187 +        def openFilename (option, opt_str, value, parser, *args, **kwargs):
188 +            try:
189 +                f=open (value, 'a')
190 +            except IOError:
191 +                print "WARNING: Unable to open log file %s. Using stderr." % value
192 +                f=sys.stderr
193 +            setattr (parser.values, option.dest, f)
194 +        
195 +        self.parser.add_option ("--log-file",
196 +                           help="FILE to which redirect log messages",
197 +                           dest="logFile",
198 +                           default=sys.stderr,
199 +                           action="callback",
200 +                           callback=openFilename,
201 +                           metavar="FILENAME",
202 +                           type="str",
203 +                           nargs=1)
204 +                          
205 +        self.parser.add_option ("--log-level",
206 +                            help="detail LEVEL for the main log",
207 +                            dest="logLevel",
208 +                            default=10,
209 +                            metavar="LEVEL",
210 +                            type="int")
211      
212      def run (self):
213 +        if "--help" in sys.argv:
214 +            g_Logger.detailLevel = -100
215          validOptions = getValidOptions (sys.argv)
216  
187        print "parse"
217          opts, args = self.parser.parse_args (args=validOptions)
189        print opts, args
190        print "parsed"
218  
219 +        g_Logger.stream = opts.logFile
220 +        if "--help" not in sys.argv:
221 +            g_Logger.detailLevel = opts.logLevel
222 +        
223          if not len (args):
224              args = ["start"]
225          
226          factory = CommandFactory (self.context, opts, args)
227          startCommand = factory.createByName (args[0])
228          if not startCommand:
229 <            print "Command %s not known." % args[0]
229 >            "Command %s not known." % args[0]
230              sys.exit (1)
231          startCommand.run ()
232          startCommand.finish ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines