diff --git a/pubs/configs.py b/pubs/configs.py index 457a9e6..305b58c 100644 --- a/pubs/configs.py +++ b/pubs/configs.py @@ -1,10 +1,11 @@ import os +import sys import collections from .p3 import configparser, ConfigParser, _read_config from .content import check_file, _open - +from . import __version__ # constant stuff (DFT = DEFAULT) @@ -23,7 +24,7 @@ DFT_CONFIG = collections.OrderedDict([ ('import_copy', True), ('import_move', False), ('color', True), - ('version', 5), + ('version', __version__), ('version_warning', True), ('open_cmd', 'open'), ('edit_cmd', DFT_EDIT_CMD), @@ -66,12 +67,18 @@ class Config(object): if not check_file(path, fail=False): raise IOError(("The configuration file {} does not exist." " Did you run 'pubs init' ?").format(path)) - with _open(path, 'r+') as f: + b_flag = '' + if sys.version_info[0] == 2: # HACK, FIXME please + b_flag = 'b' + with _open(path, 'r{}+'.format(b_flag)) as f: _read_config(self._cfg, f) return self def save(self, path=DFT_CONFIG_PATH): - with _open(path, 'w+') as f: + b_flag = '' + if sys.version_info[0] == 2: # HACK, FIXME please + b_flag = 'b' + with _open(path, 'w{}+'.format(b_flag)) as f: self._cfg.write(f) def __setattr__(self, name, value): diff --git a/pubs/pubs_cmd.py b/pubs/pubs_cmd.py index b254682..5d9cf83 100644 --- a/pubs/pubs_cmd.py +++ b/pubs/pubs_cmd.py @@ -34,7 +34,9 @@ CORE_CMDS = collections.OrderedDict([ def _update_check(config, ui): if config.version_warning: code_version = __version__.split('.') - repo_version = ('0.{}.0'.format(config.version)).split('.') # FIXME + if len(config.version) == 1: # support for deprecated version scheme. + config.version = '0.{}.0'.format(config.version) + repo_version = config.version.split('.') if repo_version > code_version: ui.warning( diff --git a/pubs/uis.py b/pubs/uis.py index cb36b52..1a1d1c8 100644 --- a/pubs/uis.py +++ b/pubs/uis.py @@ -6,7 +6,7 @@ import codecs from .content import editor_input from . import color -from .p3 import _get_raw_stdout, _get_raw_stderr, input +from .p3 import _get_raw_stdout, _get_raw_stderr, input, ustr # package-shared ui that can be accessed using : @@ -93,7 +93,7 @@ class InputUI(PrintUI): except EOFError: self.error(u'Standard input ended while waiting for answer.') self.exit(1) - return data.decode('utf-8') + return ustr(data) #.decode('utf-8') def input_choice_ng(self, options, option_chars=None, default=None, question=''): """Ask the user to chose between a set of options. The iser is asked diff --git a/tests/fake_env.py b/tests/fake_env.py index abe357d..c5299cf 100644 --- a/tests/fake_env.py +++ b/tests/fake_env.py @@ -83,7 +83,8 @@ class UnicodeStringIOWrapper(object): def _force_binary_mode(mode): if 'b' in mode: - raise ValueError('Open should not happen in binary mode.') + return mode # python 2 fix. + # raise ValueError('Open should not happen in binary mode.') return mode + 'b'