Commits

Anonymous committed 0a7df9d

Fixed some typos, factored out CeleryCommand base class.

Comments (0)

Files changed (1)

celerypylons/commands.py

 
 ## @@ We have to do some rather odd bootstrapping in order to get
 ## celery to load correctly.
-try:
-    path_to_ini_file = os.path.realpath(sys.argv[2])
-    conf = paste.deploy.appconfig('config:' + path_to_ini_file)
-    config.init_app(conf.global_conf,conf.local_conf)
-    if os.environ.get('CELERY_CONFIG_MODULE', None) is not None:
-        warnings.warn("'CELERY_CONFIG_MODULE' environment variable is already set but will be overridden by celery-pylons.")
-except ValueError:
-    ## @@ If the user just wants to see usage or docs, don't fail on configuration
-    pass
-except IndexError:
-    ## @@ No configuration was passed in
-    pass
-os.environ['CELERY_CONFIG_MODULE'] = 'celerypylons.config'
-
+def bootstrap_config():
+    try:
+        path_to_ini_file = os.path.realpath(sys.argv[2])
+        conf = paste.deploy.appconfig('config:' + path_to_ini_file)
+        config.init_app(conf.global_conf,conf.local_conf)
+        if os.environ.get('CELERY_CONFIG_MODULE', None) is not None:
+            warnings.warn("'CELERY_CONFIG_MODULE' environment variable is already set but will be overridden by celery-pylons.")
+    except ValueError:
+        ## @@ If the user just wants to see usage or docs, don't fail on configuration
+        pass
+    except IndexError:
+        ## @@ No configuration was passed in
+        pass
+    os.environ['CELERY_CONFIG_MODULE'] = 'celerypylons.config'
+bootstrap_config()
 
 ## @@ We can now import celeryd since the configuration has been set.
 try:
     import dummy as celeryev
 
 
-class CeleryDaemonCommand(Command):
+class CeleryCommand(Command):
+    min_args = 1
+    min_args_error = "Please provide a paster config file as an argument."
+    takes_config_file = 1
+    requires_config_file = True
+
+
+class CeleryDaemonCommand(CeleryCommand):
     """Start the celery worker
 
     Starts the celery worker that uses a paste.deploy configuration
     file.
     """
-    min_args = 1
-    min_args_error = "Please provide a paster config file as an argument."
     usage = 'CONFIG_FILE [celeryd options...]'
-    takes_config_file = 1
     summary = __doc__.splitlines()[0]
     description = "".join(__doc__.splitlines()[2:])
-    requires_config_file = True
 
     parser = Command.standard_parser(quiet=True)
     for x in celeryd.OPTION_LIST:
         return celeryd.run_worker(**vars(options))
 
 
-class CeleryBeatCommand(Command):
+class CeleryBeatCommand(CeleryCommand):
     """Start the celery beat server
 
     Starts the celery beat server using a paste.deploy configuration
     file.
     """
-    min_args = 1
-    min_args_error = "Please provide a paster config file as an argument."
     usage = 'CONFIG_FILE [celerybeat options...]'
-    takes_config_file = 1
     summary = __doc__.splitlines()[0]
     description = "".join(__doc__.splitlines()[2:])
-    requires_config_file = True
 
     parser = Command.standard_parser(quiet=True)
     for x in celerybeat.OPTION_LIST:
         return celerybeat.run_celerybeat(**vars(options))
 
 
-class CAMQPAdminCommand(Command):
+class CAMQPAdminCommand(CeleryCommand):
     """CAMQP Admin
 
     CAMQP celery admin tool.
     """
-    min_args = 1
-    min_args_error = "Please provide a paster config file as an argument."
     usage = 'CONFIG_FILE [camqadm options...]'
-    takes_config_file = 1
     summary = __doc__.splitlines()[0]
     description = "".join(__doc__.splitlines()[2:])
-    requires_config_file = True
 
     parser = Command.standard_parser(quiet=True)
     for x in camqadm.OPTION_LIST:
         return camqadm.camqadm(*values, **vars(options))
 
     
-class CeleryEventCommand(Command):
+class CeleryEventCommand(CeleryCommand):
     """Celery event commandd.
 
     Capture celery events.
     """
-    min_args = 1
-    min_args_error = "Please provide a paster config file as an argument."
-    usage = 'CONFIG_FILE [camqadm options...]'
-    takes_config_file = 1
+    usage = 'CONFIG_FILE [celeryev options...]'
     summary = __doc__.splitlines()[0]
     description = "".join(__doc__.splitlines()[2:])
-    requires_config_file = True
 
     parser = Command.standard_parser(quiet=True)
     for x in celeryev.OPTION_LIST: