@@ -72,10 +72,10 @@ def _file_unchanged(old, new):
72
72
return True
73
73
74
74
75
- def shell_out (cmd ):
75
+ def shell_out (cmd , shell = False ):
76
76
logging .debug ("Running command %r" , cmd )
77
77
try :
78
- return subprocess .check_output (cmd , shell = True ,
78
+ return subprocess .check_output (cmd , shell = shell ,
79
79
stdin = subprocess .PIPE ,
80
80
stderr = subprocess .STDOUT ,
81
81
universal_newlines = True )
@@ -108,17 +108,17 @@ def git_clone(repository, directory, branch=None):
108
108
logging .info ("Updating repository %s in %s" , repository , directory )
109
109
try :
110
110
if branch :
111
- shell_out (" git -C {} checkout {}" . format ( directory , branch ) )
112
- shell_out (" git -C {} pull --ff-only" . format ( directory ) )
111
+ shell_out ([ ' git' , '-C' , directory , ' checkout' , branch ] )
112
+ shell_out ([ ' git' , '-C' , directory , ' pull' , ' --ff-only' ] )
113
113
except subprocess .CalledProcessError :
114
114
if os .path .exists (directory ):
115
115
shutil .rmtree (directory )
116
116
logging .info ("Cloning %s into %s" , repository , directory )
117
117
os .makedirs (directory , mode = 0o775 )
118
- shell_out (" git clone --depth 1 --no-single-branch {} {}" . format (
119
- repository , directory ) )
118
+ shell_out ([ ' git' , ' clone' , ' --depth=1' , ' --no-single-branch' ,
119
+ repository , directory ] )
120
120
if branch :
121
- shell_out (" git -C {} checkout {}" . format ( directory , branch ) )
121
+ shell_out ([ ' git' , '-C' , directory , ' checkout' , branch ] )
122
122
123
123
124
124
def pep_545_tag_to_gettext_tag (tag ):
@@ -140,8 +140,7 @@ def translation_branch(locale_repo, locale_clone_dir, needed_version):
140
140
returns the name of the nearest existing branch.
141
141
"""
142
142
git_clone (locale_repo , locale_clone_dir )
143
- remote_branches = shell_out (
144
- "git -C {} branch -r" .format (locale_clone_dir ))
143
+ remote_branches = shell_out (['git' , '-C' , locale_clone_dir , 'branch' , '-r' ])
145
144
translated_branches = []
146
145
for translated_branch in remote_branches .split ('\n ' ):
147
146
if not translated_branch :
@@ -150,7 +149,8 @@ def translation_branch(locale_repo, locale_clone_dir, needed_version):
150
149
translated_branches .append (float (translated_branch .split ('/' )[1 ]))
151
150
except ValueError :
152
151
pass # Skip non-version branches like 'master' if they exists.
153
- return sorted (translated_branches , key = lambda x : abs (needed_version - x ))[0 ]
152
+ return str (sorted (translated_branches ,
153
+ key = lambda x : abs (needed_version - x ))[0 ])
154
154
155
155
156
156
def build_one (version , git_branch , isdev , quick , venv , build_root , www_root ,
@@ -187,7 +187,7 @@ def build_one(version, git_branch, isdev, quick, venv, build_root, www_root,
187
187
os .makedirs (target , exist_ok = True )
188
188
try :
189
189
os .chmod (target , 0o775 )
190
- shell_out (" chgrp -R { group} {file}" . format ( group = group , file = target ) )
190
+ shell_out ([ ' chgrp' , '-R' , group , target ] )
191
191
except (PermissionError , subprocess .CalledProcessError ) as err :
192
192
logging .warning ("Can't change mod or group of %s: %s" ,
193
193
target , str (err ))
@@ -203,39 +203,42 @@ def build_one(version, git_branch, isdev, quick, venv, build_root, www_root,
203
203
shell_out (
204
204
"cd Doc; make PYTHON=%s SPHINXBUILD=%s BLURB=%s VENVDIR=%s SPHINXOPTS='%s' %s >> %s 2>&1" %
205
205
(python , sphinxbuild , blurb , venv , sphinxopts , maketarget ,
206
- os .path .join (log_directory , logname )))
207
- shell_out ("chgrp -R {group} {file}" .format (
208
- group = group , file = log_directory ))
206
+ os .path .join (log_directory , logname )), shell = True )
207
+ shell_out (['chgrp' , '-R' , group , log_directory ])
209
208
changed = changed_files (os .path .join (checkout , "Doc/build/html" ), target )
210
209
logging .info ("Copying HTML files to %s" , target )
211
- shell_out ("chown -R :{} Doc/build/html/" .format (group ))
212
- shell_out ("chmod -R o+r Doc/build/html/" )
213
- shell_out ("find Doc/build/html/ -type d -exec chmod o+x {} ';'" )
214
- shell_out ("rsync -a {delete} Doc/build/html/ {target}" .format (
215
- delete = "" if quick else "--delete-delay" ,
216
- target = target ))
210
+ shell_out (['chown' , '-R' , ':' + group , 'Doc/build/html/' ])
211
+ shell_out (['chmod' , '-R' , 'o+r' , 'Doc/build/html/' ])
212
+ shell_out (['find' , 'Doc/build/html/' , '-type' , 'd' ,
213
+ '-exec' , 'chmod' , 'o+x' , '{}' , ';' ])
214
+ if quick :
215
+ shell_out (['rsync' , '-a' , 'Doc/build/html/' , target ])
216
+ else :
217
+ shell_out (['rsync' , '-a' , '--delete-delay' , 'Doc/build/html/' , target ])
217
218
if not quick :
218
219
logging .debug ("Copying dist files" )
219
- shell_out (" chown -R :{} Doc/dist/" . format ( group ) )
220
- shell_out (" chmod -R o+r Doc/dist/" )
221
- shell_out (" mkdir -m o+rx -p %s/archives" % target )
222
- shell_out (" chown :{} {}/archives" . format ( group , target ) )
223
- shell_out ("cp -a Doc/dist/* %s/archives" % target )
220
+ shell_out ([ ' chown' , '-R' , ':' + group , ' Doc/dist/' ] )
221
+ shell_out ([ ' chmod' , '-R' , ' o+r' , ' Doc/dist/' ] )
222
+ shell_out ([ ' mkdir' , '-m' , ' o+rx' , '-p' , target + '/archives' ] )
223
+ shell_out ([ ' chown' , ':' + group , target + '/archives' ] )
224
+ shell_out ("cp -a Doc/dist/* %s/archives" % target , shell = True )
224
225
changed .append ("archives/" )
225
226
for fn in os .listdir (os .path .join (target , "archives" )):
226
227
changed .append ("archives/" + fn )
227
228
228
229
logging .info ("%s files changed" , len (changed ))
229
230
if changed and not skip_cache_invalidation :
230
231
targets_dir = www_root
231
- prefixes = shell_out ('find -L {} -samefile {}' .format (
232
- targets_dir , target )).replace (targets_dir + '/' , '' )
232
+ prefixes = shell_out (['find' , '-L' , targets_dir ,
233
+ '-samefile' , target ])
234
+ prefixes = prefixes .replace (targets_dir + '/' , '' )
233
235
prefixes = [prefix + '/' for prefix in prefixes .split ('\n ' ) if prefix ]
234
236
to_purge = prefixes [:]
235
237
for prefix in prefixes :
236
238
to_purge .extend (prefix + p for p in changed )
237
239
logging .info ("Running CDN purge" )
238
- shell_out ("curl -X PURGE \" https://docs.python.org/{%s}\" " % "," .join (to_purge ))
240
+ shell_out (['curl' , '-XPURGE' ,
241
+ 'https://docs.python.org/{%s}' % "," .join (to_purge )])
239
242
240
243
logging .info ("Finished %s" , checkout )
241
244
@@ -254,7 +257,7 @@ def parse_args():
254
257
help = "Make HTML files only (Makefile rules suffixed with -html)." )
255
258
parser .add_argument (
256
259
"-b" , "--branch" ,
257
- metavar = 3.6 ,
260
+ metavar = ' 3.6' ,
258
261
type = float ,
259
262
help = "Version to build (defaults to all maintained branches)." )
260
263
parser .add_argument (
0 commit comments