Skip to content
Newer
Older
100755 144 lines (124 sloc) 4.38 KB
fa41889 @groovecoder bug 641839 mdn branch needs update_site.py script
groovecoder authored May 5, 2011
1 #!/usr/bin/env python
2 """
3 Usage: update_site.py [options]
4 Updates a server's sources, vendor libraries, packages CSS/JS
5 assets, migrates the database, and other nifty deployment tasks.
6
7 Options:
8 -h, --help show this help message and exit
90b8736 @groovecoder bug 673455 remove settings*.pyc files during update_site.py
groovecoder authored Aug 3, 2011
9 -e ENVIRONMENT,
10 --environment=ENVIRONMENT
11 Type of environment. One of
12 (dev|stage|prod|mdn_dev|mdn_stage|mdn_prod)
13 Example:
fa41889 @groovecoder bug 641839 mdn branch needs update_site.py script
groovecoder authored May 5, 2011
14 update_site.py -e stage
15 -v, --verbose Echo actions before taking them.
16 """
17
18 import os
19 import sys
20 from textwrap import dedent
21 from optparse import OptionParser
22
23 # Constants
24 PROJECT = 0
25
26 ENV_BRANCH = {
aac3a6d @groovecoder update update_site.py to reflect new branches
groovecoder authored Mar 26, 2012
27 # 'env': 'git branch'
28 # kuma-stage is set to 'stage'
29 'dev': 'master',
30 'stage': 'master',
31 'mdn_dev': 'master',
32 # developer-stage9 is set to 'mdn_stage'
33 'mdn_stage': 'next',
34 'mdn_prod': 'next',
fa41889 @groovecoder bug 641839 mdn branch needs update_site.py script
groovecoder authored May 5, 2011
35 }
36
6cb12ce @groovecoder install compiled lib's as part of update script
groovecoder authored Oct 18, 2011
37 PIP_INSTALL_COMPILED = "pip install -q -r requirements/compiled.txt"
90b8736 @groovecoder bug 673455 remove settings*.pyc files during update_site.py
groovecoder authored Aug 3, 2011
38 RM_SETTINGS_PYC = "rm -f settings*.pyc"
fa41889 @groovecoder bug 641839 mdn branch needs update_site.py script
groovecoder authored May 5, 2011
39 GIT_PULL = "git pull -q origin %(branch)s"
d9a8d80 @lmorchard Try doing `git reset --hard HEAD` before pull in update_site.py
lmorchard authored Sep 2, 2011
40 GIT_RESET_HARD = "git reset --hard HEAD"
456420e @lmorchard Update kuma-lib commit used for submodule;
lmorchard authored May 24, 2011
41 GIT_SUBMODULE_SYNC = "git submodule sync"
3500c8e @groovecoder bug 660644 no more recursive submodule update
groovecoder authored Jun 2, 2011
42 GIT_SUBMODULE_UPDATE = "git submodule update --init -q"
5847571 @groovecoder bug 659669 revert any un-committed svn changes when updating to avoid…
groovecoder authored Jul 5, 2011
43 SVN_REVERT = "svn revert -R ."
fa41889 @groovecoder bug 641839 mdn branch needs update_site.py script
groovecoder authored May 5, 2011
44 SVN_UP = "svn update"
45 COMPILE_PO = "./compile-mo.sh ."
46
47 EXEC = 'exec'
48 CHDIR = 'chdir'
49
50
51 def update_site(env, debug):
52 """Run through commands to update this site."""
53 error_updating = False
54 here = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
aac3a6d @groovecoder update update_site.py to reflect new branches
groovecoder authored Mar 27, 2012
55 project_branch = {'branch': ENV_BRANCH[env]}
fa41889 @groovecoder bug 641839 mdn branch needs update_site.py script
groovecoder authored May 5, 2011
56
57 commands = [
58 (CHDIR, here),
90b8736 @groovecoder bug 673455 remove settings*.pyc files during update_site.py
groovecoder authored Aug 3, 2011
59 (EXEC, RM_SETTINGS_PYC),
d9a8d80 @lmorchard Try doing `git reset --hard HEAD` before pull in update_site.py
lmorchard authored Sep 2, 2011
60 (EXEC, GIT_RESET_HARD),
90b8736 @groovecoder bug 673455 remove settings*.pyc files during update_site.py
groovecoder authored Aug 3, 2011
61 (EXEC, GIT_PULL % project_branch),
62 (EXEC, GIT_SUBMODULE_SYNC),
63 (EXEC, GIT_SUBMODULE_UPDATE),
fa41889 @groovecoder bug 641839 mdn branch needs update_site.py script
groovecoder authored May 5, 2011
64 ]
65
66 # Update locale dir if applicable
67 if os.path.exists(os.path.join(here, 'locale', '.svn')):
68 commands += [
69 (CHDIR, os.path.join(here, 'locale')),
5847571 @groovecoder bug 659669 revert any un-committed svn changes when updating to avoid…
groovecoder authored Jul 5, 2011
70 (EXEC, SVN_REVERT),
fa41889 @groovecoder bug 641839 mdn branch needs update_site.py script
groovecoder authored May 5, 2011
71 (EXEC, SVN_UP),
72 (EXEC, COMPILE_PO),
73 (CHDIR, here),
74 ]
75 elif os.path.exists(os.path.join(here, 'locale', '.git')):
76 commands += [
77 (CHDIR, os.path.join(here, 'locale')),
78 (EXEC, GIT_PULL % 'master'),
79 (CHDIR, here),
80 ]
81
82 commands += [
83 (CHDIR, os.path.join(here, 'vendor')),
2786a9d @lmorchard In update_site.py, swap `git pull origin master` for `git reset --har…
lmorchard authored Sep 2, 2011
84 # This seems like a bad idea - it pulls from master, while the web app
85 # itself has a submodule pointing at a specific vendor-lib commit ID
86 (EXEC, GIT_RESET_HARD),
456420e @lmorchard Update kuma-lib commit used for submodule;
lmorchard authored May 24, 2011
87 (EXEC, GIT_SUBMODULE_SYNC),
88 (EXEC, GIT_SUBMODULE_UPDATE),
fa41889 @groovecoder bug 641839 mdn branch needs update_site.py script
groovecoder authored May 5, 2011
89 (CHDIR, os.path.join(here)),
09c0634 @groovecoder bug 657995 re-enable migrations in update_site script
groovecoder authored May 20, 2011
90 (EXEC, 'python2.6 vendor/src/schematic/schematic migrations/'),
ddb3157 @groovecoder bug 665122 kuma branch should now use south
groovecoder authored Jul 19, 2011
91 (EXEC, 'python2.6 manage.py migrate'),
92 (EXEC, 'python2.6 manage.py compress_assets'),
fa41889 @groovecoder bug 641839 mdn branch needs update_site.py script
groovecoder authored May 5, 2011
93 ]
a50cde3 @lmorchard bug 702988: Initial sweep through merge conflicts
lmorchard authored Nov 21, 2011
94
fa41889 @groovecoder bug 641839 mdn branch needs update_site.py script
groovecoder authored May 5, 2011
95 for cmd, cmd_args in commands:
96 if CHDIR == cmd:
97 if debug:
98 sys.stdout.write("cd %s\n" % cmd_args)
99 os.chdir(cmd_args)
100 elif EXEC == cmd:
101 if debug:
102 sys.stdout.write("%s\n" % cmd_args)
103 if not 0 == os.system(cmd_args):
104 error_updating = True
105 break
106 else:
107 raise Exception("Unknown type of command %s" % cmd)
108
109 if error_updating:
110 sys.stderr.write("There was an error while updating. Please try again "
111 "later. Aborting.\n")
112
113
114 def main():
115 """ Handels command line args. """
116 debug = False
117 usage = dedent("""\
118 %prog [options]
119 Updates a server's sources, vendor libraries, packages CSS/JS
120 assets, migrates the database, and other nifty deployment tasks.
121 """.rstrip())
122
123 options = OptionParser(usage=usage)
124 e_help = "Type of environment. One of (%s) Example: update_site.py \
125 -e stage" % '|'.join(ENV_BRANCH.keys())
126 options.add_option("-e", "--environment", help=e_help)
127 options.add_option("-v", "--verbose",
128 help="Echo actions before taking them.",
129 action="store_true", dest="verbose")
130 (opts, _) = options.parse_args()
131
132 if opts.verbose:
133 debug = True
134 if opts.environment in ENV_BRANCH.keys():
135 update_site(opts.environment, debug)
136 else:
137 sys.stderr.write("Invalid environment!\n")
138 options.print_help(sys.stderr)
139 sys.exit(1)
140
141
142 if __name__ == '__main__':
143 main()
Something went wrong with that request. Please try again.