summaryrefslogtreecommitdiff
path: root/dotbot/plugins/create.py
diff options
context:
space:
mode:
authorAnish Athalye <me@anishathalye.com>2019-10-12 11:55:18 -0400
committerAnish Athalye <me@anishathalye.com>2019-10-12 11:55:18 -0400
commit04c113b5b85e87969fdbbab22d26bc4aa5398e69 (patch)
treed84ef53e2d8fff0f165727c50f0912a80750c8d4 /dotbot/plugins/create.py
parent32741ea0caea2caf490e9561fd0289ce2150d565 (diff)
parent5a0f6676d41a7291e89f5e32e09396490d71a800 (diff)
Merge branch 'jesseleite/create-directive'
Diffstat (limited to 'dotbot/plugins/create.py')
-rw-r--r--dotbot/plugins/create.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/dotbot/plugins/create.py b/dotbot/plugins/create.py
new file mode 100644
index 0000000..dc119da
--- /dev/null
+++ b/dotbot/plugins/create.py
@@ -0,0 +1,53 @@
+import os
+import glob
+import shutil
+import dotbot
+import subprocess
+
+
+class Create(dotbot.Plugin):
+ '''
+ Create empty paths.
+ '''
+
+ _directive = 'create'
+
+ def can_handle(self, directive):
+ return directive == self._directive
+
+ def handle(self, directive, data):
+ if directive != self._directive:
+ raise ValueError('Create cannot handle directive %s' % directive)
+ return self._process_paths(data)
+
+ def _process_paths(self, paths):
+ success = True
+ for path in paths:
+ path = os.path.expandvars(os.path.expanduser(path))
+ success &= self._create(path)
+ if success:
+ self._log.info('All paths have been set up')
+ else:
+ self._log.error('Some paths were not successfully set up')
+ return success
+
+ def _exists(self, path):
+ '''
+ Returns true if the path exists.
+ '''
+ path = os.path.expanduser(path)
+ return os.path.exists(path)
+
+ def _create(self, path):
+ success = True
+ if not self._exists(path):
+ self._log.debug('Trying to create path %s' % path)
+ try:
+ self._log.lowinfo('Creating path %s' % path)
+ os.makedirs(path)
+ except OSError:
+ self._log.warning('Failed to create path %s' % path)
+ success = False
+ else:
+ self._log.lowinfo('Path exists %s' % path)
+ return success