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
This commit is contained in:
David Pursehouse 2015-08-24 14:39:14 +09:00
parent 3010e5ba64
commit f33929d014

View File

@ -63,6 +63,10 @@ def _error(fmt, *args):
msg = fmt % args msg = fmt % args
print('error: %s' % msg, file=sys.stderr) 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): def not_rev(r):
return '^' + r return '^' + r
@ -1092,8 +1096,7 @@ class Project(object):
tar.extractall(path=path) tar.extractall(path=path)
return True return True
except (IOError, tarfile.TarError) as e: except (IOError, tarfile.TarError) as e:
print("error: Cannot extract archive %s: " _error("Cannot extract archive %s: %s", tarpath, str(e))
"%s" % (tarpath, str(e)), file=sys.stderr)
return False return False
def Sync_NetworkHalf(self, def Sync_NetworkHalf(self,
@ -1110,8 +1113,7 @@ class Project(object):
""" """
if archive and not isinstance(self, MetaProject): if archive and not isinstance(self, MetaProject):
if self.remote.url.startswith(('http://', 'https://')): if self.remote.url.startswith(('http://', 'https://')):
print("error: %s: Cannot fetch archives from http/https " _error("%s: Cannot fetch archives from http/https remotes.", self.name)
"remotes." % self.name, file=sys.stderr)
return False return False
name = self.relpath.replace('\\', '/') name = self.relpath.replace('\\', '/')
@ -1122,7 +1124,7 @@ class Project(object):
try: try:
self._FetchArchive(tarpath, cwd=topdir) self._FetchArchive(tarpath, cwd=topdir)
except GitError as e: except GitError as e:
print('error: %s' % str(e), file=sys.stderr) _error('%s', e)
return False return False
# From now on, we only need absolute tarpath # From now on, we only need absolute tarpath
@ -1133,8 +1135,7 @@ class Project(object):
try: try:
os.remove(tarpath) os.remove(tarpath)
except OSError as e: except OSError as e:
print("warn: Cannot remove archive %s: " _warn("Cannot remove archive %s: %s", tarpath, str(e))
"%s" % (tarpath, str(e)), file=sys.stderr)
self._CopyAndLinkFiles() self._CopyAndLinkFiles()
return True return True
if is_new is None: if is_new is None: