update check at startup
This commit is contained in:
parent
edbe1af3fa
commit
9247c0d3f3
@ -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 :
|
||||
|
@ -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():
|
||||
|
Loading…
x
Reference in New Issue
Block a user