diff options
-rw-r--r-- | git_superproject.py | 51 | ||||
-rw-r--r-- | tests/test_git_superproject.py | 1 |
2 files changed, 28 insertions, 24 deletions
diff --git a/git_superproject.py b/git_superproject.py index b5c262b4..69a4d1fe 100644 --- a/git_superproject.py +++ b/git_superproject.py | |||
@@ -125,23 +125,24 @@ class Superproject(object): | |||
125 | """Returns the manifest path if the path exists or None.""" | 125 | """Returns the manifest path if the path exists or None.""" |
126 | return self._manifest_path if os.path.exists(self._manifest_path) else None | 126 | return self._manifest_path if os.path.exists(self._manifest_path) else None |
127 | 127 | ||
128 | def _LogMessage(self, message): | 128 | def _LogMessage(self, fmt, *inputs): |
129 | """Logs message to stderr and _git_event_log.""" | 129 | """Logs message to stderr and _git_event_log.""" |
130 | message = f'{self._LogMessagePrefix()} {fmt.format(*inputs)}' | ||
130 | if self._print_messages: | 131 | if self._print_messages: |
131 | print(message, file=sys.stderr) | 132 | print(message, file=sys.stderr) |
132 | self._git_event_log.ErrorEvent(message, f'{message}') | 133 | self._git_event_log.ErrorEvent(message, fmt) |
133 | 134 | ||
134 | def _LogMessagePrefix(self): | 135 | def _LogMessagePrefix(self): |
135 | """Returns the prefix string to be logged in each log message""" | 136 | """Returns the prefix string to be logged in each log message""" |
136 | return f'repo superproject branch: {self._branch} url: {self._remote_url}' | 137 | return f'repo superproject branch: {self._branch} url: {self._remote_url}' |
137 | 138 | ||
138 | def _LogError(self, message): | 139 | def _LogError(self, fmt, *inputs): |
139 | """Logs error message to stderr and _git_event_log.""" | 140 | """Logs error message to stderr and _git_event_log.""" |
140 | self._LogMessage(f'{self._LogMessagePrefix()} error: {message}') | 141 | self._LogMessage(f'error: {fmt}', *inputs) |
141 | 142 | ||
142 | def _LogWarning(self, message): | 143 | def _LogWarning(self, fmt, *inputs): |
143 | """Logs warning message to stderr and _git_event_log.""" | 144 | """Logs warning message to stderr and _git_event_log.""" |
144 | self._LogMessage(f'{self._LogMessagePrefix()} warning: {message}') | 145 | self._LogMessage(f'warning: {fmt}', *inputs) |
145 | 146 | ||
146 | def _Init(self): | 147 | def _Init(self): |
147 | """Sets up a local Git repository to get a copy of a superproject. | 148 | """Sets up a local Git repository to get a copy of a superproject. |
@@ -162,8 +163,8 @@ class Superproject(object): | |||
162 | capture_stderr=True) | 163 | capture_stderr=True) |
163 | retval = p.Wait() | 164 | retval = p.Wait() |
164 | if retval: | 165 | if retval: |
165 | self._LogWarning(f'git init call failed, command: git {cmd}, ' | 166 | self._LogWarning('git init call failed, command: git {}, ' |
166 | f'return code: {retval}, stderr: {p.stderr}') | 167 | 'return code: {}, stderr: {}', cmd, retval, p.stderr) |
167 | return False | 168 | return False |
168 | return True | 169 | return True |
169 | 170 | ||
@@ -174,7 +175,7 @@ class Superproject(object): | |||
174 | True if fetch is successful, or False. | 175 | True if fetch is successful, or False. |
175 | """ | 176 | """ |
176 | if not os.path.exists(self._work_git): | 177 | if not os.path.exists(self._work_git): |
177 | self._LogWarning(f'git fetch missing directory: {self._work_git}') | 178 | self._LogWarning('git fetch missing directory: {}', self._work_git) |
178 | return False | 179 | return False |
179 | if not git_require((2, 28, 0)): | 180 | if not git_require((2, 28, 0)): |
180 | self._LogWarning('superproject requires a git version 2.28 or later') | 181 | self._LogWarning('superproject requires a git version 2.28 or later') |
@@ -200,8 +201,8 @@ class Superproject(object): | |||
200 | capture_stderr=True) | 201 | capture_stderr=True) |
201 | retval = p.Wait() | 202 | retval = p.Wait() |
202 | if retval: | 203 | if retval: |
203 | self._LogWarning(f'git fetch call failed, command: git {cmd}, ' | 204 | self._LogWarning('git fetch call failed, command: git {}, ' |
204 | f'return code: {retval}, stderr: {p.stderr}') | 205 | 'return code: {}, stderr: {}', cmd, retval, p.stderr) |
205 | return False | 206 | return False |
206 | return True | 207 | return True |
207 | 208 | ||
@@ -214,7 +215,7 @@ class Superproject(object): | |||
214 | data: data returned from 'git ls-tree ...' instead of None. | 215 | data: data returned from 'git ls-tree ...' instead of None. |
215 | """ | 216 | """ |
216 | if not os.path.exists(self._work_git): | 217 | if not os.path.exists(self._work_git): |
217 | self._LogWarning(f'git ls-tree missing directory: {self._work_git}') | 218 | self._LogWarning('git ls-tree missing directory: {}', self._work_git) |
218 | return None | 219 | return None |
219 | data = None | 220 | data = None |
220 | branch = 'HEAD' if not self._branch else self._branch | 221 | branch = 'HEAD' if not self._branch else self._branch |
@@ -229,8 +230,8 @@ class Superproject(object): | |||
229 | if retval == 0: | 230 | if retval == 0: |
230 | data = p.stdout | 231 | data = p.stdout |
231 | else: | 232 | else: |
232 | self._LogWarning(f'git ls-tree call failed, command: git {cmd}, ' | 233 | self._LogWarning('git ls-tree call failed, command: git {}, ' |
233 | f'return code: {retval}, stderr: {p.stderr}') | 234 | 'return code: {}, stderr: {}', cmd, retval, p.stderr) |
234 | return data | 235 | return data |
235 | 236 | ||
236 | def Sync(self, git_event_log): | 237 | def Sync(self, git_event_log): |
@@ -244,16 +245,16 @@ class Superproject(object): | |||
244 | """ | 245 | """ |
245 | self._git_event_log = git_event_log | 246 | self._git_event_log = git_event_log |
246 | if not self._manifest.superproject: | 247 | if not self._manifest.superproject: |
247 | self._LogWarning(f'superproject tag is not defined in manifest: ' | 248 | self._LogWarning('superproject tag is not defined in manifest: {}', |
248 | f'{self._manifest.manifestFile}') | 249 | self._manifest.manifestFile) |
249 | return SyncResult(False, False) | 250 | return SyncResult(False, False) |
250 | 251 | ||
251 | _PrintBetaNotice() | 252 | _PrintBetaNotice() |
252 | 253 | ||
253 | should_exit = True | 254 | should_exit = True |
254 | if not self._remote_url: | 255 | if not self._remote_url: |
255 | self._LogWarning(f'superproject URL is not defined in manifest: ' | 256 | self._LogWarning('superproject URL is not defined in manifest: {}', |
256 | f'{self._manifest.manifestFile}') | 257 | self._manifest.manifestFile) |
257 | return SyncResult(False, should_exit) | 258 | return SyncResult(False, should_exit) |
258 | 259 | ||
259 | if not self._Init(): | 260 | if not self._Init(): |
@@ -276,8 +277,8 @@ class Superproject(object): | |||
276 | 277 | ||
277 | data = self._LsTree() | 278 | data = self._LsTree() |
278 | if not data: | 279 | if not data: |
279 | self._LogWarning(f'git ls-tree failed to return data for manifest: ' | 280 | self._LogWarning('git ls-tree failed to return data for manifest: {}', |
280 | f'{self._manifest.manifestFile}') | 281 | self._manifest.manifestFile) |
281 | return CommitIdsResult(None, True) | 282 | return CommitIdsResult(None, True) |
282 | 283 | ||
283 | # Parse lines like the following to select lines starting with '160000' and | 284 | # Parse lines like the following to select lines starting with '160000' and |
@@ -303,7 +304,7 @@ class Superproject(object): | |||
303 | manifest_path: Path name of the file into which manifest is written instead of None. | 304 | manifest_path: Path name of the file into which manifest is written instead of None. |
304 | """ | 305 | """ |
305 | if not os.path.exists(self._superproject_path): | 306 | if not os.path.exists(self._superproject_path): |
306 | self._LogWarning(f'missing superproject directory: {self._superproject_path}') | 307 | self._LogWarning('missing superproject directory: {}', self._superproject_path) |
307 | return None | 308 | return None |
308 | manifest_str = self._manifest.ToXml(groups=self._manifest.GetGroupsStr(), | 309 | manifest_str = self._manifest.ToXml(groups=self._manifest.GetGroupsStr(), |
309 | omit_local=True).toxml() | 310 | omit_local=True).toxml() |
@@ -312,7 +313,8 @@ class Superproject(object): | |||
312 | with open(manifest_path, 'w', encoding='utf-8') as fp: | 313 | with open(manifest_path, 'w', encoding='utf-8') as fp: |
313 | fp.write(manifest_str) | 314 | fp.write(manifest_str) |
314 | except IOError as e: | 315 | except IOError as e: |
315 | self._LogError(f'cannot write manifest to : {manifest_path} {e}') | 316 | self._LogError('cannot write manifest to : {} {}', |
317 | manifest_path, e) | ||
316 | return None | 318 | return None |
317 | return manifest_path | 319 | return manifest_path |
318 | 320 | ||
@@ -364,8 +366,9 @@ class Superproject(object): | |||
364 | # If superproject doesn't have a commit id for a project, then report an | 366 | # If superproject doesn't have a commit id for a project, then report an |
365 | # error event and continue as if do not use superproject is specified. | 367 | # error event and continue as if do not use superproject is specified. |
366 | if projects_missing_commit_ids: | 368 | if projects_missing_commit_ids: |
367 | self._LogWarning(f'please file a bug using {self._manifest.contactinfo.bugurl} ' | 369 | self._LogWarning('please file a bug using {} to report missing ' |
368 | f'to report missing commit_ids for: {projects_missing_commit_ids}') | 370 | 'commit_ids for: {}', self._manifest.contactinfo.bugurl, |
371 | projects_missing_commit_ids) | ||
369 | return UpdateProjectsResult(None, False) | 372 | return UpdateProjectsResult(None, False) |
370 | 373 | ||
371 | for project in projects: | 374 | for project in projects: |
diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py index 0bdf1a4e..b9b597a6 100644 --- a/tests/test_git_superproject.py +++ b/tests/test_git_superproject.py | |||
@@ -163,6 +163,7 @@ class SuperprojectTestCase(unittest.TestCase): | |||
163 | sync_result = self._superproject.Sync(self.git_event_log) | 163 | sync_result = self._superproject.Sync(self.git_event_log) |
164 | self.assertFalse(sync_result.success) | 164 | self.assertFalse(sync_result.success) |
165 | self.assertTrue(sync_result.fatal) | 165 | self.assertTrue(sync_result.fatal) |
166 | self.verifyErrorEvent() | ||
166 | 167 | ||
167 | def test_superproject_get_superproject_mock_init(self): | 168 | def test_superproject_get_superproject_mock_init(self): |
168 | """Test with _Init failing.""" | 169 | """Test with _Init failing.""" |