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', '') }}
1
+ #!/usr/bin/env python3
2
2
#
3
3
# Copyright (c) 2015 Michael Scherer <[email protected] >
4
4
#
34
34
import syslog
35
35
import argparse
36
36
import shutil
37
+ from io import open
37
38
38
39
39
40
parser = argparse .ArgumentParser (description = "Build middleman sites based "
@@ -96,7 +97,7 @@ def log_print(message):
96
97
except NameError :
97
98
pass
98
99
else :
99
- log_fd .write (message + "\n " )
100
+ log_fd .write (message + u "\n " )
100
101
log_fd .flush ()
101
102
102
103
@@ -112,7 +113,7 @@ def refresh_checkout(checkout_dir):
112
113
result = subprocess .check_output (['git' , 'fetch' , '-q' ], stderr = subprocess .STDOUT )
113
114
except subprocess .CalledProcessError as C :
114
115
notify_error ('setup' , C .output )
115
- debug_print (result .decode ())
116
+ debug_print (result .decode ('utf-8' ))
116
117
117
118
118
119
def get_last_commit (checkout_dir ):
@@ -122,7 +123,7 @@ def get_last_commit(checkout_dir):
122
123
'refs/remotes/origin/%s' % config ['git_version' ]])
123
124
except subprocess .CalledProcessError as C :
124
125
notify_error ('setup' , C .output )
125
- return r .decode ().split ()[0 ]
126
+ return r .decode ('utf-8' ).split ()[0 ]
126
127
127
128
128
129
def get_last_commit_submodule (checkout_dir , submodule ):
@@ -132,7 +133,7 @@ def get_last_commit_submodule(checkout_dir, submodule):
132
133
'refs/remotes/origin/HEAD' ])
133
134
except subprocess .CalledProcessError as C :
134
135
notify_error ('setup' , C .output )
135
- return r .decode ().split ()[0 ]
136
+ return r .decode ('utf-8' ).split ()[0 ]
136
137
137
138
138
139
def get_submodules_checkout (checkout_dir ):
@@ -142,7 +143,7 @@ def get_submodules_checkout(checkout_dir):
142
143
submodule_status = subprocess .check_output (['git' , 'submodule' , 'status' ])
143
144
except subprocess .CalledProcessError as C :
144
145
notify_error ('setup' , C .output )
145
- for s in submodule_status .decode ().split ('\n ' ):
146
+ for s in submodule_status .decode ('utf-8' ).split ('\n ' ):
146
147
# there is a empty line at the end...
147
148
if s :
148
149
result .append (s .split ()[1 ])
@@ -157,7 +158,7 @@ def load_config(config_file):
157
158
print ("Error %s is not a file" % config_file )
158
159
sys .exit (1 )
159
160
160
- with open (config_file ) as f :
161
+ with open (config_file , encoding = 'utf-8' ) as f :
161
162
config = yaml .safe_load (f )
162
163
163
164
return config
@@ -169,7 +170,7 @@ def has_submodules(checkout_dir):
169
170
r = subprocess .check_output (['git' , 'submodule' , 'status' ])
170
171
except subprocess .CalledProcessError as C :
171
172
notify_error ('setup' , C .output )
172
- return len (r .decode ()) > 0
173
+ return len (r .decode ('utf-8' )) > 0
173
174
174
175
175
176
# TODO complete that
@@ -197,7 +198,7 @@ def do_rsync(source):
197
198
config ['remote' ]], stderr = subprocess .STDOUT )
198
199
except subprocess .CalledProcessError as C :
199
200
notify_error ('setup' , C .output )
200
- return r .decode ()
201
+ return r .decode ('utf-8' )
201
202
202
203
203
204
@@ -229,7 +230,7 @@ def do_rsync(source):
229
230
status_file = os .path .expanduser ('~/status_%s.yml' % name )
230
231
status = {}
231
232
if os .path .exists (status_file ):
232
- with open (status_file ) as f :
233
+ with open (status_file , encoding = 'utf-8' ) as f :
233
234
# in case it's empty
234
235
status = yaml .safe_load (f ) or {}
235
236
@@ -281,32 +282,32 @@ def do_rsync(source):
281
282
# Do not open earlier or we would end-up logging a lot of
282
283
# "Nothing to build" messages and lose the last build log.
283
284
log_file = os .path .expanduser ('~/%s.log' % name )
284
- log_fd = open (log_file , "w" )
285
- log_fd .write ("last_build_date: {}\n " .format (datetime .datetime .utcnow ().strftime ("%Y-%m-%d %H:%M:%S (UTC)" )))
286
- log_fd .write ("last_build_commit: {}\n " .format (current_commit ))
287
- log_fd .write ("submodule_commits: {}\n " .format (current_submodule_commits ))
288
- log_fd .write ("\n " )
285
+ log_fd = open (log_file , "w" , encoding = 'utf-8' )
286
+ log_fd .write (u "last_build_date: {}\n " .format (datetime .datetime .utcnow ().strftime ("%Y-%m-%d %H:%M:%S (UTC)" )))
287
+ log_fd .write (u "last_build_commit: {}\n " .format (current_commit ))
288
+ log_fd .write (u "submodule_commits: {}\n " .format (current_submodule_commits ))
289
+ log_fd .write (u "\n " )
289
290
290
291
syslog .syslog ("Start the build of {}" .format (name ))
291
292
292
293
os .chdir (checkout_dir )
293
294
if not args .no_refresh :
294
295
try :
295
296
result = subprocess .check_output (['git' , 'stash' ], stderr = subprocess .STDOUT )
296
- debug_print (result .decode ())
297
+ debug_print (result .decode ('utf-8' ))
297
298
result = subprocess .check_output (['git' , 'stash' , 'clear' ], stderr = subprocess .STDOUT )
298
- debug_print (result .decode ())
299
+ debug_print (result .decode ('utf-8' ))
299
300
result = subprocess .check_output (['git' , 'pull' , '--rebase' ], stderr = subprocess .STDOUT )
300
- debug_print (result .decode ())
301
+ debug_print (result .decode ('utf-8' ))
301
302
except subprocess .CalledProcessError as C :
302
303
notify_error ('setup' , C .output )
303
304
304
305
if has_submodules (checkout_dir ):
305
306
try :
306
307
result = subprocess .check_output (['git' , 'submodule' , 'init' ], stderr = subprocess .STDOUT )
307
- debug_print (result .decode ())
308
+ debug_print (result .decode ('utf-8' ))
308
309
result = subprocess .check_output (['git' , 'submodule' , 'sync' ], stderr = subprocess .STDOUT )
309
- debug_print (result .decode ())
310
+ debug_print (result .decode ('utf-8' ))
310
311
except subprocess .CalledProcessError as C :
311
312
notify_error ('setup' , C .output )
312
313
@@ -336,7 +337,7 @@ def do_rsync(source):
336
337
# don't use embedded libraries to build Nokogiri
337
338
os .environ ['NOKOGIRI_USE_SYSTEM_LIBRARIES' ] = '1'
338
339
result = subprocess .check_output (['bundle' , 'install' ], stderr = subprocess .STDOUT )
339
- debug_print (result .decode ())
340
+ debug_print (result .decode ('utf-8' ))
340
341
except subprocess .CalledProcessError as C :
341
342
log_print (C .output )
342
343
if config ['remote' ]:
@@ -356,7 +357,7 @@ def do_rsync(source):
356
357
command = builder_info [config ['builder' ]]['build_command' ]
357
358
syslog .syslog ("Build of {}: {}" .format (name , ' ' .join (command )))
358
359
result = subprocess .check_output (command , stderr = subprocess .STDOUT )
359
- debug_print (result .decode ())
360
+ debug_print (result .decode ('utf-8' ))
360
361
except subprocess .CalledProcessError as C :
361
362
log_print (C .output )
362
363
if config ['remote' ]:
@@ -379,7 +380,7 @@ def do_rsync(source):
379
380
else :
380
381
command = builder_info [config ['builder' ]]['deploy_command' ]
381
382
if command :
382
- result = subprocess .check_output (command ).decode ()
383
+ result = subprocess .check_output (command ).decode ('utf-8' )
383
384
else :
384
385
result = "No deployment done: no Rsync settings provided and this builder has no reployment method defined"
385
386
debug_print (result )
@@ -391,9 +392,9 @@ def do_rsync(source):
391
392
392
393
status = {}
393
394
status ['last_build_commit' ] = current_commit
394
- status ['last_build' ] = datetime .datetime .now ().strftime ("%s" )
395
- status ['last_build_human' ] = datetime .datetime .now ().strftime ("%c" )
395
+ status ['last_build' ] = datetime .datetime .now ().strftime (u "%s" )
396
+ status ['last_build_human' ] = datetime .datetime .now ().strftime (u "%c" )
396
397
status ['submodule_commits' ] = current_submodule_commits
397
398
398
- with open (status_file , 'w+' ) as f :
399
+ with open (status_file , 'w+' , encoding = 'utf-8' ) as f :
399
400
f .write (yaml .safe_dump (status , default_flow_style = False ))
0 commit comments