-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ celery>=3.0.0 | |
chardet | ||
corenlp_xml | ||
cytoolz | ||
docopt | ||
elasticsearch>=1.2.0,<2.0.0 | ||
flask>=0.10.1 | ||
gensim | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ celery>=3.0.0 | |
chardet | ||
corenlp_xml | ||
cytoolz | ||
docopt | ||
elasticsearch>=1.2.0,<2.0.0 | ||
flask>=0.10.1 | ||
gensim | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
# Generate xtas configuration file. | ||
"""Generate xtas configuration file. | ||
Usage: | ||
make_config [-o file] | ||
if __name__ == '__main__': | ||
import argparse | ||
from os.path import abspath, dirname, join | ||
from shutil import copyfileobj | ||
import sys | ||
Options: | ||
-h, --help show this help message and exit | ||
-o file Write output to <file> [default: xtas_config.py]. | ||
""" | ||
|
||
from os.path import abspath, dirname, join | ||
from shutil import copyfileobj | ||
import sys | ||
|
||
from docopt import docopt | ||
|
||
parser = argparse.ArgumentParser(description= | ||
'Make xtas configuration file.') | ||
parser.add_argument('-o', dest='output', default='xtas_config.py') | ||
args = parser.parse_args() | ||
|
||
if __name__ == '__main__': | ||
args = docopt(__doc__) | ||
|
||
with open(join(dirname(__file__), '..', '_defaultconfig.py')) as default: | ||
print("Generating configuration file at %r" % args['-o']) | ||
# XXX in Python 3, we can make this safer by opening with 'x' | ||
with open(args.output, 'w') as out: | ||
with open(args['-o'], 'w') as out: | ||
copyfileobj(default, out) | ||
print("Generated configuration file at %r" % args.output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,52 @@ | ||
"""xtas worker | ||
Usage: | ||
xtas.worker [options] | ||
Options: | ||
-h, --help show this help message and exit | ||
--loglevel=LOGLEVEL Set minimum severity level of logger, e.g. DEBUG, | ||
ERROR, INFO. [default: WARNING]. | ||
--pidfile=PIDFILE Write PID of worker to PIDFILE (not removed at | ||
shutdown!). | ||
--version Print version info and exit. | ||
""" | ||
|
||
from __future__ import print_function | ||
|
||
from argparse import ArgumentParser | ||
import logging | ||
import os | ||
import sys | ||
|
||
from celery.bin.worker import worker | ||
from docopt import docopt | ||
|
||
from . import __version__ | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = ArgumentParser() | ||
parser.add_argument('--loglevel', dest='loglevel', default='WARN', | ||
help='Set minimum severity level of logger,' | ||
' e.g. DEBUG, ERROR, INFO. Default=WARNING.') | ||
parser.add_argument('--pidfile', dest='pidfile', | ||
help='Write PID of worker to PIDFILE' | ||
' (not removed at shutdown!).') | ||
parser.add_argument('--version', dest='version', const=True, | ||
action='store_const', | ||
help='Print version info and exit.') | ||
args = parser.parse_args() | ||
|
||
logging.basicConfig(level=args.loglevel.upper()) | ||
|
||
if args.pidfile is not None: | ||
args = docopt(__doc__) | ||
|
||
loglevel = args['--loglevel'].upper() | ||
logging.basicConfig(level=loglevel) | ||
|
||
pidfilepath = args.get('--pidfile') | ||
if pidfilepath is not None: | ||
# XXX use 'x' in Python 3 | ||
with open(args.pidfile, 'w') as pidfile: | ||
logging.info('Writing PID to %s' % args.pidfile) | ||
with open(pidfilepath, 'w') as pidfile: | ||
logging.info('Writing PID to %s' % pidfilepath) | ||
pidfile.write(str(os.getpid())) | ||
|
||
# This import must be done after we've parsed the cmdline args and set | ||
# the logging level. | ||
from .core import app | ||
|
||
if args.version: | ||
if args.get('--version'): | ||
print("xtas %s" % __version__) | ||
print("Celery", end=" ") | ||
app.worker_main(["--version"]) | ||
sys.exit() | ||
|
||
# XXX app.worker_main is prettier but doesn't seem to reply to --loglevel. | ||
w = worker(app=app) | ||
w.run(loglevel=args.loglevel) | ||
# XXX app.worker_main is prettier but doesn't seem to respond to --loglevel | ||
worker(app=app).run(loglevel=loglevel) |