Merge lp:~nick-moffitt/assets-bundler/use-jinja2-not-sed into lp:assets-bundler

Proposed by Nick Moffitt
Status: Needs review
Proposed branch: lp:~nick-moffitt/assets-bundler/use-jinja2-not-sed
Merge into: lp:assets-bundler
Diff against target: 56 lines (+10/-31)
2 files modified
Makefile (+10/-16)
update-bundles-yaml.sh (+0/-15)
To merge this branch: bzr merge lp:~nick-moffitt/assets-bundler/use-jinja2-not-sed
Reviewer Review Type Date Requested Status
Webteam Backend Pending
Review via email: mp+238278@code.launchpad.net

Description of the change

This change is untested as of now, but it relies on a jinja2 one-liner I've used in many places in the past. The basic trick is that it uses a template snarfed from stdin and populates it with environment variables. This approach isn't always the most robust, but it seems preferrable to a special-purpose script full of sed commands that aim to emulate jinja2's functionality.

The branch removes this script, which I hope will ease the maintenance burden. If the technique is not suitable here for some reason, I hope you will consider it in other situations where you need a quick template.

To post a comment you must log in.

Unmerged revisions

32. By Nick Moffitt

Try actually using jinja2 templates instead of sed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2014-07-14 15:04:15 +0000
3+++ Makefile 2014-10-14 11:05:31 +0000
4@@ -117,22 +117,16 @@
5 update-manager-directory:
6 PROJECT_NAME=assets-manager sh -ex update-project-directory.sh
7
8-upload-and-update-bundles-yaml:
9- cp bundles.template.yaml bundles.temp.yaml
10-
11- PROJECT_NAME=assets-server source upload-archive-to-swift.sh && \
12- SERVER_CONTAINER_URI=$$CONTAINER_URI \
13- SERVER_ARCHIVE_FILENAME=$$ARCHIVE_FILENAME \
14- SERVER_BUILD_LABEL=$$BUILD_LABEL \
15- sh -ex update-bundles-yaml.sh
16-
17- PROJECT_NAME=assets-manager source upload-archive-to-swift.sh && \
18- MANAGER_CONTAINER_URI=$$CONTAINER_URI \
19- MANAGER_ARCHIVE_FILENAME=$$ARCHIVE_FILENAME \
20- MANAGER_BUILD_LABEL=$$BUILD_LABEL \
21- sh -ex update-bundles-yaml.sh
22-
23- mv bundles.temp.yaml bundles.yaml
24+upload-and-update-bundles:
25+ PROJECT_NAME=assets-server source upload-archive-to-swift.sh
26+ PROJECT_NAME=assets-manager source upload-archive-to-swift.sh
27+ server_container_uri=$$CONTAINER_URI \
28+ server_archive_filename=$$ARCHIVE_FILENAME \
29+ server_build_label=$$BUILD_LABEL \
30+ manager_container_uri=$$CONTAINER_URI \
31+ manager_archive_filename=$$ARCHIVE_FILENAME \
32+ manager_build_label=$$BUILD_LABEL \
33+ python -c "import os,sys,jinja2; print jinja2.Template(sys.stdin.read()).render(**os.environ)" < bundles.temp.yaml > bundles.yaml
34
35 deploy-dev:
36 BUNDLE_NAME=assets-bundle-dev sh -ex deploy.sh
37
38=== removed file 'update-bundles-yaml.sh'
39--- update-bundles-yaml.sh 2014-07-11 22:15:09 +0000
40+++ update-bundles-yaml.sh 1970-01-01 00:00:00 +0000
41@@ -1,15 +0,0 @@
42-# Set archive location variables in bundles.yaml
43-# ===
44-
45-if [ $SERVER_CONTAINER_URI ]; then sed -i 's!{{server_container_uri}}!'$SERVER_CONTAINER_URI'!' bundles.temp.yaml; fi
46-if [ $SERVER_ARCHIVE_FILENAME ]; then sed -i 's!{{server_archive_filename}}!'$SERVER_ARCHIVE_FILENAME'!' bundles.temp.yaml; fi
47-if [ $SERVER_BUILD_LABEL ]; then sed -i 's!{{server_build_label}}!'$SERVER_BUILD_LABEL'!' bundles.temp.yaml; fi
48-
49-if [ $MANAGER_CONTAINER_URI ]; then sed -i 's!{{manager_container_uri}}!'$MANAGER_CONTAINER_URI'!' bundles.temp.yaml; fi
50-if [ $MANAGER_ARCHIVE_FILENAME ]; then sed -i 's!{{manager_archive_filename}}!'$MANAGER_ARCHIVE_FILENAME'!' bundles.temp.yaml; fi
51-if [ $MANAGER_BUILD_LABEL ]; then sed -i 's!{{manager_build_label}}!'$MANAGER_BUILD_LABEL'!' bundles.temp.yaml; fi
52-
53-if [ $OS_AUTH_URL ]; then sed -i 's!{{swift_auth_url}}!'$OS_AUTH_URL'!' bundles.temp.yaml; fi
54-if [ $OS_USERNAME ]; then sed -i 's!{{swift_username}}!'$OS_USERNAME'!' bundles.temp.yaml; fi
55-if [ $OS_PASSWORD ]; then sed -i 's!{{swift_password}}!'$OS_PASSWORD'!' bundles.temp.yaml; fi
56-if [ $OS_TENANT_NAME ]; then sed -i 's!{{swift_tenant_name}}!'$OS_TENANT_NAME'!' bundles.temp.yaml; fi

Subscribers

People subscribed via source and target branches

to all changes: