9
9
run tests on based on the branch-difference (to allow checking of only files
10
10
which a developer has actually modified on their branch)
11
11
"""
12
- import re
12
+
13
13
import os
14
+ import re
14
15
import subprocess
15
16
import time
16
17
@@ -20,10 +21,11 @@ class FCMError(Exception):
20
21
"""
21
22
Exception class for FCM commands
22
23
"""
24
+
23
25
def __str__ (self ):
24
- return ( " \n FCM command: \ " {0:s}\" "
25
- " \n Failed with error: \" {1:s} \" "
26
- . format ( " " . join ( self . args [ 0 ]), self . args [ 1 ]. strip ()) )
26
+ return ' \n FCM command: "{0:s}" \n Failed with error: "{1:s}"' . format (
27
+ " " . join ( self . args [ 0 ]), self . args [ 1 ]. strip ()
28
+ )
27
29
28
30
29
31
# ------------------------------------------------------------------------------
@@ -32,16 +34,20 @@ def is_trunk(url):
32
34
Given an FCM url, returns True if it appears to be pointing to the
33
35
UM main trunk
34
36
"""
35
- search = re .search (r"""
37
+ search = re .search (
38
+ r"""
36
39
(svn://fcm\d+/\w+_svn/\w+/trunk|
37
40
.*/svn/[\w\.]+/\w+/trunk|
38
41
..*_svn/\w+/trunk)
39
- """ , url , flags = re .VERBOSE )
42
+ """ ,
43
+ url ,
44
+ flags = re .VERBOSE ,
45
+ )
40
46
return search is not None
41
47
42
48
43
49
# ------------------------------------------------------------------------------
44
- def text_decoder (bytes_type_string , codecs = [' utf8' , ' cp1252' ]):
50
+ def text_decoder (bytes_type_string , codecs = [" utf8" , " cp1252" ]):
45
51
"""
46
52
Given a bytes type string variable, attempt to decode it using the codecs
47
53
listed.
@@ -127,18 +133,20 @@ def get_branch_diff_filenames(branch=".", path_override=None):
127
133
# Strip whitespace, and remove blank lines while turning the output into
128
134
# a list of strings.
129
135
bdiff_files = [x .strip () for x in bdiff .split ("\n " ) if x .strip ()]
130
- bdiff_files = [bfile .split ()[1 ] for bfile in bdiff_files
131
- if bfile .split ()[0 ].strip () == "M" or
132
- bfile .split ()[0 ].strip () == "A" ]
136
+ bdiff_files = [
137
+ bfile .split ()[1 ]
138
+ for bfile in bdiff_files
139
+ if bfile .split ()[0 ].strip () == "M" or bfile .split ()[0 ].strip () == "A"
140
+ ]
133
141
134
142
# Convert the file paths to be relative to the current URL; to do this
135
143
# construct the base path of the trunk URL and compare it to the results
136
144
# of the bdiff command above
137
145
repos_root = get_repository_root (info )
138
- relative_paths = [os . path . relpath ( bfile ,
139
- os .path .join (repos_root ,
140
- "main" , "trunk" ))
141
- for bfile in bdiff_files ]
146
+ relative_paths = [
147
+ os . path . relpath ( bfile , os .path .join (repos_root , "main" , "trunk" ))
148
+ for bfile in bdiff_files
149
+ ]
142
150
143
151
# These relative paths can be joined to an appropriate base to complete
144
152
# the filenames to return
@@ -169,9 +177,9 @@ def run_fcm_command(command, max_retries, snooze):
169
177
"""
170
178
retries = 0
171
179
while True :
172
- output = subprocess .Popen (command ,
173
- stdout = subprocess .PIPE ,
174
- stderr = subprocess . PIPE )
180
+ output = subprocess .Popen (
181
+ command , stdout = subprocess .PIPE , stderr = subprocess . PIPE
182
+ )
175
183
_ = output .wait ()
176
184
if output .returncode == 0 :
177
185
return text_decoder (output .stdout .read ())
@@ -198,8 +206,7 @@ def use_mirror(branch):
198
206
if mirror_key in os .environ :
199
207
branch = os .environ [mirror_key ]
200
208
retries = 2
201
- print ("[INFO] Switching branch used for fcm command to : {0:}" .format (
202
- branch ))
209
+ print (f"[INFO] Switching branch used for fcm command to: { branch } " )
203
210
else :
204
211
retries = 0
205
212
return branch , retries
@@ -211,8 +218,9 @@ def get_repository_root(branch_info):
211
218
Given the raw output from an fcm binfo command - which can be retrieved by
212
219
calling get_branch_info() - returns the Repository Root field
213
220
"""
214
- repos_root = re .search (r"^Repository Root:\s*(?P<url>.*)\s*$" ,
215
- branch_info , flags = re .MULTILINE )
221
+ repos_root = re .search (
222
+ r"^Repository Root:\s*(?P<url>.*)\s*$" , branch_info , flags = re .MULTILINE
223
+ )
216
224
if repos_root :
217
225
repos_root = repos_root .group ("url" )
218
226
else :
@@ -226,8 +234,9 @@ def get_branch_parent(branch_info):
226
234
Given the raw output from an fcm binfo command - which can be retrieved by
227
235
calling get_branch_info() - returns the Branch Parent Field
228
236
"""
229
- parent = re .search (r"^Branch Parent:\s*(?P<parent>.*)$" , branch_info ,
230
- flags = re .MULTILINE )
237
+ parent = re .search (
238
+ r"^Branch Parent:\s*(?P<parent>.*)$" , branch_info , flags = re .MULTILINE
239
+ )
231
240
if parent :
232
241
parent = parent .group ("parent" )
233
242
else :
0 commit comments