summaryrefslogtreecommitdiff
path: root/dotbot/plugins/create.py
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-11-15 16:25:57 +0100
committerAnton Khirnov <anton@khirnov.net>2020-11-15 16:25:57 +0100
commit79c9c0747e876c0b97a4fb3fe91fa9825e462722 (patch)
treeff298dd32dfccfde9921d0ac2c48bc36113a55c6 /dotbot/plugins/create.py
parent5ffd208bdb85215cc7c5ba6f2903bfa7756aa945 (diff)
Add a dry run mode.
Diffstat (limited to 'dotbot/plugins/create.py')
-rw-r--r--dotbot/plugins/create.py34
1 files changed, 23 insertions, 11 deletions
diff --git a/dotbot/plugins/create.py b/dotbot/plugins/create.py
index 2420558..aa14277 100644
--- a/dotbot/plugins/create.py
+++ b/dotbot/plugins/create.py
@@ -9,15 +9,23 @@ class Create(dotbot.Plugin):
_directive = 'create'
- def handle(self, directive, paths):
+ def handle(self, directive, paths, dry_run):
success = True
for path in paths:
path = os.path.expandvars(os.path.expanduser(path))
- success &= self._create(path)
- if success:
- self._log.verbose('All paths have been set up')
+ success &= self._create(path, dry_run)
+
+ if dry_run:
+ if success:
+ self._log.verbose('create/dry run: nothing to do')
+ else:
+ self._log.verbose('create/dry run: some targets are missing')
else:
- self._log.error('Some paths were not successfully set up')
+ if success:
+ self._log.verbose('All paths have been set up')
+ else:
+ self._log.error('Some paths were not successfully set up')
+
return success
def _exists(self, path):
@@ -27,16 +35,20 @@ class Create(dotbot.Plugin):
path = os.path.expanduser(path)
return os.path.exists(path)
- def _create(self, path):
+ def _create(self, path, dry_run):
+ if self._exists(path):
+ self._log.verbose('Path exists %s' % path)
+ return True
+
success = True
- if not self._exists(path):
- self._log.debug('Trying to create path %s' % path)
+ self._log.info('Creating path %s' % path)
+ if dry_run:
+ success = False
+ else:
try:
- self._log.info('Creating path %s' % path)
os.makedirs(path)
except OSError:
self._log.warning('Failed to create path %s' % path)
success = False
- else:
- self._log.verbose('Path exists %s' % path)
+
return success