-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jesseleite/create-directive'
- Loading branch information
Showing
5 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .clean import Clean | ||
from .create import Create | ||
from .link import Link | ||
from .shell import Shell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
test_description='create folders' | ||
. '../test-lib.bash' | ||
|
||
test_expect_success 'run' ' | ||
run_dotbot <<EOF | ||
- create: | ||
- ~/somedir | ||
- ~/nested/somedir | ||
EOF | ||
' | ||
|
||
test_expect_success 'test' ' | ||
[ -d ~/somedir ] && | ||
[ -d ~/nested/somedir ] | ||
' | ||
|
||
test_expect_success 'run 2' ' | ||
run_dotbot <<EOF | ||
- create: | ||
- ~/somedir | ||
- ~/nested/somedir | ||
EOF | ||
' |