|
1 |
| -import StringIO |
2 |
| - |
3 |
| -from fabric.api import env, put, roles, runs_once, settings, sudo, task |
4 |
| -from fabric.operations import prompt |
5 |
| -from fabric.tasks import execute |
6 |
| - |
7 |
| -from jinja2 import Template |
8 |
| - |
9 |
| -import app |
| 1 | +from fabric.api import env, roles, settings, sudo, task |
10 | 2 |
|
11 | 3 |
|
12 | 4 | env['eagerly_disconnect'] = True
|
13 | 5 |
|
14 | 6 |
|
15 |
| -APPLICATIONS = ['static', 'frontend'] |
16 |
| -CAMPAIGN_CLASSES = ['red', 'black', 'green'] |
17 | 7 | TEMPLATES = [
|
18 | 8 | 'wrapper.html.erb',
|
19 | 9 | 'homepage.html.erb',
|
|
22 | 12 | ]
|
23 | 13 |
|
24 | 14 |
|
25 |
| -def validate_classes(campaign_class): |
26 |
| - """Checks that the campaign class is valid""" |
27 |
| - if campaign_class in CAMPAIGN_CLASSES: |
28 |
| - return campaign_class |
29 |
| - raise Exception("Invalid class {}, valid values are {}".format(campaign_class, CAMPAIGN_CLASSES)) |
30 |
| - |
31 |
| - |
32 |
| -@runs_once |
33 |
| -def set_context(): |
34 |
| - env['context'] = { |
35 |
| - 'heading': prompt("Heading:", 'heading'), |
36 |
| - 'extra_info': prompt("Short description:", 'extra_info'), |
37 |
| - 'more_info_url': prompt("More info link:", 'more_info_url'), |
38 |
| - 'campaign_class': prompt("Campaign class (one of {}):".format(", ".join(CAMPAIGN_CLASSES)), 'campaign_class', validate=validate_classes) |
39 |
| - } |
40 |
| - |
41 |
| - |
42 |
| -def template(app): |
43 |
| - if app == 'frontend': |
44 |
| - template = Template("""<div id="campaign" class="{{ campaign_class }}"> |
45 |
| - <div class="campaign-inner"> |
46 |
| - <h1>{{ heading|e }}</h1> |
47 |
| - <p>{{ extra_info|e }}</p> |
48 |
| -
|
49 |
| - {% if more_info_url %} |
50 |
| - <a href="{{ more_info_url|e }}">More information</a> |
51 |
| - {% endif %} |
52 |
| - </div> |
53 |
| - </div>""") |
54 |
| - elif app == 'static': |
55 |
| - template = Template("""<p>{{ heading|e }}<br /> |
56 |
| - {{ extra_info|e }}</p> |
57 |
| - {% if more_info_url %} |
58 |
| - <a href="{{ more_info_url|e }}" class="more-information">More information</a> |
59 |
| - {% endif %}""") |
60 |
| - |
61 |
| - env['template_contents'] = template.render(env.context) |
62 |
| - |
63 |
| - |
64 | 15 | def clear_static_generated_templates():
|
65 | 16 | """
|
66 | 17 | Our various frontend applications use the wrapper.html.erb,
|
@@ -89,51 +40,6 @@ def clear_government_frontend_cache():
|
89 | 40 | sudo("rm -rf /var/apps/government-frontend/tmp/cache/*")
|
90 | 41 |
|
91 | 42 |
|
92 |
| -def deploy_banner(application): |
93 |
| - execute(template, application) |
94 |
| - if application == 'frontend': |
95 |
| - remote_filename = '/var/apps/frontend/app/views/homepage/_campaign_notification.html.erb' |
96 |
| - elif application == 'static': |
97 |
| - remote_filename = "/var/apps/static/app/views/notifications/banner_{}.erb".format(env.campaign_class) |
98 |
| - content = env['template_contents'] |
99 |
| - put(StringIO.StringIO(content), remote_filename, use_sudo=True, mirror_local_mode=True) |
100 |
| - sudo('chown deploy:deploy %s' % remote_filename) |
101 |
| - execute(app.restart, application) |
102 |
| - if application == 'static': |
103 |
| - clear_static_generated_templates() |
104 |
| - |
105 |
| - |
106 |
| -def remove_banner(application): |
107 |
| - if application == 'frontend': |
108 |
| - remote_filenames = ['/var/apps/frontend/app/views/homepage/_campaign_notification.html.erb'] |
109 |
| - elif application == 'static': |
110 |
| - remote_filenames = ["/var/apps/static/app/views/notifications/banner_%s.erb" % i for i in CAMPAIGN_CLASSES] |
111 |
| - content = '' |
112 |
| - for remote_filename in remote_filenames: |
113 |
| - put(StringIO.StringIO(content), remote_filename, use_sudo=True, mirror_local_mode=True) |
114 |
| - sudo('chown deploy:deploy %s' % remote_filename) |
115 |
| - execute(app.restart, application) |
116 |
| - if application == 'static': |
117 |
| - clear_static_generated_templates() |
118 |
| - |
119 |
| - |
120 |
| -@task |
121 |
| -@roles('class-frontend') |
122 |
| -def deploy_emergency_banner(): |
123 |
| - """Deploy an emergency banner to GOV.UK""" |
124 |
| - execute(set_context) |
125 |
| - for application in APPLICATIONS: |
126 |
| - deploy_banner(application) |
127 |
| - |
128 |
| - |
129 |
| -@task |
130 |
| -@roles('class-frontend') |
131 |
| -def remove_emergency_banner(): |
132 |
| - """Remove all banners from GOV.UK""" |
133 |
| - for application in APPLICATIONS: |
134 |
| - remove_banner(application) |
135 |
| - |
136 |
| - |
137 | 43 | @task
|
138 | 44 | @roles('class-frontend')
|
139 | 45 | def clear_cached_templates():
|
|
0 commit comments