Skip to content
This repository was archived by the owner on Mar 4, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions skeleton/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
import sys
import weakref

from skeleton.utils import (
get_loggger, get_file_mode, vars_to_optparser, prompt)

from skeleton.utils import (get_loggger, get_file_mode, vars_to_optparser, prompt, ignored)

_LOG = get_loggger(__name__)


class SkeletonError(Exception):
"""Root exception"""

Expand Down Expand Up @@ -244,7 +241,7 @@ def get_missing_variables(self):
_LOG.debug("Variable %r already set", var.name)

@run_requirements_first
def write(self, dst_dir, run_dry=False):
def write(self, dst_dir, run_dry=False, ignore=None):
"""Apply skeleton to `dst_dir`.

Copy files and folders from the `src` folder to the `dst_dir`.
Expand Down Expand Up @@ -283,10 +280,14 @@ def write(self, dst_dir, run_dry=False):

for dir_path, dir_names, file_names in os.walk(real_src):
rel_dir_path = dir_path[real_src_len:].lstrip(r'\/')
# apply template formatting to directories
rel_dir_path = self._format_file_name(rel_dir_path, dir_path)

#copy files
for file_name in file_names:
src = os.path.join(dir_path, file_name)
if ignored(src,ignore):
continue
dst = os.path.join(
dst_dir,
rel_dir_path,
Expand All @@ -297,13 +298,15 @@ def write(self, dst_dir, run_dry=False):
#copy directories
for dir_name in dir_names:
src = os.path.join(dir_path, dir_name)
if ignored(src,ignore):
continue
dst = os.path.join(
dst_dir,
rel_dir_path,
self.template_formatter(dir_name))
self._mkdir(dst, like=src)

def run(self, dst_dir, run_dry=False):
def run(self, dst_dir, run_dry=False, ignore=None):
"""Like write() but prompt user for missing variables.

Raises:
Expand All @@ -314,7 +317,7 @@ def run(self, dst_dir, run_dry=False):
files and folder.
"""
self.get_missing_variables()
self.write(dst_dir, run_dry=run_dry)
self.write(dst_dir, run_dry=run_dry, ignore=ignore)

@classmethod
def cmd(cls, argv=None, **kw):
Expand Down
15 changes: 15 additions & 0 deletions skeleton/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,18 @@ def prompt(prompt_):
return result.decode(sys.stdin.encoding)
except AttributeError:
return result


def ignored(path,ignore):
"""
return true if one of the string in ignore is found in the path
"""
ignored = False

if ignore is not None:
for s in ignore:
if s in path:
ignored = True

return ignored