summaryrefslogtreecommitdiff
path: root/dotbot
diff options
context:
space:
mode:
authorBen Klein <robobenklein@gmail.com>2018-02-23 16:56:19 -0500
committerAnish Athalye <me@anishathalye.com>2018-10-16 20:22:40 -0400
commita9cf9fffe4b7ac6ed9f58d69e06f75681715a0e2 (patch)
treef442551b47ae4d0351b1c5f3dfd79eace82aa327 /dotbot
parentb442b9bdced7d849ddc0ea4283de1f80d9bacd8c (diff)
Implement conditional linking
Diffstat (limited to 'dotbot')
-rw-r--r--dotbot/plugins/link.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/dotbot/plugins/link.py b/dotbot/plugins/link.py
index 5274e3b..bf1c5a9 100644
--- a/dotbot/plugins/link.py
+++ b/dotbot/plugins/link.py
@@ -2,6 +2,7 @@ import os
import glob
import shutil
import dotbot
+import subprocess
class Link(dotbot.Plugin):
@@ -31,6 +32,10 @@ class Link(dotbot.Plugin):
use_glob = defaults.get('glob', False)
if isinstance(source, dict):
# extended config
+ test = source.get('if')
+ if test is not None and not self._test_success(test):
+ self._log.lowinfo('Skipping %s' % destination)
+ continue
relative = source.get('relative', relative)
force = source.get('force', force)
relink = source.get('relink', relink)
@@ -90,6 +95,19 @@ class Link(dotbot.Plugin):
self._log.error('Some links were not successfully set up')
return success
+ def _test_success(self, command):
+ with open(os.devnull, 'w') as devnull:
+ ret = subprocess.call(
+ command,
+ shell=True,
+ stdout=devnull,
+ stderr=devnull,
+ executable=os.environ.get('SHELL'),
+ )
+ if ret != 0:
+ self._log.debug('Test \'%s\' returned false' % command)
+ return ret == 0
+
def _default_source(self, destination, source):
if source is None:
basename = os.path.basename(destination)