mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-16 02:36:11 +00:00
add check_version config option
This commit is contained in:
@@ -13,6 +13,7 @@ Entry | Description | Default
|
|||||||
-------- | ------------- | ------------
|
-------- | ------------- | ------------
|
||||||
`backup` | Create a backup of the dotfile in case it differs from the one that will be installed by dotdrop | true
|
`backup` | Create a backup of the dotfile in case it differs from the one that will be installed by dotdrop | true
|
||||||
`banner` | Display the banner | true
|
`banner` | Display the banner | true
|
||||||
|
`check_version` | Check if a new version of dotdrop is available on github | false
|
||||||
`chmod_on_import` | Always add a chmod entry on newly imported dotfiles (see `--preserve-mode`) | false
|
`chmod_on_import` | Always add a chmod entry on newly imported dotfiles (see `--preserve-mode`) | false
|
||||||
`cmpignore` | List of patterns to ignore when comparing, applied to all dotfiles (enclose in quotes when using wildcards; see [ignore patterns](config.md#ignore-patterns)) | -
|
`cmpignore` | List of patterns to ignore when comparing, applied to all dotfiles (enclose in quotes when using wildcards; see [ignore patterns](config.md#ignore-patterns)) | -
|
||||||
`create` | Create a directory hierarchy when installing dotfiles if it doesn't exist | true
|
`create` | Create a directory hierarchy when installing dotfiles if it doesn't exist | true
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from dotdrop.comparator import Comparator
|
|||||||
from dotdrop.importer import Importer
|
from dotdrop.importer import Importer
|
||||||
from dotdrop.utils import get_tmpdir, removepath, \
|
from dotdrop.utils import get_tmpdir, removepath, \
|
||||||
uniq_list, patch_ignores, dependencies_met, \
|
uniq_list, patch_ignores, dependencies_met, \
|
||||||
adapt_workers
|
adapt_workers, check_version
|
||||||
from dotdrop.linktypes import LinkTypes
|
from dotdrop.linktypes import LinkTypes
|
||||||
from dotdrop.exceptions import YamlException, \
|
from dotdrop.exceptions import YamlException, \
|
||||||
UndefinedException, UnmetDependency
|
UndefinedException, UnmetDependency
|
||||||
@@ -829,6 +829,9 @@ def main():
|
|||||||
LOG.dbg('\n\n')
|
LOG.dbg('\n\n')
|
||||||
options_time = time.time() - time0
|
options_time = time.time() - time0
|
||||||
|
|
||||||
|
if opts.check_version:
|
||||||
|
check_version()
|
||||||
|
|
||||||
time0 = time.time()
|
time0 = time.time()
|
||||||
ret, command = _exec_command(opts)
|
ret, command = _exec_command(opts)
|
||||||
cmd_time = time.time() - time0
|
cmd_time = time.time() - time0
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ class Options(AttrMonitor):
|
|||||||
self.upignore = None
|
self.upignore = None
|
||||||
self.link_on_import = None
|
self.link_on_import = None
|
||||||
self.chmod_on_import = None
|
self.chmod_on_import = None
|
||||||
|
self.check_version = None
|
||||||
|
|
||||||
# args parsing
|
# args parsing
|
||||||
self.args = {}
|
self.args = {}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class Settings(DictParser):
|
|||||||
key_template_dotfile_default = 'template_dotfile_default'
|
key_template_dotfile_default = 'template_dotfile_default'
|
||||||
key_ignore_missing_in_dotdrop = 'ignore_missing_in_dotdrop'
|
key_ignore_missing_in_dotdrop = 'ignore_missing_in_dotdrop'
|
||||||
key_chmod_on_import = 'chmod_on_import'
|
key_chmod_on_import = 'chmod_on_import'
|
||||||
|
key_check_version = 'check_version'
|
||||||
|
|
||||||
# import keys
|
# import keys
|
||||||
key_import_actions = 'import_actions'
|
key_import_actions = 'import_actions'
|
||||||
@@ -65,7 +66,8 @@ class Settings(DictParser):
|
|||||||
template_dotfile_default=True,
|
template_dotfile_default=True,
|
||||||
ignore_missing_in_dotdrop=False,
|
ignore_missing_in_dotdrop=False,
|
||||||
force_chmod=False,
|
force_chmod=False,
|
||||||
chmod_on_import=False):
|
chmod_on_import=False,
|
||||||
|
check_version=False):
|
||||||
self.backup = backup
|
self.backup = backup
|
||||||
self.banner = banner
|
self.banner = banner
|
||||||
self.create = create
|
self.create = create
|
||||||
@@ -95,6 +97,7 @@ class Settings(DictParser):
|
|||||||
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
|
self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop
|
||||||
self.force_chmod = force_chmod
|
self.force_chmod = force_chmod
|
||||||
self.chmod_on_import = chmod_on_import
|
self.chmod_on_import = chmod_on_import
|
||||||
|
self.check_version = check_version
|
||||||
|
|
||||||
def _serialize_seq(self, name, dic):
|
def _serialize_seq(self, name, dic):
|
||||||
"""serialize attribute 'name' into 'dic'"""
|
"""serialize attribute 'name' into 'dic'"""
|
||||||
@@ -121,6 +124,7 @@ class Settings(DictParser):
|
|||||||
self.key_ignore_missing_in_dotdrop: self.ignore_missing_in_dotdrop,
|
self.key_ignore_missing_in_dotdrop: self.ignore_missing_in_dotdrop,
|
||||||
self.key_force_chmod: self.force_chmod,
|
self.key_force_chmod: self.force_chmod,
|
||||||
self.key_chmod_on_import: self.chmod_on_import,
|
self.key_chmod_on_import: self.chmod_on_import,
|
||||||
|
self.key_check_version: self.check_version,
|
||||||
}
|
}
|
||||||
self._serialize_seq(self.key_default_actions, dic)
|
self._serialize_seq(self.key_default_actions, dic)
|
||||||
self._serialize_seq(self.key_import_actions, dic)
|
self._serialize_seq(self.key_import_actions, dic)
|
||||||
|
|||||||
@@ -15,10 +15,14 @@ import importlib
|
|||||||
import filecmp
|
import filecmp
|
||||||
import itertools
|
import itertools
|
||||||
from shutil import rmtree, which
|
from shutil import rmtree, which
|
||||||
|
import json
|
||||||
|
import requests
|
||||||
|
from packaging import version
|
||||||
|
|
||||||
# local import
|
# local import
|
||||||
from dotdrop.logger import Logger
|
from dotdrop.logger import Logger
|
||||||
from dotdrop.exceptions import UnmetDependency
|
from dotdrop.exceptions import UnmetDependency
|
||||||
|
from dotdrop.version import __version__ as VERSION
|
||||||
|
|
||||||
LOG = Logger()
|
LOG = Logger()
|
||||||
STAR = '*'
|
STAR = '*'
|
||||||
@@ -447,3 +451,22 @@ def debug_dict(title, elems, debug):
|
|||||||
LOG.dbg('\t\t- {}'.format(i))
|
LOG.dbg('\t\t- {}'.format(i))
|
||||||
else:
|
else:
|
||||||
LOG.dbg('\t- \"{}\": {}'.format(k, val))
|
LOG.dbg('\t- \"{}\": {}'.format(k, val))
|
||||||
|
|
||||||
|
|
||||||
|
def check_version():
|
||||||
|
"""check dotdrop version on github and compare with current"""
|
||||||
|
url = 'https://api.github.com/repos/deadc0de6/dotdrop/releases/latest'
|
||||||
|
req = requests.get(url, timeout=1)
|
||||||
|
if not req:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
latest = req.json()['name']
|
||||||
|
except json.decoder.JSONDecodeError:
|
||||||
|
return
|
||||||
|
except ValueError:
|
||||||
|
return
|
||||||
|
if latest.startswith('v'):
|
||||||
|
latest = latest[1:]
|
||||||
|
if version.parse(VERSION) < version.parse(latest):
|
||||||
|
msg = 'A new version of dotdrop is available ({})'
|
||||||
|
LOG.warn(msg.format(latest))
|
||||||
|
|||||||
@@ -2,3 +2,5 @@ Jinja2; python_version > '3.4'
|
|||||||
docopt; python_version > '3.4'
|
docopt; python_version > '3.4'
|
||||||
ruamel.yaml; python_version > '3.4'
|
ruamel.yaml; python_version > '3.4'
|
||||||
python-magic; python_version > '3.4'
|
python-magic; python_version > '3.4'
|
||||||
|
packaging; python_version > '3.4'
|
||||||
|
requests; python_version > '3.4'
|
||||||
|
|||||||
Reference in New Issue
Block a user