1
- #!/usr/bin/python
1
+ #!/usr/bin/python{{ ((ansible_os_family == "RedHat" and ansible_distribution_major_version|int >= 8) or (ansible_os_family == "Debian" and ansible_distribution_major_version|int >= 10)) | ternary('3', '') }}
2
2
#
3
3
# Copyright (c) 2015 Michael Scherer <[email protected] >
4
4
#
80
80
'build_command' : ['/srv/builder/planet-venus/planet.py' , '-v' , 'planet.ini' ],
81
81
'build_subdir' : 'build' ,
82
82
'deploy_command' : None
83
+ },
84
+ 'nikola' : {
85
+ 'build_env' : {},
86
+ 'build_command' : ['../.local/bin/nikola' , 'build' ],
87
+ 'build_subdir' : 'output' ,
88
+ 'deploy_command' : None
83
89
}
84
90
}
85
91
@@ -96,47 +102,47 @@ def log_print(message):
96
102
97
103
def debug_print (message ):
98
104
if args .debug :
99
- print message
105
+ print ( message )
100
106
log_print (message )
101
107
102
108
103
109
def refresh_checkout (checkout_dir ):
104
110
os .chdir (checkout_dir )
105
111
try :
106
112
result = subprocess .check_output (['git' , 'fetch' , '-q' ], stderr = subprocess .STDOUT )
107
- except subprocess .CalledProcessError , C :
113
+ except subprocess .CalledProcessError as C :
108
114
notify_error ('setup' , C .output )
109
- debug_print (result )
115
+ debug_print (result . decode () )
110
116
111
117
112
118
def get_last_commit (checkout_dir ):
113
119
os .chdir (checkout_dir )
114
120
try :
115
121
r = subprocess .check_output (['git' , 'ls-remote' , '-q' , '.' ,
116
122
'refs/remotes/origin/%s' % config ['git_version' ]])
117
- except subprocess .CalledProcessError , C :
123
+ except subprocess .CalledProcessError as C :
118
124
notify_error ('setup' , C .output )
119
- return r .split ()[0 ]
125
+ return r .decode (). split ()[0 ]
120
126
121
127
122
128
def get_last_commit_submodule (checkout_dir , submodule ):
123
129
os .chdir ("{}/{}/" .format (checkout_dir , submodule ))
124
130
try :
125
131
r = subprocess .check_output (['git' , 'ls-remote' , '-q' , '.' ,
126
132
'refs/remotes/origin/HEAD' ])
127
- except subprocess .CalledProcessError , C :
133
+ except subprocess .CalledProcessError as C :
128
134
notify_error ('setup' , C .output )
129
- return r .split ()[0 ]
135
+ return r .decode (). split ()[0 ]
130
136
131
137
132
138
def get_submodules_checkout (checkout_dir ):
133
139
os .chdir (checkout_dir )
134
140
result = []
135
141
try :
136
142
submodule_status = subprocess .check_output (['git' , 'submodule' , 'status' ])
137
- except subprocess .CalledProcessError , C :
143
+ except subprocess .CalledProcessError as C :
138
144
notify_error ('setup' , C .output )
139
- for s in submodule_status .split ('\n ' ):
145
+ for s in submodule_status .decode (). split ('\n ' ):
140
146
# there is a empty line at the end...
141
147
if s :
142
148
result .append (s .split ()[1 ])
@@ -145,10 +151,10 @@ def get_submodules_checkout(checkout_dir):
145
151
146
152
def load_config (config_file ):
147
153
if not os .path .exists (config_file ):
148
- print "Error %s, do not exist" % config_file
154
+ print ( "Error %s, do not exist" % config_file )
149
155
sys .exit (1 )
150
156
if not os .path .isfile (config_file ):
151
- print "Error %s is not a file" % config_file
157
+ print ( "Error %s is not a file" % config_file )
152
158
sys .exit (1 )
153
159
154
160
with open (config_file ) as f :
@@ -161,14 +167,14 @@ def has_submodules(checkout_dir):
161
167
os .chdir (checkout_dir )
162
168
try :
163
169
r = subprocess .check_output (['git' , 'submodule' , 'status' ])
164
- except subprocess .CalledProcessError , C :
170
+ except subprocess .CalledProcessError as C :
165
171
notify_error ('setup' , C .output )
166
- return len (r ) > 0
172
+ return len (r . decode () ) > 0
167
173
168
174
169
175
# TODO complete that
170
176
def notify_error (stage , error ):
171
- print error
177
+ print ( error )
172
178
sys .exit (3 )
173
179
174
180
@@ -189,20 +195,20 @@ def do_rsync(source):
189
195
'--omit-dir-times' ,
190
196
source ,
191
197
config ['remote' ]], stderr = subprocess .STDOUT )
192
- except subprocess .CalledProcessError , C :
198
+ except subprocess .CalledProcessError as C :
193
199
notify_error ('setup' , C .output )
194
- return r
200
+ return r . decode ()
195
201
196
202
197
203
198
204
if not args .config_file :
199
- print "This script take only 1 single argument, the config file"
205
+ print ( "This script take only 1 single argument, the config file" )
200
206
sys .exit (1 )
201
207
202
208
config = load_config (args .config_file )
203
209
204
210
if 'name' not in config :
205
- print "Incorrect config file: {}" .format (args .config_file )
211
+ print ( "Incorrect config file: {}" .format (args .config_file ) )
206
212
sys .exit (1 )
207
213
208
214
name = config ['name' ]
@@ -216,7 +222,7 @@ def do_rsync(source):
216
222
217
223
# TODO try/except, show a better error message
218
224
fd = os .open (lock_file , os .O_CREAT | os .O_EXCL | os .O_WRONLY )
219
- os .write (fd , str (os .getpid ()))
225
+ os .write (fd , str (os .getpid ()). encode () )
220
226
os .close (fd )
221
227
atexit .register (os .unlink , lock_file )
222
228
@@ -229,7 +235,7 @@ def do_rsync(source):
229
235
checkout_dir = os .path .expanduser ("~/%s" % name )
230
236
if not os .path .isdir (checkout_dir ):
231
237
os .unlink (lock_file )
232
- print "Checkout not existing, exiting"
238
+ print ( "Checkout not existing, exiting" )
233
239
sys .exit (2 )
234
240
235
241
refresh_checkout (checkout_dir )
@@ -286,21 +292,21 @@ def do_rsync(source):
286
292
if not args .no_refresh :
287
293
try :
288
294
result = subprocess .check_output (['git' , 'stash' ], stderr = subprocess .STDOUT )
289
- debug_print (result )
295
+ debug_print (result . decode () )
290
296
result = subprocess .check_output (['git' , 'stash' , 'clear' ], stderr = subprocess .STDOUT )
291
- debug_print (result )
297
+ debug_print (result . decode () )
292
298
result = subprocess .check_output (['git' , 'pull' , '--rebase' ], stderr = subprocess .STDOUT )
293
- debug_print (result )
294
- except subprocess .CalledProcessError , C :
299
+ debug_print (result . decode () )
300
+ except subprocess .CalledProcessError as C :
295
301
notify_error ('setup' , C .output )
296
302
297
303
if has_submodules (checkout_dir ):
298
304
try :
299
305
result = subprocess .check_output (['git' , 'submodule' , 'init' ], stderr = subprocess .STDOUT )
300
- debug_print (result )
306
+ debug_print (result . decode () )
301
307
result = subprocess .check_output (['git' , 'submodule' , 'sync' ], stderr = subprocess .STDOUT )
302
- debug_print (result )
303
- except subprocess .CalledProcessError , C :
308
+ debug_print (result . decode () )
309
+ except subprocess .CalledProcessError as C :
304
310
notify_error ('setup' , C .output )
305
311
306
312
build_subdir = builder_info [config ['builder' ]]['build_subdir' ]
@@ -309,7 +315,7 @@ def do_rsync(source):
309
315
# ensure build directory exist or creating the sync log would fail
310
316
try :
311
317
# TODO: use exist_ok instead of all this crap when switching to Python 3
312
- os .makedirs (build_dir , mode = 0775 )
318
+ os .makedirs (build_dir , mode = 0o775 )
313
319
except OSError as exc :
314
320
if exc .errno == errno .EEXIST and os .path .isdir (build_dir ):
315
321
pass
@@ -329,15 +335,15 @@ def do_rsync(source):
329
335
# don't use embedded libraries to build Nokogiri
330
336
os .environ ['NOKOGIRI_USE_SYSTEM_LIBRARIES' ] = '1'
331
337
result = subprocess .check_output (['bundle' , 'install' ], stderr = subprocess .STDOUT )
332
- debug_print (result )
333
- except subprocess .CalledProcessError , C :
338
+ debug_print (result . decode () )
339
+ except subprocess .CalledProcessError as C :
334
340
log_print (C .output )
335
341
if config ['remote' ]:
336
342
# copy log in build dir and sync it to make it available to users
337
343
shutil .copy2 (log_file , sync_log_path )
338
344
try :
339
345
do_rsync (sync_log_path )
340
- except subprocess .CalledProcessError , C :
346
+ except subprocess .CalledProcessError :
341
347
pass
342
348
notify_error ('install' , C .output )
343
349
@@ -349,15 +355,15 @@ def do_rsync(source):
349
355
command = builder_info [config ['builder' ]]['build_command' ]
350
356
syslog .syslog ("Build of {}: {}" .format (name , ' ' .join (command )))
351
357
result = subprocess .check_output (command , stderr = subprocess .STDOUT )
352
- debug_print (result )
353
- except subprocess .CalledProcessError , C :
358
+ debug_print (result . decode () )
359
+ except subprocess .CalledProcessError as C :
354
360
log_print (C .output )
355
361
if config ['remote' ]:
356
362
# copy log in build dir and sync it to make it available to users
357
363
shutil .copy2 (log_file , sync_log_path )
358
364
try :
359
365
do_rsync (sync_log_path )
360
- except subprocess .CalledProcessError , C :
366
+ except subprocess .CalledProcessError :
361
367
pass
362
368
notify_error ('build' , C .output )
363
369
@@ -372,11 +378,11 @@ def do_rsync(source):
372
378
else :
373
379
command = builder_info [config ['builder' ]]['deploy_command' ]
374
380
if command :
375
- result = subprocess .check_output (command )
381
+ result = subprocess .check_output (command ). decode ()
376
382
else :
377
383
result = "No deployment done: no Rsync settings provided and this builder has no reployment method defined"
378
384
debug_print (result )
379
- except subprocess .CalledProcessError , C :
385
+ except subprocess .CalledProcessError as C :
380
386
notify_error ('deploy' , C .output )
381
387
syslog .syslog ("Build of {}: finish sync" .format (name ))
382
388
else :
@@ -389,4 +395,4 @@ def do_rsync(source):
389
395
status ['submodule_commits' ] = current_submodule_commits
390
396
391
397
with open (status_file , 'w+' ) as f :
392
- f .write (yaml .dump (status , default_flow_style = False ))
398
+ f .write (yaml .safe_dump (status , default_flow_style = False ))
0 commit comments