diff options
Diffstat (limited to 'dotbot/plugins/create.py')
-rw-r--r-- | dotbot/plugins/create.py | 34 |
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 |