Browse Source

Rename optparse.make_option -> Option

Ask Solem 14 years ago
parent
commit
499d45cde2
3 changed files with 99 additions and 97 deletions
  1. 23 23
      celery/bin/celerybeat.py
  2. 67 66
      celery/bin/celeryd.py
  3. 9 8
      celery/bin/celeryev.py

+ 23 - 23
celery/bin/celerybeat.py

@@ -23,9 +23,10 @@
 
 """
 import sys
-import optparse
 import traceback
 
+from optparse import OptionParser, make_option as Option
+
 import celery
 from celery import beat
 from celery import conf
@@ -41,27 +42,26 @@ Configuration ->
 """.strip()
 
 OPTION_LIST = (
-    optparse.make_option('-s', '--schedule',
-            default=conf.CELERYBEAT_SCHEDULE_FILENAME,
-            action="store", dest="schedule",
-            help="Path to the schedule database. The extension \
-                    '.db' will be appended to the filename. Default: %s" % (
-                    conf.CELERYBEAT_SCHEDULE_FILENAME)),
-    optparse.make_option('--max-interval',
-            default=3600, type="int", dest="max_interval",
-            help="Maximum time to sleep between rechecking the schedule."),
-    optparse.make_option('-S', '--scheduler',
-            default=None,
-            action="store", dest="scheduler_cls",
-            help="Scheduler class. Default is "
-                 "celery.beat.PersistentScheduler"),
-    optparse.make_option('-f', '--logfile', default=conf.CELERYBEAT_LOG_FILE,
-            action="store", dest="logfile",
-            help="Path to log file."),
-    optparse.make_option('-l', '--loglevel',
-            default=conf.CELERYBEAT_LOG_LEVEL,
-            action="store", dest="loglevel",
-            help="Loglevel. One of DEBUG/INFO/WARNING/ERROR/CRITICAL."),
+    Option('-s', '--schedule',
+        default=conf.CELERYBEAT_SCHEDULE_FILENAME,
+        action="store", dest="schedule",
+        help="Path to the schedule database. The extension "
+             "'.db' will be appended to the filename. Default: %s" % (
+                    conf.CELERYBEAT_SCHEDULE_FILENAME, )),
+    Option('--max-interval',
+        default=3600, type="int", dest="max_interval",
+        help="Maximum time to sleep between re-reading the schedule."),
+    Option('-S', '--scheduler',
+        default=None,
+        action="store", dest="scheduler_cls",
+        help="Scheduler class. Default is celery.beat.PersistentScheduler"),
+    Option('-f', '--logfile', default=conf.CELERYBEAT_LOG_FILE,
+        action="store", dest="logfile",
+        help="Path to log file."),
+    Option('-l', '--loglevel',
+        default=conf.CELERYBEAT_LOG_LEVEL,
+        action="store", dest="loglevel",
+        help="Loglevel. One of DEBUG/INFO/WARNING/ERROR/CRITICAL."),
 )
 
 
@@ -141,7 +141,7 @@ class Beat(object):
 
 def parse_options(arguments):
     """Parse the available options to ``celeryd``."""
-    parser = optparse.OptionParser(option_list=OPTION_LIST)
+    parser = OptionParser(option_list=OPTION_LIST)
     options, values = parser.parse_args(arguments)
     return options
 

+ 67 - 66
celery/bin/celeryd.py

@@ -76,7 +76,9 @@ import platform as _platform
 import warnings
 import multiprocessing
 
-import celery
+from optparse import OptionParser, make_option as Option
+
+from celery import __version__
 from celery import conf
 from celery import signals
 from celery import platform
@@ -107,73 +109,73 @@ TASK_LIST_FMT = """    . tasks ->\n%s"""
 
 
 def dump_version(*args):
-    print("celeryd v%s" % celery.__version__)
+    print("celeryd v%s" % __version__)
     sys.exit(0)
 
 
 OPTION_LIST = (
-    optparse.make_option('-c', '--concurrency',
-            default=conf.CELERYD_CONCURRENCY,
-            action="store", dest="concurrency", type="int",
-            help="Number of child processes processing the queue."),
-    optparse.make_option('-V', '--version',
-            action="callback", callback=dump_version,
-            help="Show version information and exit."),
-    optparse.make_option('--purge', '--discard', default=False,
-            action="store_true", dest="discard",
-            help="Discard all waiting tasks before the server is started. "
-                 "WARNING: This is unrecoverable, and the tasks will be "
-                 "deleted from the messaging server."),
-    optparse.make_option('-f', '--logfile', default=conf.CELERYD_LOG_FILE,
-            action="store", dest="logfile",
-            help="Path to log file."),
-    optparse.make_option('-l', '--loglevel', default=conf.CELERYD_LOG_LEVEL,
-            action="store", dest="loglevel",
-            help="Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL/FATAL."),
-    optparse.make_option('-n', '--hostname', default=None,
-            action="store", dest="hostname",
-            help="Set custom host name. E.g. 'foo.example.com'."),
-    optparse.make_option('-B', '--beat', default=False,
-            action="store_true", dest="run_clockservice",
-            help="Also run the celerybeat periodic task scheduler. \
-                  Please note that only one instance must be running."),
-    optparse.make_option('-s', '--schedule',
-            default=conf.CELERYBEAT_SCHEDULE_FILENAME,
-            action="store", dest="schedule",
-            help="Path to the schedule database if running with the -B \
-                    option. The extension '.db' will be appended to the \
-                    filename. Default: %s" % (
-                    conf.CELERYBEAT_SCHEDULE_FILENAME)),
-    optparse.make_option('-S', '--statedb', default=conf.CELERYD_STATE_DB,
-            action="store", dest="db",
-            help="Path to the state database. The extension '.db' will \
-                 be appended to the filename. Default: %s" % (
-                     conf.CELERYD_STATE_DB)),
-    optparse.make_option('-E', '--events', default=conf.SEND_EVENTS,
-            action="store_true", dest="events",
-            help="Send events so celery can be monitored by e.g. celerymon."),
-    optparse.make_option('--time-limit',
-            default=conf.CELERYD_TASK_TIME_LIMIT,
-            action="store", type="int", dest="task_time_limit",
-            help="Enables a hard time limit (in seconds) for tasks."),
-    optparse.make_option('--soft-time-limit',
-            default=conf.CELERYD_TASK_SOFT_TIME_LIMIT,
-            action="store", type="int", dest="task_soft_time_limit",
-            help="Enables a soft time limit (in seconds) for tasks."),
-    optparse.make_option('--maxtasksperchild',
-            default=conf.CELERYD_MAX_TASKS_PER_CHILD,
-            action="store", type="int", dest="max_tasks_per_child",
-            help="Maximum number of tasks a pool worker can execute"
-                 "before it's terminated and replaced by a new worker."),
-    optparse.make_option('--queues', '-Q', default=[],
-            action="store", dest="queues",
-            help="Comma separated list of queues to enable for this worker. "
-                 "By default all configured queues are enabled. "
-                 "Example: -Q video,image"),
-    optparse.make_option('--include', '-I', default=[],
-            action="store", dest="include",
-            help="Comma separated list of additional modules to import. "
-                 "Example: -I foo.tasks,bar.tasks"),
+    Option('-c', '--concurrency',
+        default=conf.CELERYD_CONCURRENCY,
+        action="store", dest="concurrency", type="int",
+        help="Number of child processes processing the queue."),
+    Option('-V', '--version',
+        action="callback", callback=dump_version,
+        help="Show version information and exit."),
+    Option('--purge', '--discard', default=False,
+        action="store_true", dest="discard",
+        help="Discard all waiting tasks before the server is started. "
+             "WARNING: This is unrecoverable, and the tasks will be "
+             "deleted from the messaging server."),
+    Option('-f', '--logfile', default=conf.CELERYD_LOG_FILE,
+        action="store", dest="logfile",
+        help="Path to log file."),
+    Option('-l', '--loglevel', default=conf.CELERYD_LOG_LEVEL,
+        action="store", dest="loglevel",
+        help="Choose between DEBUG/INFO/WARNING/ERROR/CRITICAL/FATAL."),
+    Option('-n', '--hostname', default=None,
+        action="store", dest="hostname",
+        help="Set custom host name. E.g. 'foo.example.com'."),
+    Option('-B', '--beat', default=False,
+        action="store_true", dest="run_clockservice",
+        help="Also run the celerybeat periodic task scheduler. "
+             "Please note that only one instance of celerybeat should be "
+             "running at any one time."),
+    Option('-s', '--schedule',
+        default=conf.CELERYBEAT_SCHEDULE_FILENAME,
+        action="store", dest="schedule",
+        help="Path to the schedule database if running with the -B \
+              option. The extension '.db' will be appended to the \
+              filename. Default: %s" % conf.CELERYBEAT_SCHEDULE_FILENAME),
+    Option('-S', '--statedb', default=conf.CELERYD_STATE_DB,
+        action="store", dest="db",
+        help="Path to the state database. The extension '.db' will "
+             "be appended to the filename. Default: %s" % (
+                        conf.CELERYD_STATE_DB, )),
+    Option('-E', '--events', default=conf.SEND_EVENTS,
+        action="store_true", dest="events",
+        help="Send events so celery can be monitored by e.g. celerymon."),
+    Option('--time-limit',
+        default=conf.CELERYD_TASK_TIME_LIMIT,
+        action="store", type="int", dest="task_time_limit",
+        help="Enables a hard time limit (in seconds) for tasks."),
+    Option('--soft-time-limit',
+        default=conf.CELERYD_TASK_SOFT_TIME_LIMIT,
+        action="store", type="int", dest="task_soft_time_limit",
+        help="Enables a soft time limit (in seconds) for tasks."),
+    Option('--maxtasksperchild',
+        default=conf.CELERYD_MAX_TASKS_PER_CHILD,
+        action="store", type="int", dest="max_tasks_per_child",
+        help="Maximum number of tasks a pool worker can execute"
+             "before it's terminated and replaced by a new worker."),
+    Option('--queues', '-Q', default=[],
+        action="store", dest="queues",
+        help="Comma separated list of queues to enable for this worker. "
+             "By default all configured queues are enabled. "
+             "Example: -Q video,image"),
+    Option('--include', '-I', default=[],
+        action="store", dest="include",
+        help="Comma separated list of additional modules to import. "
+             "Example: -I foo.tasks,bar.tasks"),
 )
 
 
@@ -219,8 +221,7 @@ class Worker(object):
         self.init_queues()
         self.worker_init()
         self.redirect_stdouts_to_logger()
-        print("celery@%s v%s is starting." % (self.hostname,
-                                              celery.__version__))
+        print("celery@%s v%s is starting." % (self.hostname, __version__))
 
         if getattr(self.settings, "DEBUG", False):
             warnings.warn("Using settings.DEBUG leads to a memory leak, "

+ 9 - 8
celery/bin/celeryev.py

@@ -1,29 +1,30 @@
 import logging
-import optparse
 import sys
 
+from optparse import OptionParser, make_option as Option
+
 from celery.events.cursesmon import evtop
 from celery.events.dumper import evdump
 from celery.events.snapshot import evcam
 
 
 OPTION_LIST = (
-    optparse.make_option('-d', '--dump',
+    Option('-d', '--dump',
         action="store_true", dest="dump",
         help="Dump events to stdout."),
-    optparse.make_option('-c', '--camera',
+    Option('-c', '--camera',
         action="store", dest="camera",
         help="Camera class to take event snapshots with."),
-    optparse.make_option('-F', '--frequency', '--freq',
+    Option('-F', '--frequency', '--freq',
         action="store", dest="frequency", type="float", default=1.0,
         help="Recording: Snapshot frequency."),
-    optparse.make_option('-r', '--maxrate',
+    Option('-r', '--maxrate',
         action="store", dest="maxrate", default=None,
         help="Recording: Shutter rate limit (e.g. 10/m)"),
-    optparse.make_option('-l', '--loglevel',
+    Option('-l', '--loglevel',
         action="store", dest="loglevel", default="WARNING",
         help="Loglevel. Default is WARNING."),
-    optparse.make_option('-f', '--logfile',
+    Option('-f', '--logfile',
         action="store", dest="logfile", default=None,
         help="Log file. Default is <stderr>"),
 )
@@ -41,7 +42,7 @@ def run_celeryev(dump=False, camera=None, frequency=1.0, maxrate=None,
 
 def parse_options(arguments):
     """Parse the available options to ``celeryev``."""
-    parser = optparse.OptionParser(option_list=OPTION_LIST)
+    parser = OptionParser(option_list=OPTION_LIST)
     options, values = parser.parse_args(arguments)
     return options