Commit | Line | Data |
---|---|---|
4be9d9da OL |
1 | # -*- encoding: utf-8 -*- |
2 | ||
3 | import os | |
4 | import shutil | |
5 | import pkg_resources | |
6 | import djangorecipe | |
7 | from djangorecipe.boilerplate import versions | |
8 | from djangorecipe.recipe import Recipe as OriginalDjangoRecipe | |
9 | from boilerplate import * | |
10 | ||
05129f35 OL |
11 | djangorecipe.boilerplate.versions['1.3']['settings'] = auf_settings_template |
12 | djangorecipe.boilerplate.versions['1.3']['urls'] = auf_urls_template | |
13 | djangorecipe.boilerplate.versions['1.3']['production_settings'] = auf_production_settings | |
14 | djangorecipe.boilerplate.versions['1.3']['development_settings'] = auf_development_settings | |
4be9d9da OL |
15 | |
16 | ||
17 | class Recipe(OriginalDjangoRecipe): | |
18 | ||
19 | def install(self): | |
20 | """ | |
21 | """ | |
22 | location = self.options['location'] | |
23 | base_dir = self.buildout['buildout']['directory'] | |
24 | self.options['project_name'] = os.path.basename(base_dir) | |
25 | ||
26 | project_dir = os.path.join(base_dir, self.options['project']) | |
27 | ||
28 | extra_paths = self.get_extra_paths() | |
8d784906 | 29 | requirements, ws = self.egg.working_set(['auf.recipe.django']) |
4be9d9da OL |
30 | |
31 | script_paths = [] | |
32 | ||
33 | # Create the Django management script | |
34 | script_paths.extend(self.create_manage_script(extra_paths, ws)) | |
35 | ||
36 | # Create the test runner | |
37 | script_paths.extend(self.create_test_runner(extra_paths, ws)) | |
38 | ||
39 | # Make the wsgi and fastcgi scripts if enabled | |
40 | script_paths.extend(self.make_scripts(extra_paths, ws)) | |
41 | ||
42 | # Create default settings if we haven't got a project | |
43 | # egg specified, and if it doesn't already exist | |
44 | if not self.options.get('projectegg'): | |
45 | if not os.path.exists(project_dir): | |
46 | self.create_project(project_dir) | |
47 | else: | |
48 | self.log.info( | |
49 | 'Skipping creating of project: %(project)s since ' | |
50 | 'it exists' % self.options) | |
51 | ||
52 | return script_paths + [location] | |
53 | ||
54 | def create_project(self, project_dir): | |
55 | super(Recipe, self).create_project(project_dir) | |
56 | ||
57 | # fichier de configuration de base de données | |
58 | self.create_file(os.path.join(project_dir, 'conf.py'), conf_file, self.options) | |
59 | self.create_file(os.path.join(project_dir, 'conf.py.edit'), conf_file, self.options) | |
60 | self.create_file(os.path.join(project_dir, 'dashboard.py'), dashboard_file, self.options) | |
61 | ||
3a9e38cc | 62 | def create_manage_script(self, extra_paths, ws): |
dd501324 OL |
63 | _script_template = zc.buildout.easy_install.script_template |
64 | zc.buildout.easy_install.script_template = auf_buildout_file | |
3a9e38cc | 65 | project = self.options.get('projectegg', self.options['project']) |
dd501324 | 66 | scripts = zc.buildout.easy_install.scripts( |
3a9e38cc EMS |
67 | [(self.options.get('control-script', self.name), |
68 | 'auf.recipe.django.manage', 'main')], | |
69 | ws, self.options['executable'], self.options['bin-directory'], | |
70 | extra_paths=extra_paths, | |
71 | arguments="'%s.%s'" % (project, | |
72 | self.options['settings'])) | |
dd501324 OL |
73 | zc.buildout.easy_install.script_template = _script_template |
74 | return scripts | |
75 | ||
76 | def make_scripts(self, extra_paths, ws): | |
77 | scripts = [] | |
78 | _script_template = zc.buildout.easy_install.script_template | |
79 | for protocol in ('wsgi', 'fcgi'): | |
80 | zc.buildout.easy_install.script_template = \ | |
81 | zc.buildout.easy_install.script_header + \ | |
82 | auf_script_template[protocol] | |
83 | if self.options.get(protocol, '').lower() == 'true': | |
84 | project = self.options.get('projectegg', | |
85 | self.options['project']) | |
86 | scripts.extend( | |
87 | zc.buildout.easy_install.scripts( | |
88 | [('%s.%s' % (self.options.get('control-script', | |
89 | self.name), | |
90 | protocol), | |
91 | 'djangorecipe.%s' % protocol, 'main')], | |
92 | ws, | |
93 | self.options['executable'], | |
94 | self.options['bin-directory'], | |
95 | extra_paths=extra_paths, | |
96 | arguments="'%s.%s', logfile='%s'" % ( | |
97 | project, self.options['settings'], | |
98 | self.options.get('logfile')))) | |
99 | zc.buildout.easy_install.script_template = _script_template | |
100 | return scripts |