Ask Solem 9 лет назад
Родитель
Сommit
37c081ee07

+ 2 - 0
celery/app/defaults.py

@@ -185,6 +185,8 @@ NAMESPACES = Namespace(
         ),
         persistent=Option(None, type='bool'),
         serializer=Option('json'),
+
+        fspath=Option(None),
     ),
     riak=Namespace(
         __old__=old_ns('celery_riak'),

+ 20 - 14
celery/backends/filesystem.py

@@ -24,18 +24,26 @@ except NameError:
     FileNotFoundError = IOError
     IsADirectoryError = IOError
 
+E_PATH_INVALID = """\
+The configured path for the Filesystem backend does not
+work correctly, please make sure that it exists and has
+the correct permissions.\
+"""
+
 
 class FilesystemBackend(KeyValueStoreBackend):
+
     def __init__(self, url=None, open=open, unlink=os.unlink, sep=os.sep,
                  encoding=default_encoding, *args, **kwargs):
         """Initialize the filesystem backend.
 
         Keyword arguments (in addition to those of KeyValueStoreBackend):
-        url      -- URL to the directory we should use
-        open     -- open function to use when opening files
-        unlink   -- unlink function to use when deleting files
-        sep      -- directory seperator (to join the directory with the key)
-        encoding -- encoding used on the filesystem
+
+        :param url:  URL to the directory we should use
+        :param open: open function to use when opening files
+        :param unlink: unlink function to use when deleting files
+        :param sep: directory seperator (to join the directory with the key)
+        :param encoding: encoding used on the filesystem
 
         """
 
@@ -55,10 +63,11 @@ class FilesystemBackend(KeyValueStoreBackend):
     def _find_path(self, url):
         if url is not None and url.startswith('file:///'):
             return url[7:]
-        if hasattr(self.app.conf, 'CELERY_RESULT_FSPATH'):
-            return self.app.conf.CELERY_RESULT_FSPATH
-        raise ImproperlyConfigured(
-            'You need to configure a path for the Filesystem backend')
+        path = self.app.conf.result_fspath
+        if not path:
+            raise ImproperlyConfigured(
+                'You need to configure a path for the Filesystem backend')
+        return path
 
     def _do_directory_test(self, key):
         try:
@@ -66,10 +75,7 @@ class FilesystemBackend(KeyValueStoreBackend):
             assert self.get(key) == b'test value'
             self.delete(key)
         except IOError:
-            raise ImproperlyConfigured(
-                'The configured path for the Filesystem backend does not '
-                'work correctly, please make sure that it exists and has '
-                'the correct permissions.')
+            raise ImproperlyConfigured(E_PATH_INVALID)
 
     def _filename(self, key):
         return self.sep.join((self.path, key))
@@ -79,7 +85,7 @@ class FilesystemBackend(KeyValueStoreBackend):
             with self.open(self._filename(key), 'rb') as infile:
                 return infile.read()
         except FileNotFoundError:
-            return None
+            pass
 
     def set(self, key, value):
         with self.open(self._filename(key), 'wb') as outfile:

+ 13 - 7
celery/bin/celeryd_detach.py

@@ -56,6 +56,9 @@ class PartialOptionParser(OptionParser):
         self.leftovers = []
         OptionParser.__init__(self, *args, **kwargs)
 
+    def add_option_group(self, group):
+        self.option_list.extend(group.option_list)
+
     def _process_long_opt(self, rargs, values):
         arg = rargs.pop(0)
 
@@ -118,15 +121,18 @@ class detached_celeryd(object):
     def __init__(self, app=None):
         self.app = app
 
-    def Parser(self, prog_name):
-        return PartialOptionParser(prog=prog_name,
-                                   usage=self.usage,
-                                   description=self.description,
-                                   version=self.version)
+    def create_parser(self, prog_name):
+        p = PartialOptionParser(
+            prog=prog_name,
+            usage=self.usage,
+            description=self.description,
+            version=self.version,
+        )
+        self.prepare_arguments(p)
+        return p
 
     def parse_options(self, prog_name, argv):
-        parser = self.Parser(prog_name)
-        self.prepare_arguments(parser)
+        parser = self.create_parser(prog_name)
         options, values = parser.parse_args(argv)
         if options.logfile:
             parser.leftovers.append('--logfile={0}'.format(options.logfile))

+ 7 - 5
celery/tests/backends/test_filesystem.py

@@ -1,18 +1,20 @@
 # -*- coding: utf-8 -*-
 from __future__ import absolute_import
 
+import os
+import shutil
+import tempfile
+
 from celery import states
-from celery.tests.case import AppCase
 from celery.backends.filesystem import FilesystemBackend
 from celery.exceptions import ImproperlyConfigured
 from celery.utils import uuid
 
-import os
-import shutil
-import tempfile
+from celery.tests.case import AppCase
 
 
 class test_FilesystemBackend(AppCase):
+
     def setup(self):
         self.directory = tempfile.mkdtemp()
         self.url = 'file://' + self.directory
@@ -26,7 +28,7 @@ class test_FilesystemBackend(AppCase):
             FilesystemBackend(app=self.app)
 
     def test_a_path_in_app_conf(self):
-        self.app.conf.CELERY_RESULT_FSPATH = self.url[7:]
+        self.app.conf.result_fspath = self.url[7:]
         tb = FilesystemBackend(app=self.app)
         self.assertEqual(tb.path, self.path)
 

+ 1 - 1
celery/tests/bin/test_celery.py

@@ -575,7 +575,7 @@ class test_control(AppCase):
 class test_multi(AppCase):
 
     def test_get_options(self):
-        self.assertTupleEqual(multi(app=self.app).get_options(), ())
+        self.assertIsNone(multi(app=self.app).get_options())
 
     def test_run_from_argv(self):
         with patch('celery.bin.multi.MultiTool') as MultiTool:

+ 3 - 1
celery/tests/bin/test_celeryd_detach.py

@@ -56,11 +56,13 @@ class test_PartialOptionParser(AppCase):
 
     def test_parser(self):
         x = detached_celeryd(self.app)
-        p = x.Parser('celeryd_detach')
+        p = x.create_parser('celeryd_detach')
         options, values = p.parse_args([
             '--logfile=foo', '--fake', '--enable',
             'a', 'b', '-c1', '-d', '2',
         ])
+        print(p.option_list)
+        print('O: %r V: %r' % (vars(options), values))
         self.assertEqual(options.logfile, 'foo')
         self.assertEqual(values, ['a', 'b'])
         self.assertEqual(p.leftovers, ['--enable', '-c1', '-d', '2'])

+ 1 - 1
celery/tests/bin/test_events.py

@@ -64,7 +64,7 @@ class test_events(AppCase):
         self.assertTrue(evcam.called)
 
     def test_get_options(self):
-        self.assertTrue(self.ev.get_options())
+        self.assertFalse(self.ev.get_options())
 
     @_old_patch('celery.bin.events', 'events', MockCommand)
     def test_main(self):