* reduce ci matrix
* python runscript without bash
(cherry picked from commit 9b148a6679722db5eb7ffabd3a27a8579f296319)
* change link dest function to handle '\?\' links
* add path normalization for windows support
* Revert "add path normalization for windows support"
This reverts commit 2ab0fc1b3c
.
* link variable extraction without normpath
* type annotation
* blacken
* missing black files
* variable renames from '2775765a' outside link function
* from '2775765a' use method for default flags
* fix defaults from method
* variable renames from '2775765a' in link function and method renames
* refactor if clauses into blocks
* maybe fix if refactor
* remove unreachable code
* remove silly disambiguation semantics
* remove silly disambiguation semantics 2
* incremental else swap
* bring source existence check to front
* bring source existence check to front and remove old back check
* refactor almost final case
* check symlink broken cases up front
* add return missing
* flip block order to make things easier to understand
63 lines
2.3 KiB
Python
63 lines
2.3 KiB
Python
import os
|
|
from .plugin import Plugin
|
|
from .messenger import Messenger
|
|
from .context import Context
|
|
import traceback
|
|
|
|
|
|
class Dispatcher(object):
|
|
def __init__(self, base_directory, only=None, skip=None):
|
|
self._log = Messenger()
|
|
self._setup_context(base_directory)
|
|
self._load_plugins()
|
|
self._only = only
|
|
self._skip = skip
|
|
|
|
def _setup_context(self, base_directory):
|
|
path = os.path.abspath(os.path.expanduser(base_directory))
|
|
if not os.path.exists(path):
|
|
raise DispatchError("Nonexistent base directory")
|
|
self._context = Context(path)
|
|
|
|
def dispatch(self, tasks):
|
|
success = True
|
|
for task in tasks:
|
|
for action in task.keys():
|
|
if (
|
|
self._only is not None
|
|
and action not in self._only
|
|
or self._skip is not None
|
|
and action in self._skip
|
|
) and action != "defaults":
|
|
self._log.info("Skipping action %s" % action)
|
|
continue
|
|
handled = False
|
|
# print("\tcurrent action", action)
|
|
if action == "defaults":
|
|
self._context.set_defaults(task[action]) # replace, not update
|
|
handled = True
|
|
# keep going, let other plugins handle this if they want
|
|
for plugin in self._plugins:
|
|
|
|
if plugin.can_handle(action):
|
|
# print("Action:", action)
|
|
try:
|
|
success &= plugin.handle(action, task[action])
|
|
handled = True
|
|
except Exception as err:
|
|
print("failure", err)
|
|
traceback.print_exception(type(err), err, err.__traceback__)
|
|
self._log.error('An error was encountered while executing action "%s"' % action)
|
|
self._log.debug(err)
|
|
if not handled:
|
|
success = False
|
|
self._log.error('Action "%s" not handled' % action)
|
|
return success
|
|
|
|
def _load_plugins(self):
|
|
self._plugins = [plugin(self._context) for plugin in Plugin.__subclasses__()]
|
|
|
|
|
|
class DispatchError(Exception):
|
|
pass
|