implement requested changes for #133
This commit is contained in:
parent
dc4e118c3c
commit
c7e9470300
@ -23,7 +23,6 @@ def command(conf, args):
|
|||||||
ui = get_ui()
|
ui = get_ui()
|
||||||
force = args.force
|
force = args.force
|
||||||
rp = repo.Repository(conf)
|
rp = repo.Repository(conf)
|
||||||
print(type(args.citekeys[0]), args.citekeys[0])
|
|
||||||
|
|
||||||
keys = resolve_citekey_list(repo=rp, citekeys=args.citekeys, ui=ui, exit_on_fail=True)
|
keys = resolve_citekey_list(repo=rp, citekeys=args.citekeys, ui=ui, exit_on_fail=True)
|
||||||
|
|
||||||
|
@ -2,8 +2,7 @@ import io
|
|||||||
import sys
|
import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from six import b, u
|
from six import b
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info[0] == 2:
|
if sys.version_info[0] == 2:
|
||||||
@ -56,7 +55,7 @@ if sys.version_info[0] == 2:
|
|||||||
def to_utf8(s):
|
def to_utf8(s):
|
||||||
return b(s)
|
return b(s)
|
||||||
|
|
||||||
# for details, seehttp://bugs.python.org/issue9779
|
# for details, see http://bugs.python.org/issue9779
|
||||||
class ArgumentParser(argparse.ArgumentParser):
|
class ArgumentParser(argparse.ArgumentParser):
|
||||||
def _print_message(self, message, file=None):
|
def _print_message(self, message, file=None):
|
||||||
"""Fixes the lack of a buffer interface in unicode object """
|
"""Fixes the lack of a buffer interface in unicode object """
|
||||||
@ -66,7 +65,6 @@ if sys.version_info[0] == 2:
|
|||||||
file.write(message.encode('utf-8'))
|
file.write(message.encode('utf-8'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
ustr = str
|
ustr = str
|
||||||
uchr = chr
|
uchr = chr
|
||||||
|
19
pubs/uis.py
19
pubs/uis.py
@ -14,7 +14,8 @@ from .p3 import _get_raw_stdout, _get_raw_stderr, input, ustr
|
|||||||
from .content import check_file, read_text_file, write_file, system_path
|
from .content import check_file, read_text_file, write_file, system_path
|
||||||
|
|
||||||
|
|
||||||
DEBUG = False
|
DEBUG = False # unhandled exceptions traces are printed
|
||||||
|
DEBUG_ALL_TRACES = False # handled exceptions traces are printed
|
||||||
# package-shared ui that can be accessed using :
|
# package-shared ui that can be accessed using :
|
||||||
# from uis import get_ui
|
# from uis import get_ui
|
||||||
# ui = get_ui()
|
# ui = get_ui()
|
||||||
@ -109,10 +110,10 @@ class PrintUI(object):
|
|||||||
def error(self, message, **kwargs):
|
def error(self, message, **kwargs):
|
||||||
kwargs['file'] = self._stderr
|
kwargs['file'] = self._stderr
|
||||||
print('{}: {}'.format(color.dye_err('error', 'error'), message), **kwargs)
|
print('{}: {}'.format(color.dye_err('error', 'error'), message), **kwargs)
|
||||||
# if an exception has been raised and debug is on, raise it.
|
|
||||||
if DEBUG or self.debug:
|
if DEBUG_ALL_TRACES: # if an exception has been raised, print the trace.
|
||||||
if sys.exc_info()[0] is not None:
|
if sys.exc_info()[0] is not None:
|
||||||
raise
|
traceback.print_exception(*sys.exc_info)
|
||||||
|
|
||||||
def exit(self, error_code=1):
|
def exit(self, error_code=1):
|
||||||
sys.exit(error_code)
|
sys.exit(error_code)
|
||||||
@ -122,12 +123,12 @@ class PrintUI(object):
|
|||||||
|
|
||||||
:returns: True if exception has been handled (currently never happens)
|
:returns: True if exception has been handled (currently never happens)
|
||||||
"""
|
"""
|
||||||
if (not DEBUG) and (not self.debug):
|
|
||||||
self.error(ustr(exc))
|
|
||||||
self.exit()
|
|
||||||
self.error(ustr(exc))
|
self.error(ustr(exc))
|
||||||
return False
|
if DEBUG or self.debug:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
self.exit()
|
||||||
|
return True # never happens
|
||||||
|
|
||||||
class InputUI(PrintUI):
|
class InputUI(PrintUI):
|
||||||
"""UI class. Stores configuration parameters and system information.
|
"""UI class. Stores configuration parameters and system information.
|
||||||
|
@ -116,10 +116,9 @@ class CommandTestCase(fake_env.TestFakeFs):
|
|||||||
input.as_global()
|
input.as_global()
|
||||||
try:
|
try:
|
||||||
if capture_output:
|
if capture_output:
|
||||||
actual_cmd.split()
|
capture_wrap = fake_env.capture(pubs_cmd.execute,
|
||||||
_, stdout, stderr = fake_env.capture(pubs_cmd.execute,
|
verbose=PRINT_OUTPUT)
|
||||||
verbose=PRINT_OUTPUT)(
|
_, stdout, stderr = capture_wrap(actual_cmd.split())
|
||||||
actual_cmd.split())
|
|
||||||
actual_out = color.undye(stdout)
|
actual_out = color.undye(stdout)
|
||||||
actual_err = color.undye(stderr)
|
actual_err = color.undye(stderr)
|
||||||
if expected_out is not None:
|
if expected_out is not None:
|
||||||
@ -202,6 +201,11 @@ class TestAlone(CommandTestCase):
|
|||||||
self.execute_cmds(['pubs'])
|
self.execute_cmds(['pubs'])
|
||||||
self.assertEqual(cm.exception.code, 2)
|
self.assertEqual(cm.exception.code, 2)
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
|
||||||
|
@unittest.skipIf(sys.version_info.major == 2, "not supported for Python2")
|
||||||
|
>>>>>>> implement requested changes for #133
|
||||||
def test_alone_prints_help(self):
|
def test_alone_prints_help(self):
|
||||||
# capturing the output of `pubs --help` is difficult because argparse
|
# capturing the output of `pubs --help` is difficult because argparse
|
||||||
# raises as SystemExit(0) after calling `print_help`, and this gets
|
# raises as SystemExit(0) after calling `print_help`, and this gets
|
||||||
|
Loading…
x
Reference in New Issue
Block a user