Commits

ianschenck  committed dfbec81

Tidied up the parser stuff, got help messages working if a config file is passed in. Next is probably to make a dummy config to allow help messages to be displayed without a working config file.

  • Participants
  • Parent commits 521e7ea

Comments (0)

Files changed (2)

File celerypylons/commands.py

     takes_config_file = 1
     requires_config_file = True
 
-    def bootstrap_config(self):
-        path_to_ini_file = os.path.realpath(self.args[0])
+    def run(self, args):
+        if len(args) < self.min_args:
+            raise BadCommand(
+                self.min_args_error % {'min_args': self.min_args,
+                                       'actual_args': len(args)})            
+        self.bootstrap_config(args[0])
+        self.update_parser()
+        return super(CeleryCommand, self).run(args)
+
+    def update_parser(self):
+        raise NotImplemented("Abstract Method.")
+
+    def bootstrap_config(self, conf):
+        path_to_ini_file = os.path.realpath(conf)
         conf = paste.deploy.appconfig('config:' + path_to_ini_file)
         config.init_app(conf.global_conf,conf.local_conf)
 
     description = "".join(__doc__.splitlines()[2:])
 
     parser = Command.standard_parser(quiet=True)
-        
-    def command(self):
-        self.bootstrap_config()
+
+    def update_parser(self):
         from celery.bin import celeryd
         for x in celeryd.OPTION_LIST:
             self.parser.add_option(x)
-        options = celeryd.parse_options(sys.argv[1:])
-        return celeryd.run_worker(**vars(options))
+
+    def command(self):
+        from celery.bin import celeryd
+        return celeryd.run_worker(**vars(self.options))
 
 
 class CeleryBeatCommand(CeleryCommand):
     description = "".join(__doc__.splitlines()[2:])
 
     parser = Command.standard_parser(quiet=True)
+
+    def update_parser(self):
+        from celery.bin import celerybeat
+        for x in celerybeat.OPTION_LIST:
+            self.parser.add_option(x)        
         
     def command(self):
-        self.bootstrap_config()
         from celery.bin import celerybeat
-        for x in celerybeat.OPTION_LIST:
-            self.parser.add_option(x)
-        options = celerybeat.parse_options(self.args[1:])
-        return celerybeat.run_celerybeat(**vars(options))
+        return celerybeat.run_celerybeat(**vars(self.options))
 
 
 class CAMQPAdminCommand(CeleryCommand):
     description = "".join(__doc__.splitlines()[2:])
 
     parser = Command.standard_parser(quiet=True)
-        
-    def command(self):
-        self.bootstrap_config()
+    
+    def update_parser(self):
         from celery.bin import camqadm
         for x in camqadm.OPTION_LIST:
             self.parser.add_option(x)
-        options, values = camqadm.parse_options(self.args[1:])
-        return camqadm.camqadm(*values, **vars(options))
+
+    def command(self):
+        from celery.bin import camqadm
+        return camqadm.camqadm(*self.args[1:], **vars(self.options))
 
     
 class CeleryEventCommand(CeleryCommand):
     description = "".join(__doc__.splitlines()[2:])
 
     parser = Command.standard_parser(quiet=True)
-        
-    def command(self):
-        self.bootstrap_config()
+
+    def update_parser(self):
         from celery.bin import celeryev
         for x in celeryev.OPTION_LIST:
             self.parser.add_option(x)
-        options = celeryev.parse_options(self.args[1:])
-        return celeryev.run_celeryev(**vars(options))
+
+    def command(self):
+        from celery.bin import celeryev
+        return celeryev.run_celeryev(**vars(self.options))

File celerypylons/dummy.py

-OPTION_LIST = []