commit 376fc43f72e6cc1beb4aaecd242a4afab6f29bd3 Author: Jan Pokorný jpokorny@redhat.com Date: Thu Mar 15 23:24:35 2012 +0100
prepare-devel.py: add possibility to ignore files
which is useful and needed (scss/_vimrc_local.vim -> css/ not desired)
Signed-off-by: Jan Pokorný jpokorny@redhat.com
prepare-devel.py | 40 +++++++++++++++++++++++++--------------- 1 files changed, 25 insertions(+), 15 deletions(-) --- diff --git a/prepare-devel.py b/prepare-devel.py index f096770..9187b67 100644 --- a/prepare-devel.py +++ b/prepare-devel.py @@ -20,6 +20,8 @@ DEVEL_JAVASCRIPT_ROOT = 'devel-js'
PYSCSS_PATH = join('third-party','git-pyscss')
+IGNORE = ['_vimrc_local.vim', 'dir_info.txt'] + class ParamItems(object): """Base abstract class for local parameters wrapper
@@ -27,8 +29,8 @@ class ParamItems(object): for generating single input parameter (as return value) and generating multiple parameters directly (via `gen_file` et. al.) respectively. """ - def __init__(self, *inputitems): - self.init() + def __init__(self, *inputitems, **kwargs): + self.init(**kwargs) self.add(*inputitems) def init(self): pass @@ -46,12 +48,13 @@ class ParamItems(object): return False
@staticmethod - def proceed(inputitem, destdir=None, pattern='*', pattern_proceed=None): + def proceed(inputitem, destdir=None, pattern='*', pattern_proceed=None, + ignore=()): """Copy files in dir tree + another action with pattern matching ones
The same business in performed if `inputitem` is directly a file. And the "copy" phase can be totally skipped by leaving `destdir` - as `None`. + as `None`. There is also `ignore` as a filter of files to ignore. """ to_copy = [] inputitem = normpath(inputitem) @@ -68,7 +71,7 @@ class ParamItems(object): fpath = join(root, filename) matches = ParamItems._proceed_matching(fpath, pattern, pattern_proceed) - if not matches: + if not matches and not filename in ignore: nonmatching.append(filename) # this arrangment guarantees creating dir only if needed if nonmatching and destdir: @@ -82,8 +85,9 @@ class ParamItems(object): copy2(src, dst)
class StylesheetItems(ParamItems): - def init(self): + def init(self, ignore=(), **kwargs): self._items = [] + self._ignore = ignore def add(self, *inputitems): assert len([item for item in inputitems if item in self._items]) == 0 self._items.extend(inputitems) @@ -91,7 +95,8 @@ class StylesheetItems(ParamItems): outer_self = self destdir = join(*stylesheet_dir) class StylesheetGetter(ContentGetter): - def get(self): + # NOTE: beware of using inner_self + def get(inner_self): from sys import path as sys_path sys_path.insert(0, PYSCSS_PATH) try: @@ -104,19 +109,21 @@ class StylesheetItems(ParamItems): logging.basicConfig(format='%(levelname)s: %(message)s') del logging del sys_path - collected = self.getter.collected + collected = inner_self.getter.collected opts = dict(compress = ifdevel(False, True)(collected)) files = {} - for inputitem in outer_self._items: + for inputitem in self._items: # NOTE: no explicit collision checks - outer_self.proceed(inputitem, destdir, '*css', lambda fn: - files.setdefault(fn, open(fn).read())) + self.proceed(inputitem, destdir, '*css', lambda fn: + files.setdefault(fn, open(fn).read()), + self._ignore) return Scss(scss_opts=opts, scss_files=files).compile() return StylesheetGetter
class JavaScriptItems(ParamItems): - def init(self): + def init(self, ignore=(), **kwargs): self._items = {} + self._ignore = ignore def _inputitem2dict(self, fn): # jquery-ui-1.8.17.js -> jquery_ui_1_8_17, etc. base = splitext(basename(fn))[0].replace('-', '_').replace('.', '_') @@ -124,7 +131,8 @@ class JavaScriptItems(ParamItems): self._items[base] = fn def add(self, *inputitems): for inputitem in inputitems: - self.proceed(inputitem, None, '*.js', self._inputitem2dict) + self.proceed(inputitem, None, '*.js', self._inputitem2dict, + self._ignore) def make_params(self, *javascript_dir): destdir = join(*javascript_dir) for key, item in self._items.iteritems(): @@ -137,8 +145,10 @@ class JavaScriptItems(ParamItems): nonoptions(**{key: base}) # easy access to script within JS dir
# initiate input items with anything appropriate from devel dirs -stylesheet_items = StylesheetItems(join(PACKAGE,PUBLIC,DEVEL_STYLESHEET_ROOT)) -javascript_items = JavaScriptItems(join(PACKAGE,PUBLIC,DEVEL_JAVASCRIPT_ROOT)) +stylesheet_items = StylesheetItems(join(PACKAGE,PUBLIC,DEVEL_STYLESHEET_ROOT), + ignore=IGNORE) +javascript_items = JavaScriptItems(join(PACKAGE,PUBLIC,DEVEL_JAVASCRIPT_ROOT), + ignore=IGNORE)
# RequireJS + requisities (hardcoded as this is referrenced via metadata.py) gen_file('requirejs',
sunzi-devel@lists.fedorahosted.org