diff --git a/skeleton/core.py b/skeleton/core.py index 7189dfb..8622885 100644 --- a/skeleton/core.py +++ b/skeleton/core.py @@ -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""" @@ -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`. @@ -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, @@ -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: @@ -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): diff --git a/skeleton/utils.py b/skeleton/utils.py index 959a5d2..e554684 100644 --- a/skeleton/utils.py +++ b/skeleton/utils.py @@ -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 +