Merge 81937086b2
into b442b9bdce
This commit is contained in:
commit
4a8aec29b7
|
@ -192,6 +192,7 @@ Available extended configuration parameters:
|
|||
| `force` | Force removes the old target, file or folder, and forces a new link (default:false) |
|
||||
| `relative` | Use a relative path when creating the symlink (default:false, absolute links) |
|
||||
| `glob` | Treat a `*` character as a wildcard, and perform link operations on all of those matches (default:false) |
|
||||
| `if` | Execute this in your `$SHELL` and only link if it is successful. |
|
||||
|
||||
#### Example
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ class Dispatcher(object):
|
|||
self._log.error(
|
||||
'An error was encountered while executing action %s' %
|
||||
action)
|
||||
self._log.debug(err)
|
||||
self._log.debug("Err: " + str(type(err)) + ": " + str(err))
|
||||
if not handled:
|
||||
success = False
|
||||
self._log.error('Action %s not handled' % action)
|
||||
|
@ -43,6 +43,7 @@ class Dispatcher(object):
|
|||
def _load_plugins(self):
|
||||
self._plugins = [plugin(self._context)
|
||||
for plugin in Plugin.__subclasses__()]
|
||||
self._log.debug("Found plugins: " + str(self._plugins))
|
||||
|
||||
class DispatchError(Exception):
|
||||
pass
|
||||
|
|
|
@ -2,6 +2,8 @@ import os
|
|||
import glob
|
||||
import shutil
|
||||
import dotbot
|
||||
import subprocess
|
||||
import copy
|
||||
|
||||
|
||||
class Link(dotbot.Plugin):
|
||||
|
@ -10,6 +12,7 @@ class Link(dotbot.Plugin):
|
|||
'''
|
||||
|
||||
_directive = 'link'
|
||||
_config_if_key = 'if'
|
||||
|
||||
def can_handle(self, directive):
|
||||
return directive == self._directive
|
||||
|
@ -17,7 +20,19 @@ class Link(dotbot.Plugin):
|
|||
def handle(self, directive, data):
|
||||
if directive != self._directive:
|
||||
raise ValueError('Link cannot handle directive %s' % directive)
|
||||
return self._process_links(data)
|
||||
data_filtered = copy.deepcopy(data)
|
||||
for d_key in list(data_filtered):
|
||||
if isinstance(data_filtered[d_key], dict) and self._config_if_key in data_filtered[d_key]:
|
||||
self._log.debug("testing conditional: %s" % data_filtered[d_key][self._config_if_key])
|
||||
commandsuccess = self._test_success(data_filtered[d_key][self._config_if_key])
|
||||
if commandsuccess:
|
||||
# command successful, treat as normal link
|
||||
del data_filtered[d_key][self._config_if_key]
|
||||
else:
|
||||
# remove the item from data, we aren't going to link it
|
||||
del data_filtered[d_key]
|
||||
|
||||
return self._process_links(data_filtered)
|
||||
|
||||
def _process_links(self, links):
|
||||
success = True
|
||||
|
@ -90,6 +105,20 @@ class Link(dotbot.Plugin):
|
|||
self._log.error('Some links were not successfully set up')
|
||||
return success
|
||||
|
||||
def _test_success(self, testcommand):
|
||||
try:
|
||||
osstdout = subprocess.check_output(
|
||||
testcommand,
|
||||
stderr=subprocess.STDOUT,
|
||||
shell=True,
|
||||
executable=os.environ.get("SHELL", "/bin/sh")
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
# self._log.warning("Command failed: " + str(testcommand))
|
||||
self._log.debug("Command returned "+str(e.returncode)+": \n" + str(testcommand))
|
||||
return False
|
||||
return True
|
||||
|
||||
def _default_source(self, destination, source):
|
||||
if source is None:
|
||||
basename = os.path.basename(destination)
|
||||
|
|
Loading…
Reference in New Issue