Commit c49188b7 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Fix history read unicode issue

parent 1d0f1ffa
......@@ -168,25 +168,21 @@ class history_run(_init_history):
def _run_from_line(self, line):
terms = split_input(line)
cmd, args = self._cmd_tree.find_best_match(terms)
if not cmd.is_command:
return
try:
instance = cmd.cmd_class(
self.arguments,
auth_base=getattr(self, 'auth_base', None))
instance.config = self.config
prs = ArgumentParseManager(
cmd.path.split(),
dict(instance.arguments))
prs.syntax = '%s %s' % (
cmd.path.replace('_', ' '),
cmd.cmd_class.syntax)
prs.parse(args)
exec_cmd(instance, prs.unparsed, prs.parser.print_help)
except (CLIError, ClientError) as err:
print_error_message(err, self._err)
except Exception as e:
self.error('Execution of [ %s ] failed\n\t%s' % (line, e))
if cmd.is_command:
try:
instance = cmd.cmd_class(
self.arguments, auth_base=getattr(self, 'auth_base', None))
instance.config = self.config
prs = ArgumentParseManager(
cmd.path.split(), dict(instance.arguments))
prs.syntax = '%s %s' % (
cmd.path.replace('_', ' '), cmd.cmd_class.syntax)
prs.parse(args)
exec_cmd(instance, prs.unparsed, prs.parser.print_help)
except (CLIError, ClientError) as err:
print_error_message(err, self._err)
except Exception as e:
self.error('Execution of [ %s ] failed\n\t%s' % (line, e))
@errors.generic.all
@errors.history._get_cmd_ids
......
......@@ -33,6 +33,8 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
import codecs
class History(object):
def __init__(self, filepath):
......@@ -49,8 +51,8 @@ class History(object):
def get(self, match_terms=None, limit=0):
limit = int(limit) or 0
with open(self.filepath, 'r') as f:
result = ['%s. \t%s' % (
with codecs.open(self.filepath, mode='r', encoding='utf-8') as f:
result = [u'%s. \t%s' % (
i + 1, line) for i, line in enumerate(f.readlines())
if self._match(line, match_terms)]
return result[- limit:]
......
......@@ -221,7 +221,8 @@ def print_list(
item = ('%s' % item).strip()
if item in exclude:
continue
out.writelines(u'%s%s\n' % (print_str, item))
out.write(u'%s%s\n' % (print_str, item))
out.flush()
def print_items(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment