From 9247c0d3f32ed57ebbae9b3bdf6c4d61d6f8248d Mon Sep 17 00:00:00 2001 From: Fabien Benureau Date: Thu, 4 Jul 2013 21:31:53 +0100 Subject: [PATCH] update check at startup --- papers/configs.py | 9 +++++---- papers/papers_cmd.py | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/papers/configs.py b/papers/configs.py index 391b1b0..25b80e4 100644 --- a/papers/configs.py +++ b/papers/configs.py @@ -15,17 +15,18 @@ DFT_PLUGINS = '' DFT_CONFIG = {'papers_dir' : os.path.expanduser('~/.papers'), 'doc_dir' : 'doc', - 'import_copy' : 'yes', - 'import_move' : 'no', - 'color' : 'yes', + 'import_copy' : True, + 'import_move' : False, + 'color' : True, 'version' : 3, + 'version_warning' : True, 'open_cmd' : 'open', 'edit_cmd' : DFT_EDIT_CMD, 'plugins' : DFT_PLUGINS } -BOOLEANS = {'import_copy', 'import_move', 'color'} +BOOLEANS = {'import_copy', 'import_move', 'color', 'version_warning'} # package-shared config that can be accessed using : diff --git a/papers/papers_cmd.py b/papers/papers_cmd.py index 5118bfb..cd1e138 100644 --- a/papers/papers_cmd.py +++ b/papers/papers_cmd.py @@ -9,6 +9,7 @@ from .ui import UI from . import configs from . import commands from . import plugins +from .__init__ import __version__ cmds = collections.OrderedDict([ ('init', commands.init_cmd), @@ -25,6 +26,26 @@ cmds = collections.OrderedDict([ ('update', commands.update_cmd), ]) +def _update_check(config, ui): + if config.version_warning: + code_version = int(__version__) + repo_version = int(config.version) + + if repo_version > code_version: + ui.print_('warning: your repository was generated with an newer version' + ' of papers (v{}) than the one you are using (v{}).\n'.format( + repo_version, code_version) + + ' you should not use papers until you install the ' + 'newest version. (use version_warning in you papersrc ' + 'to bypass this error)') + sys.exit() + elif repo_version < code_version: + ui.print_( + 'warning: your repository version (v{})'.format(repo_version) + + 'must be updated to version {}.\n'.format(code_version) + + "run 'papers update'.") + sys.exit() + def execute(raw_args = sys.argv): # loading config @@ -34,6 +55,8 @@ def execute(raw_args = sys.argv): ui = UI(config) + _update_check(config, ui) + # Extend with plugin commands plugins.load_plugins(ui, config.plugins.split()) for p in plugins.get_plugins().values():