summaryrefslogtreecommitdiff
path: root/dotbot
diff options
context:
space:
mode:
authorAnish Athalye <me@anishathalye.com>2014-10-22 14:44:40 -0400
committerAnish Athalye <me@anishathalye.com>2014-10-22 14:44:40 -0400
commitafebc0bb2fe817778f77d0fcfe30e508bf15d441 (patch)
tree98c0e9b3aefdfb7b0cf9955d37c833542adb1059 /dotbot
parent13c925be87ddf946773689ec51fd0251f795a9c4 (diff)
Add functionality to create parent directories
This commit introduces an additional option for extended configuration syntax for linking. It adds the "create" parameter which results in automatically creating a parent directory if necessary before linking a file.
Diffstat (limited to 'dotbot')
-rw-r--r--dotbot/executor/linker.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/dotbot/executor/linker.py b/dotbot/executor/linker.py
index 2d14ecc..c3d6dc5 100644
--- a/dotbot/executor/linker.py
+++ b/dotbot/executor/linker.py
@@ -23,6 +23,9 @@ class Linker(Executor):
# extended config
path = source['path']
force = source.get('force', False)
+ create = source.get('create', False)
+ if create:
+ success &= self._create(destination)
if force:
success &= self._delete(destination)
else:
@@ -55,6 +58,19 @@ class Linker(Executor):
path = os.path.expanduser(path)
return os.path.exists(path)
+ def _create(self, path):
+ success = True
+ parent = os.path.abspath(os.path.join(os.path.expanduser(path), os.pardir))
+ if not self._exists(parent):
+ try:
+ os.makedirs(parent)
+ except OSError:
+ self._log.warning('Failed to create directory %s' % parent)
+ success = False
+ else:
+ self._log.lowinfo('Creating directory %s' % parent)
+ return success
+
def _delete(self, path):
success = True
if self._exists(path) and not self._is_link(path):