/
vendor.py
executable file
·330 lines (296 loc) · 6.6 KB
/
vendor.py
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/usr/bin/python
"""Support Toolkit vender.py
@package SupportToolkit
@copyright (c) 2012 phpBB Group
@license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
This utility copies all vendor files that are required by the Support Toolkit
into their correct locations. This tool expects that the vendor repositories
are already checked out.
"""
import argparse
from os import chdir, getcwd, makedirs, remove
from os.path import dirname, exists, isdir
from shutil import copy2, copytree, rmtree
from subprocess import PIPE, Popen
import types
class STKVendor :
__phpBBFiles = [
[
"",
[
"composer.json",
"composer.lock",
],
"phpBB/"
],
[
"adm/images/",
[
"arrow_down.gif",
"arrow_left.gif",
"arrow_right.gif",
"bg_button.gif",
"bg_tabs1.gif",
"bg_tabs2.gif",
"corners_left.gif",
"corners_right.gif",
"gradient2b.gif",
"innerbox_bg.gif",
"phpbb_logo.gif",
"toggle.gif",
],
"view/images/"
],
[
"adm/style/admin.css",
"view/theme/admin.css"
],
[
"includes/",
[
"constants.php",
"functions.php",
"session.php",
"startup.php",
"user.php",
],
"phpBB/includes/"
],
[
"includes/auth/",
"phpBB/includes/auth/"
],
[
"includes/cache/",
[
"factory.php",
"service.php",
],
"phpBB/includes/cache/"
],
[
"includes/cache/driver/",
"phpBB/includes/cache/driver/"
],
[
"includes/config/",
[
"config.php",
"db.php",
],
"phpBB/includes/config/"
],
[
"includes/db/",
"phpBB/includes/db/"
],
[
"includes/request/",
"phpBB/includes/request/"
],
[
"includes/style/",
[
"path_provider.php",
"path_provider_interface.php",
"resource_locator.php",
"style.php",
"template.php",
"template_compile.php",
"template_context.php",
"template_filter.php",
"template_renderer.php",
"template_renderer_eval.php",
"template_renderer_include.php",
],
"phpBB/includes/style/"
],
[
"includes/utf/",
[
"utf_normalizer.php",
"utf_tools.php",
],
"phpBB/includes/utf/"
],
[
"includes/utf/data/",
"phpBB/includes/utf/data/"
]
]
__repos = {
"MODX": "v1.2.5",
"phpBB": "develop",
"Pimple": "master",
"UMIL": "master",
}
args = []
cwd = ''
""" Set of commands passed into `Popen` on various occations"""
commands = {
'php': {
'curl': [
'curl',
'-s',
'http://getcomposer.org/installer',
],
'php': [
'php',
],
'composerInstall': [
'php',
'composer.phar',
'install',
],
},
'git': {
'fetch': [
'git',
'fetch',
],
'init': [
'git',
'submodule',
'update',
'--init',
],
'reset': [
'git',
'reset',
'--hard',
'HEAD',
],
},
}
def __init__(self) :
self.args = self.getCommandLineArgs()
self.cwd = getcwd()
def getCommandLineArgs(self) :
parser = argparse.ArgumentParser(
description='Script that copies vendor files to the correct location into the Support Toolkit tree. This script assumes that the vendor submodules are already checked out.'
)
parser.add_argument(
"-f",
"--force",
dest="force",
action="store_true",
help="Update files, setting this parameter will force the script to overwrite the files if they already exist"
)
parser.add_argument(
"-s",
"--setup",
dest="setup",
action="store_true",
help="Initialise the submodules"
)
parser.add_argument(
"-u",
"--update",
dest="update",
action="store_true",
help="Update the submodules to point to the latest revision in the tree",
)
return parser.parse_args()
def copyphpBBFiles(self) :
basesrc = './stk/vendor/phpBB/phpBB/'
basedest = './stk/'
for file in self.__phpBBFiles :
if isinstance(file[1], types.ListType) :
for f in file[1]:
self._copy(
basesrc + file[0] + f,
basedest + file[2] + f,
self.args.force
)
else :
self._copy(
basesrc + file[0],
basedest + file[1],
self.args.force
)
def _copy(self, src, dest, update=False) :
if (exists(dest) and update == False) :
print ('\033[91m' + 'Skipping: ' + '\033[0m' + src + ' (destination already exists)')
return False
out = ('\033[92m' + 'Copying: ' + '\033[0m' if update == False else '\033[94m' + 'Force copying: ' + '\033[0m') + src + ' to: ' + dest
print (out)
if isdir(src) :
if (exists(dirname(dest)) and update == True):
rmtree(dest)
copytree(src, dest)
else :
if not exists(dirname(dest)) :
makedirs(dirname(dest))
elif (exists(dest) and update == True):
remove(dest)
copy2(src, dest)
return True
def installComposor(self) :
chdir('./stk/phpBB/')
p1 = Popen(self.commands.php.curl, stdout=PIPE, stderr=PIPE)
p2 = Popen(self.commands.php.php, stdin=p1.stdout, stdout=PIPE, stderr=PIPE)
p1.stdout.close()
p2_stdout_value = p2.communicate()
print (p2_stdout_value)
p2.stdout.close()
p3 = Popen(self.commands.php.composerInstall, stdout=PIPE, stderr=PIPE)
print (p3.stdout.read())
p3.stdout.close()
chdir(self.cwd)
def setupRepos(self) :
print("\033[91m" + "Initialising vendor repositories" + "\033[0m")
p1 = Popen(self.commands.git.init, stdout=PIPE)
print (p1.stdout.read())
p1.stdout.close()
def updateRepos(self) :
for r, b in self.__repos.items() :
print("\033[91m" + "Updating /vendor/" + r + "\033[0m")
chdir('./stk/vendor/' + r)
p1 = Popen(self.commands.git.fetch, stdout=PIPE)
print(p1.stdout.read())
p1.stdout.close()
p2 = Popen(self.commands.git.reset, stdout=PIPE)
print(p2.stdout.read())
p2.stdout.close()
com3 = ['git', 'checkout', b]
p3 = Popen(com3, stdout=PIPE)
print(p3.stdout.read())
p3.stdout.close()
p4 = Popen(self.commands.git.reset, stdout=PIPE)
print(p4.stdout.read())
p4.stdout.close()
b = 'origin/' + b if (b[:1] != "v") else b
com5 = ['git', 'merge', b]
p5 = Popen(com5, stdout=PIPE)
print(p5.stdout.read())
p5.stdout.close()
chdir(self.cwd)
print("\n\n")
def main():
vendor = STKVendor()
# Update the repos
if vendor.args.update :
vendor.updateRepos()
return
# Setup
if vendor.args.setup :
vendor.setupRepos()
print("\033[91m" + "Copying files" + "\033[0m")
# phpBB files
vendor.copyphpBBFiles()
# Pimple
vendor._copy (
'./stk/vendor/Pimple/lib/Pimple.php',
'./stk/core/DI/Pimple.php',
vendor.args.force
)
# MODX
vendor._copy (
'./stk/vendor/MODX/modx.prosilver.en.xsl',
'./contrib/modx.prosilver.en.xsl',
vendor.args.force
)
# Finally install and run composer in 'stk/phpBB/'
vendor.installComposor()
if __name__ == "__main__" :
main()