Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b018ad5

Browse files
author
Bevan Loon
committed
Remove emergency publishing deploy and removal scripts
Emergency banner publishing is now done with a Jenkins task. Remove the deprecated fabric scripts.
1 parent b9a03f7 commit b018ad5

File tree

1 file changed

+1
-95
lines changed

1 file changed

+1
-95
lines changed

campaigns.py

Lines changed: 1 addition & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
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
102

113

124
env['eagerly_disconnect'] = True
135

146

15-
APPLICATIONS = ['static', 'frontend']
16-
CAMPAIGN_CLASSES = ['red', 'black', 'green']
177
TEMPLATES = [
188
'wrapper.html.erb',
199
'homepage.html.erb',
@@ -22,45 +12,6 @@
2212
]
2313

2414

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-
6415
def clear_static_generated_templates():
6516
"""
6617
Our various frontend applications use the wrapper.html.erb,
@@ -89,51 +40,6 @@ def clear_government_frontend_cache():
8940
sudo("rm -rf /var/apps/government-frontend/tmp/cache/*")
9041

9142

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-
13743
@task
13844
@roles('class-frontend')
13945
def clear_cached_templates():

0 commit comments

Comments
 (0)