-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathos2web_build.py
More file actions
executable file
·176 lines (146 loc) · 6.3 KB
/
os2web_build.py
File metadata and controls
executable file
·176 lines (146 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env python
"""
Build script for OS2Web.
Utilises Drush make to build a site or install profile based on OS2Web.
"""
from optparse import OptionParser
from subprocess import Popen, PIPE, STDOUT
import logging
import os.path
import shutil
import sys
def parse_args():
""" Configure and run optparse to parse commandline parameters """
parser = OptionParser(usage='usage: %prog [-dDhlqv -L prefix -m MODE] [MAKE_PATH]')
parser.add_option("-d", "--debug",
action="store_true", dest="debug", default=False,
help="run script in debug mode, very verbose output.")
parser.add_option("-D", "--developer",
action="store_true", dest="developer", default=False,
help="build developer copy, using authenticated Git repositories.")
parser.add_option("-l", "--create_symlinks",
action="store_true", dest="create_symlinks", default=False,
help="create symlinks - latest pointing to the build performing to, and previous pointing to whatever latest was pointing to before.")
parser.add_option("-L", "--symlink-prefix",
action="store", dest="symlink_prefix", default='',
help="prefix the symlinks provided by -l with this string")
parser.add_option("-m", "--mode",
action="store", dest="mode", default='site',
help="what build mode to use. 'site' for full Drupal site, 'profile' for just the installation profile. Default is 'site'.")
parser.add_option("-f", "--file",
action="store", dest="file", default='os2web.make',
help="Use alternate make file")
parser.add_option("-v", "--verbose",
action="store_true", dest="verbose", default=False,
help="make lots of noise")
parser.add_option("-t", "--test",
action="store_true", dest="test", default=False,
help="Do a test run, with no actual release generated.")
parser.add_option("-q", "--quiet",
action="store_true", dest="quiet", default=False,
help="don't print status messages to stdout")
return parser.parse_args()
def configure_logging(options):
"""
Set up a an instance of Python's standard logging utility.
"""
if options.debug:
level = logging.DEBUG
elif options.verbose:
level = logging.INFO
else:
level = logging.WARNING
logging.basicConfig(level=level, datefmt="%H:%M:%S",
format='%(levelname)s: %(message)s (%(asctime)s)')
def make_command(options, make_path):
""" Generate the make command based on current options. """
make_file = options.file
# Set command based on mode.
if options.mode == 'site':
command = ['drush', 'make', '--no-gitinfofile', '--contrib-destination=profiles/os2web', make_file, make_path]
elif options.mode == 'profile':
command = ['drush', 'make', '--no-gitinfofile', '--no-core', '--contrib-destination=.', make_file, make_path]
else:
sys.exit('Unknown mode "%s", aborting.' % options.mode)
# Add debug or quiet flag based on our debug setting.
if options.debug:
command.insert(1, '-d')
elif options.verbose:
command.insert(1, '-v')
elif options.quiet:
command.insert(1, '-q')
if options.test:
command.insert(1, '--test')
# For developers, keep SCM checkouts.
if options.developer:
command.insert(3, '--working-copy')
return command
def start_make(command):
""" Run make command as generated by make_command() """
try:
proc = Popen(command)
except OSError:
sys.exit('Could not run %s - is it available in your path?' % command[0])
proc.wait()
if proc.returncode == 0:
logging.info('Finished Drush make sucessfully')
return True
def setup_profile(options, make_path):
"""
Setup the make product as a Drupal install profile.
Handles copying the profile file into the correct folder.
"""
if options.mode == 'site':
path = os.path.join(make_path, 'profiles', 'os2web')
else:
path = make_path
shutil.copy('os2web.profile', path)
shutil.copy('os2web.info', path)
shutil.copy('os2web.install', path)
shutil.copy('db.sql.gz', path)
# shutil.copytree('translations', os.path.join(path,'translations'))
# (options, args) = parse_args()
# os.symlink(os.path.join(args[-1],'os2web.profile'), os.path.join(path,'os2web.profile'))
# os.symlink(os.path.join(args[-1],'os2web.info'), os.path.join(path,'os2web.info'))
# os.symlink(os.path.join(args[-1],'os2web.install'), os.path.join(path,'os2web.install'))
# os.symlink(os.path.join(args[-1],'translations'), os.path.join(path,'translations'))
def create_symlinks(options, folder_name):
"""
Set up symlinks to latest and previous build.
"""
if options.symlink_prefix:
latest = 'build/%s-latest' % options.symlink_prefix
previous = 'build/%s-previous' % options.symlink_prefix
else:
latest = 'build/latest'
previous = 'build/previous'
# Revome previous symlink, if it exists.
if os.path.lexists(previous):
os.unlink(previous)
# If there is already a latest symlink, rename it to previous.
if os.path.lexists(latest):
os.rename(latest, previous)
# Set up a link from our completed build to the new one.
os.symlink(folder_name, latest)
def main():
""" Main function, run when the script is run stand-alone. """
(options, args) = parse_args()
configure_logging(options)
try:
folder_name = args[-1]
except IndexError:
folder_name = 'os2web'
make_path = 'build/%s' % folder_name
logging.info('Starting make for mode "%s" in folder "%s"' % (options.mode, make_path))
success = start_make(make_command(options, make_path))
if success:
if options.test:
logging.info('Test build successful.')
else:
setup_profile(options, make_path)
if options.create_symlinks:
create_symlinks(options, folder_name)
else:
logging.error('Build FAILED for mode "%s" in folder "%s"' % (options.mode, make_path))
if __name__ == '__main__':
main()