From f33929d014c21eaabb5471a70abf698af7742b8c Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 24 Aug 2015 14:39:14 +0900 Subject: [PATCH] project.py: Consistently use the _error method to print error messages Use the _error method instead of directly calling `print`. Also add a new _warn convenience method. Change-Id: Ia332c14ef8d9d1fe2df128dbf36b5521802ccdf1 --- project.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/project.py b/project.py index 24cac8bd..4f2b203a 100644 --- a/project.py +++ b/project.py @@ -63,6 +63,10 @@ def _error(fmt, *args): msg = fmt % args print('error: %s' % msg, file=sys.stderr) +def _warn(fmt, *args): + msg = fmt % args + print('warn: %s' % msg, file=sys.stderr) + def not_rev(r): return '^' + r @@ -1092,8 +1096,7 @@ class Project(object): tar.extractall(path=path) return True except (IOError, tarfile.TarError) as e: - print("error: Cannot extract archive %s: " - "%s" % (tarpath, str(e)), file=sys.stderr) + _error("Cannot extract archive %s: %s", tarpath, str(e)) return False def Sync_NetworkHalf(self, @@ -1110,8 +1113,7 @@ class Project(object): """ if archive and not isinstance(self, MetaProject): if self.remote.url.startswith(('http://', 'https://')): - print("error: %s: Cannot fetch archives from http/https " - "remotes." % self.name, file=sys.stderr) + _error("%s: Cannot fetch archives from http/https remotes.", self.name) return False name = self.relpath.replace('\\', '/') @@ -1122,7 +1124,7 @@ class Project(object): try: self._FetchArchive(tarpath, cwd=topdir) except GitError as e: - print('error: %s' % str(e), file=sys.stderr) + _error('%s', e) return False # From now on, we only need absolute tarpath @@ -1133,8 +1135,7 @@ class Project(object): try: os.remove(tarpath) except OSError as e: - print("warn: Cannot remove archive %s: " - "%s" % (tarpath, str(e)), file=sys.stderr) + _warn("Cannot remove archive %s: %s", tarpath, str(e)) self._CopyAndLinkFiles() return True if is_new is None: