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