mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-10 20:14:16 +00:00
exceptions and linting
This commit is contained in:
@@ -19,7 +19,8 @@ from dotdrop.profile import Profile
|
|||||||
from dotdrop.action import Action, Transform
|
from dotdrop.action import Action, Transform
|
||||||
from dotdrop.logger import Logger
|
from dotdrop.logger import Logger
|
||||||
from dotdrop.utils import strip_home, debug_list, debug_dict
|
from dotdrop.utils import strip_home, debug_list, debug_dict
|
||||||
from dotdrop.exceptions import UndefinedException, YamlException
|
from dotdrop.exceptions import UndefinedException, YamlException, \
|
||||||
|
ConfigException
|
||||||
|
|
||||||
|
|
||||||
TILD = '~'
|
TILD = '~'
|
||||||
@@ -400,7 +401,7 @@ class CfgAggregator:
|
|||||||
err = f'{container} does not contain'
|
err = f'{container} does not contain'
|
||||||
err += f' a {keys} entry named {key}'
|
err += f' a {keys} entry named {key}'
|
||||||
self.log.err(err)
|
self.log.err(err)
|
||||||
raise Exception(err)
|
raise ConfigException(err)
|
||||||
objects.append(obj)
|
objects.append(obj)
|
||||||
if not islist:
|
if not islist:
|
||||||
objects = objects[0]
|
objects = objects[0]
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ from dotdrop.utils import get_tmpdir, removepath, \
|
|||||||
adapt_workers, check_version, pivot_path
|
adapt_workers, check_version, pivot_path
|
||||||
from dotdrop.linktypes import LinkTypes
|
from dotdrop.linktypes import LinkTypes
|
||||||
from dotdrop.exceptions import YamlException, \
|
from dotdrop.exceptions import YamlException, \
|
||||||
UndefinedException, UnmetDependency
|
UndefinedException, UnmetDependency, \
|
||||||
|
ConfigException, OptionsException
|
||||||
|
|
||||||
LOG = Logger()
|
LOG = Logger()
|
||||||
TRANS_SUFFIX = 'trans'
|
TRANS_SUFFIX = 'trans'
|
||||||
@@ -877,10 +878,16 @@ def main():
|
|||||||
try:
|
try:
|
||||||
opts = Options()
|
opts = Options()
|
||||||
except YamlException as exc:
|
except YamlException as exc:
|
||||||
LOG.err(f'config error: {exc}')
|
LOG.err(f'error (yaml): {exc}')
|
||||||
|
return False
|
||||||
|
except ConfigException as exc:
|
||||||
|
LOG.err(f'error (config): {exc}')
|
||||||
return False
|
return False
|
||||||
except UndefinedException as exc:
|
except UndefinedException as exc:
|
||||||
LOG.err(f'config error: {exc}')
|
LOG.err(f'error (deps): {exc}')
|
||||||
|
return False
|
||||||
|
except OptionsException as exc:
|
||||||
|
LOG.err(f'error (options): {exc}')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if opts.debug:
|
if opts.debug:
|
||||||
|
|||||||
@@ -10,6 +10,14 @@ class YamlException(Exception):
|
|||||||
"""exception in CfgYaml"""
|
"""exception in CfgYaml"""
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigException(Exception):
|
||||||
|
"""exception in config parsing/aggregation"""
|
||||||
|
|
||||||
|
|
||||||
|
class OptionsException(Exception):
|
||||||
|
"""dotdrop options exception"""
|
||||||
|
|
||||||
|
|
||||||
class UndefinedException(Exception):
|
class UndefinedException(Exception):
|
||||||
"""exception in templating"""
|
"""exception in templating"""
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from dotdrop.logger import Logger
|
|||||||
from dotdrop.cfg_aggregator import CfgAggregator
|
from dotdrop.cfg_aggregator import CfgAggregator
|
||||||
from dotdrop.action import Action
|
from dotdrop.action import Action
|
||||||
from dotdrop.utils import uniq_list, debug_list, debug_dict
|
from dotdrop.utils import uniq_list, debug_list, debug_dict
|
||||||
from dotdrop.exceptions import YamlException
|
from dotdrop.exceptions import YamlException, OptionsException
|
||||||
|
|
||||||
ENV_PROFILE = 'DOTDROP_PROFILE'
|
ENV_PROFILE = 'DOTDROP_PROFILE'
|
||||||
ENV_CONFIG = 'DOTDROP_CONFIG'
|
ENV_CONFIG = 'DOTDROP_CONFIG'
|
||||||
@@ -430,4 +430,4 @@ class Options(AttrMonitor):
|
|||||||
|
|
||||||
def _attr_set(self, attr):
|
def _attr_set(self, attr):
|
||||||
"""error when some inexistent attr is set"""
|
"""error when some inexistent attr is set"""
|
||||||
raise Exception(f'bad option: {attr}')
|
raise OptionsException(f'bad option: {attr}')
|
||||||
|
|||||||
@@ -354,6 +354,7 @@ def dependencies_met():
|
|||||||
|
|
||||||
# check python deps
|
# check python deps
|
||||||
# pylint: disable=C0415
|
# pylint: disable=C0415
|
||||||
|
|
||||||
# python-magic
|
# python-magic
|
||||||
name = 'python-magic'
|
name = 'python-magic'
|
||||||
err = f'missing python module \"{name}\"'
|
err = f'missing python module \"{name}\"'
|
||||||
@@ -372,7 +373,7 @@ def dependencies_met():
|
|||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
assert docopt
|
assert docopt
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
raise Exception(err) from exc
|
raise UnmetDependency(err) from exc
|
||||||
|
|
||||||
# jinja2
|
# jinja2
|
||||||
name = 'jinja2'
|
name = 'jinja2'
|
||||||
@@ -381,7 +382,7 @@ def dependencies_met():
|
|||||||
import jinja2
|
import jinja2
|
||||||
assert jinja2
|
assert jinja2
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
raise Exception(err) from exc
|
raise UnmetDependency(err) from exc
|
||||||
|
|
||||||
# ruamel.yaml
|
# ruamel.yaml
|
||||||
name = 'ruamel.yaml'
|
name = 'ruamel.yaml'
|
||||||
@@ -390,7 +391,7 @@ def dependencies_met():
|
|||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
assert YAML
|
assert YAML
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
raise Exception(err) from exc
|
raise UnmetDependency(err) from exc
|
||||||
|
|
||||||
# toml
|
# toml
|
||||||
name = 'toml'
|
name = 'toml'
|
||||||
@@ -399,7 +400,7 @@ def dependencies_met():
|
|||||||
import toml
|
import toml
|
||||||
assert toml
|
assert toml
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
raise Exception(err) from exc
|
raise UnmetDependency(err) from exc
|
||||||
|
|
||||||
# distro
|
# distro
|
||||||
name = 'distro'
|
name = 'distro'
|
||||||
@@ -408,7 +409,7 @@ def dependencies_met():
|
|||||||
import distro
|
import distro
|
||||||
assert distro
|
assert distro
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
raise Exception(err) from exc
|
raise UnmetDependency(err) from exc
|
||||||
|
|
||||||
# pylint: enable=C0415
|
# pylint: enable=C0415
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user