Skip to content

Commit

Permalink
celery command: Do not remove options from beginning (rather move to …
Browse files Browse the repository at this point in the history
…end)
  • Loading branch information
ask committed Nov 18, 2013
1 parent ba0bbb3 commit 25eb48a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
11 changes: 7 additions & 4 deletions celery/bin/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,16 +686,18 @@ def on_usage_error(self, exc, command=None):
self=self, command=command,
)))

def remove_options_at_beginning(self, argv, index=0):
def _relocate_args_from_start(self, argv, index=0):
if argv:
rest = []
while index < len(argv):
value = argv[index]
if value.startswith('--'):
pass
rest.append(value)
elif value.startswith('-'):
rest.extend([value] + [argv[index + 1]])
index += 1
else:
return argv[index:]
return argv[index:] + rest
index += 1
return []

Expand All @@ -706,7 +708,8 @@ def prepare_prog_name(self, name):

def handle_argv(self, prog_name, argv):
self.prog_name = self.prepare_prog_name(prog_name)
argv = self.remove_options_at_beginning(argv)
print('ARGV THEN IS: %r' % (argv, ))
argv = self._relocate_args_from_start(argv)
_, argv = self.prepare_args(None, argv)
try:
command = argv[0]
Expand Down
24 changes: 18 additions & 6 deletions celery/tests/bin/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,25 @@ def test_determine_exit_status(self):
self.assertEqual(determine_exit_status('true'), EX_OK)
self.assertEqual(determine_exit_status(''), EX_FAILURE)

def test_remove_options_at_beginning(self):
def test_relocate_args_from_start(self):
x = CeleryCommand(app=self.app)
self.assertEqual(x.remove_options_at_beginning(None), [])
self.assertEqual(x.remove_options_at_beginning(['-c 3', '--foo']), [])
self.assertEqual(x.remove_options_at_beginning(['--foo', '-c 3']), [])
self.assertEqual(x.remove_options_at_beginning(
['foo', '--foo=1']), ['foo', '--foo=1'])
self.assertEqual(x._relocate_args_from_start(None), [])
self.assertEqual(
x._relocate_args_from_start(
['-l', 'debug', 'worker', '-c', '3', '--foo'],
),
['worker', '-c', '3', '--foo', '-l', 'debug'],
)
self.assertEqual(
x._relocate_args_from_start(
['--pool=gevent', '-l', 'debug', 'worker', '--foo', '-c', '3'],
),
['worker', '--foo', '-c', '3', '--pool=gevent', '-l', 'debug'],
)
self.assertEqual(
x._relocate_args_from_start(['foo', '--foo=1']),
['foo', '--foo=1'],
)

def test_handle_argv(self):
x = CeleryCommand(app=self.app)
Expand Down

0 comments on commit 25eb48a

Please sign in to comment.