Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use argparse to handle commandline options

  • Loading branch information...
commit b5c384f17940176de81c28d3a30d16fff0b91c32 1 parent 7fee0d4
@wichert wichert authored
Showing with 12 additions and 17 deletions.
  1. +8 −14 pyramid_celery/celeryd.py
  2. +4 −3 setup.py
View
22 pyramid_celery/celeryd.py
@@ -1,25 +1,19 @@
#!/usr/bin/env python
-import os
-import sys
+import argparse
from celery.bin.celeryd import WorkerCommand
from pyramid.paster import bootstrap
from pyramid_celery import Celery
-def usage(argv):# pragma: no cover
- cmd = os.path.basename(argv[0])
- print('usage: %s <config_uri>\n'
- '(example: "%s development.ini")' % (cmd, cmd))
- sys.exit(1)
-def main(argv=sys.argv): # pragma: no cover
- if len(argv) != 2:
- usage(argv)
-
- config_uri = argv[1]
-
- env = bootstrap(config_uri)
+def main(): # pragma: no cover
+ parser = argparse.ArgumentParser(description='Celery worker daemon')
+ parser.add_argument('config', metavar='<ini-file>',
+ help='Configuration file (and optionally section)')
+ options = parser.parse_args()
+ env = bootstrap(options.config)
worker = WorkerCommand(app=Celery(env))
worker.run()
+
if __name__ == "__main__": # pragma: no cover
main()
View
7 setup.py
@@ -1,5 +1,5 @@
import os
-
+import sys
from setuptools import setup, find_packages
here = os.path.abspath(os.path.dirname(__file__))
@@ -7,9 +7,11 @@
CHANGES = open(os.path.join(here, 'CHANGES.txt')).read()
requires = ['pyramid', 'celery']
+if sys.version_info < (2, 7):
+ requires.append('argparse')
setup(name='pyramid_celery',
- version='0.0',
+ version='1.0dev',
description='Celery integration with pyramid',
long_description=README + '\n\n' + CHANGES,
classifiers=[
@@ -35,4 +37,3 @@
pceleryd = pyramid_celery.celeryd:main
""",
)
-
Please sign in to comment.
Something went wrong with that request. Please try again.