The update is done transparently, and displays a warning message explaining the change. All the update machinery has been moved to the new update module.main
parent
93c54939b3
commit
757a8b300e
@ -1 +1 @@
|
||||
__version__ = '0.5.0'
|
||||
__version__ = '0.6.0'
|
||||
|
@ -1,39 +0,0 @@
|
||||
import sys
|
||||
|
||||
from .. import repo
|
||||
from .. import color
|
||||
|
||||
from ..uis import get_ui
|
||||
from ..__init__ import __version__
|
||||
|
||||
def parser(subparsers):
|
||||
parser = subparsers.add_parser('update', help='update the repository to the lastest format')
|
||||
return parser
|
||||
|
||||
|
||||
def command(conf, args):
|
||||
|
||||
ui = get_ui()
|
||||
|
||||
code_version = __version__.split('.')
|
||||
if len(conf['internal']['version']) == 1: # support for deprecated version scheme.
|
||||
conf['internal']['version'] = '0.{}.0'.format(conf['internal']['version'])
|
||||
repo_version = conf['internal']['version'].split('.')
|
||||
|
||||
if repo_version == code_version:
|
||||
ui.message('Your pubs repository is up-to-date.')
|
||||
sys.exit(0)
|
||||
elif repo_version > code_version:
|
||||
ui.message('Your repository was generated with an newer version of pubs.\n'
|
||||
'You should not use pubs until you install the newest version.')
|
||||
sys.exit(0)
|
||||
else:
|
||||
msg = ("You should backup the pubs directory {} before continuing."
|
||||
"Continue ?").format(color.dye_out(conf['main']['pubsdir'], color.filepath))
|
||||
sure = ui.input_yn(question=msg, default='n')
|
||||
if not sure:
|
||||
sys.exit(0)
|
||||
|
||||
#TODO: update!!
|
||||
# conf['internal']['version'] = repo_version
|
||||
# conf['internal']['version']
|
@ -1 +1 @@
|
||||
from .conf import load_default_conf, load_conf, save_conf, get_pubspath
|
||||
from .conf import get_confpath, load_default_conf, load_conf, save_conf, check_conf
|
||||
|
@ -0,0 +1,63 @@
|
||||
from . import config
|
||||
from . import uis
|
||||
from .__init__ import __version__
|
||||
|
||||
|
||||
def update_check(conf):
|
||||
"""Runs an update if necessary, and return True in that case."""
|
||||
|
||||
code_version = __version__.split('.')
|
||||
try:
|
||||
repo_version = conf['internal']['version'].split('.')
|
||||
except KeyError:
|
||||
repo_version = ['0', '5', '0']
|
||||
|
||||
if repo_version > code_version:
|
||||
uis.init_ui(config.load_default_conf())
|
||||
ui = uis.get_ui()
|
||||
|
||||
ui.warning(
|
||||
'Your repository was generated with an newer version'
|
||||
' of pubs (v{}) than the one you are using (v{}).'
|
||||
'\n'.format(repo_version, code_version) +
|
||||
'You should not use pubs until you install the '
|
||||
'newest version.')
|
||||
sys.exit()
|
||||
|
||||
elif repo_version < code_version:
|
||||
return update(conf, code_version, repo_version)
|
||||
|
||||
return False
|
||||
|
||||
def update(conf, code_version, repo_version):
|
||||
"""Runs an update if necessary, and return True in that case."""
|
||||
|
||||
if repo_version == ['0', '5', '0']: # we need to update
|
||||
default_conf = config.load_default_conf()
|
||||
uis.init_ui(config.load_default_conf())
|
||||
ui = uis.get_ui()
|
||||
|
||||
for key in ['pubsdir', 'docsdir', 'edit_cmd', 'open_cmd']:
|
||||
default_conf['main'][key] = conf['pubs'][key]
|
||||
if conf['pubs']['import_move']:
|
||||
default_conf['main']['add_doc'] = 'move'
|
||||
elif conf['pubs']['import_copy']:
|
||||
default_conf['main']['add_doc'] = 'copy'
|
||||
else:
|
||||
default_conf['main']['add_doc'] = 'link'
|
||||
|
||||
backup_path = config.get_confpath() + '.old'
|
||||
config.save_conf(conf, path=backup_path)
|
||||
config.save_conf(default_conf)
|
||||
|
||||
ui.warning(
|
||||
'Your configuration file has been updated. '
|
||||
'The old file has been moved to `{}`. '.format(backup_path) +
|
||||
'Some, but not all, of your settings has been transferred '
|
||||
'to the new file.\n'
|
||||
'You can inspect and modify your configuration '
|
||||
' using the `pubs config` command.'
|
||||
)
|
||||
|
||||
return True
|
||||
return False
|
Loading…
Reference in new issue