[jhbuild/pre-3-cleanup: 13/16] Add a file parameter to uprint() to allow printing to stderr
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [jhbuild/pre-3-cleanup: 13/16] Add a file parameter to uprint() to allow printing to stderr
- Date: Sun, 22 Sep 2019 10:38:25 +0000 (UTC)
commit b07921b32483b3b7cfd6421c7f1753e62f8540d6
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sun Sep 22 09:32:51 2019 +0200
Add a file parameter to uprint() to allow printing to stderr
This way we don't have to expose the encoding.
jhbuild/main.py | 10 +++++-----
jhbuild/utils/__init__.py | 4 ++--
jhbuild/utils/misc.py | 8 +++-----
3 files changed, 10 insertions(+), 12 deletions(-)
---
diff --git a/jhbuild/main.py b/jhbuild/main.py
index 7d98f6d9..9ac27de5 100644
--- a/jhbuild/main.py
+++ b/jhbuild/main.py
@@ -28,7 +28,7 @@ import gettext
import jhbuild.config
import jhbuild.commands
from jhbuild.errors import UsageError, FatalError
-from jhbuild.utils import uprint, _encoding, install_translation, _
+from jhbuild.utils import uprint, install_translation, _
from jhbuild.moduleset import warn_local_modulesets
@@ -53,7 +53,7 @@ def main(args):
install_translation(gettext.translation('jhbuild', localedir=localedir, fallback=True))
if 'JHBUILD_RUN_AS_ROOT' not in os.environ and hasattr(os, 'getuid') and os.getuid() == 0:
- sys.stderr.write(_('You should not run jhbuild as root.\n').encode(_encoding, 'replace'))
+ uprint(_('You should not run jhbuild as root.\n'), file=sys.stderr)
sys.exit(1)
logging.getLogger().setLevel(logging.INFO)
@@ -94,7 +94,7 @@ def main(args):
try:
config = jhbuild.config.Config(options.configfile, options.conditions)
except FatalError as exc:
- sys.stderr.write('jhbuild: %s\n' % exc.args[0].encode(_encoding, 'replace'))
+ uprint('jhbuild: %s\n' % exc.args[0], file=sys.stderr)
sys.exit(1)
if options.moduleset:
@@ -115,11 +115,11 @@ def main(args):
try:
rc = jhbuild.commands.run(command, config, args, help=lambda: print_help(parser))
except UsageError as exc:
- sys.stderr.write('jhbuild %s: %s\n' % (command, exc.args[0].encode(_encoding, 'replace')))
+ uprint('jhbuild %s: %s\n' % (command, exc.args[0]), file=sys.stderr)
parser.print_usage()
sys.exit(1)
except FatalError as exc:
- sys.stderr.write('jhbuild %s: %s\n' % (command, exc.args[0].encode(_encoding, 'replace')))
+ uprint('jhbuild %s: %s\n' % (command, exc.args[0]), file=sys.stderr)
sys.exit(1)
except KeyboardInterrupt:
uprint(_('Interrupted'))
diff --git a/jhbuild/utils/__init__.py b/jhbuild/utils/__init__.py
index e09400bc..1a206442 100644
--- a/jhbuild/utils/__init__.py
+++ b/jhbuild/utils/__init__.py
@@ -17,6 +17,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from .misc import inpath, try_import_module, uencode, udecode, uprint, _encoding, N_, _, install_translation
+from .misc import inpath, try_import_module, uencode, udecode, uprint, N_, _, install_translation
-inpath, try_import_module, uencode, udecode, uprint, _encoding, N_, _, install_translation
\ No newline at end of file
+inpath, try_import_module, uencode, udecode, uprint, N_, _, install_translation
\ No newline at end of file
diff --git a/jhbuild/utils/misc.py b/jhbuild/utils/misc.py
index f3330fe5..e10f5686 100644
--- a/jhbuild/utils/misc.py
+++ b/jhbuild/utils/misc.py
@@ -69,12 +69,10 @@ def udecode(s):
else:
return s
-def uprint(*args):
+def uprint(*args, **kwargs):
'''Print Unicode string encoded for the terminal'''
- for s in args[:-1]:
- print(uencode(s), end=' ')
- s = args[-1]
- print(uencode(s))
+
+ print(*[uencode(s) for s in args], **kwargs)
def N_(x):
return text_type(x)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]