@@ -21,7 +21,6 @@ import sys
2121import os
2222import argparse
2323import string
24- import unipath
2524import random
2625
2726
@@ -193,17 +192,6 @@ def check_redis_available():
193192 logln ("[OK]" )
194193
195194
196- def check_south_available ():
197- log ("+ Trying to import South module. " )
198-
199- try :
200- import south
201- except ImportError :
202- raise InstallError ()
203- else :
204- logln ("[OK]" )
205-
206-
207195def check_unidecode_available ():
208196 log ("+ Trying to import Unidecode module. " )
209197
@@ -588,10 +576,6 @@ sys.path.insert(0, '%(booki_path)s/')
588576
589577os.environ["DJANGO_SETTINGS_MODULE"] = "%(project_name)s_site.settings.%(profile)s"
590578
591- # Initialise celery
592- import djcelery
593- djcelery.setup_loader()
594-
595579# This application object is used by any WSGI server configured to use this
596580# file. This includes Django's development server, if the WSGI_APPLICATION
597581# setting points here.
@@ -609,6 +593,71 @@ application = get_wsgi_application()
609593 else :
610594 logln ("[OK]" )
611595
596+ def include_celery (destination ):
597+ log ("+ Import celery in {}_site __init__ file" .format (get_project_name (destination )))
598+ try :
599+ f = open ('%s/%s_site/__init__.py' % (destination , get_project_name (destination )), 'wt' )
600+ f .write ('''
601+ from __future__ import absolute_import, unicode_literals
602+
603+ # TODO we should have ability to change profile mode for celery
604+ # in general we need ENV-variables driven settings, but it will require bigger changes
605+ from .celery import app as celery_app
606+
607+ __all__ = ['celery_app']
608+
609+ ''' )
610+ f .close ()
611+ except OSError :
612+ raise InstallError ()
613+ else :
614+ logln ("[OK]" )
615+
616+
617+ def create_celery (destination ):
618+ log ("+ Creating celery.py file. " .format (profile ))
619+
620+ import booki
621+ booki_path = os .path .abspath (os .path .dirname (booki .__file__ ) + '/..' )
622+
623+ try :
624+ f = open ('%s/%s_site/celery.py' % (destination , get_project_name (destination )), 'wt' )
625+ f .write ('''
626+ from __future__ import absolute_import, unicode_literals
627+
628+ import os
629+ import sys
630+ from unipath import Path
631+ from celery import Celery
632+
633+ BASE_DIR = Path(os.path.abspath(__file__)).ancestor(2)
634+
635+ sys.path.insert(0, BASE_DIR)
636+ sys.path.insert(0, BASE_DIR.child("lib"))
637+ sys.path.insert(0, '{booki_path}')
638+
639+ os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{project_name}_site.settings.dev')
640+
641+ app = Celery('celery_booktype')
642+
643+ # Using a string here means the worker doesn't have to serialize
644+ # the configuration object to child processes.
645+ # - namespace='CELERY' means all celery-related configuration keys
646+ # should have a `CELERY_` prefix.
647+ app.config_from_object('django.conf:settings', namespace='CELERY')
648+
649+ # Load task modules from all registered Django app configs.
650+ app.autodiscover_tasks()
651+ ''' .format (booki_path = booki_path , project_name = get_project_name (destination )))
652+ f .close ()
653+ except OSError :
654+ raise InstallError ()
655+ else :
656+ logln ("[OK]" )
657+
658+
659+
660+
612661
613662def create_supervisor (destination , profile , virtual_env ):
614663 log ("+ Creating supervisor_{}.conf file." .format (profile ))
@@ -902,7 +951,6 @@ if __name__ == '__main__':
902951 check_lxml_available ()
903952 check_pil_available ()
904953 check_redis_available ()
905- # check_south_available()
906954 check_unidecode_available ()
907955
908956 # show info about user id, group id and etc...
@@ -954,10 +1002,14 @@ if __name__ == '__main__':
9541002 # create urls
9551003 create_urls (project_destination )
9561004
957- # create wsgi file
1005+ # create wsgi files
9581006 for profile in PROFILES :
9591007 create_wsgi (project_destination , profile , args .virtual_env )
9601008
1009+ # create celery files
1010+ include_celery (project_destination )
1011+ create_celery (project_destination )
1012+
9611013 # create supervisor file for wsgi (stage and prod only)
9621014 for profile in PROFILES [1 :]:
9631015 create_supervisor (project_destination , profile , args .virtual_env )
0 commit comments