From 9232952e90cccddb2d62a168ff213fa95473b5a6 Mon Sep 17 00:00:00 2001 From: dsc Date: Sun, 9 Jan 2011 00:27:01 -0800 Subject: [PATCH] Adds dep grep to build file. --- pavement.py | 43 +++++++++++++++++++++++++++++++++++++------ 1 files changed, 37 insertions(+), 6 deletions(-) diff --git a/pavement.py b/pavement.py index f9866ca..e0df0f0 100755 --- a/pavement.py +++ b/pavement.py @@ -1,12 +1,13 @@ #!/usr/bin/env paver from paver.easy import * -import yaml, json, os, sys +import yaml, json, os, sys, re +from termcolor import colored BUILD_DIR = path('build') SRC_DIRS = [ path('src')/d for d in ('Y', 'ezl', 'tanks') ] DATA_DIR = path('data') TAGS = None -GIT_VERSION = sh("git show --oneline . | head -n1 | cut -d ' ' -f 1", capture=True).strip() + def commonjs(*args, **kw): @@ -68,16 +69,17 @@ def build_scripts(): def update_version(): "Updates dependency file and build version file." tags = sourceTags() - info('Build Version: {}'.format(GIT_VERSION)) + git_version = sh("git show --oneline . | head -n1 | cut -d ' ' -f 1", capture=True).strip() + info('Build Version: {}'.format(git_version)) with path('build/versioned-deps.html').open('w') as f: - f.write(tags.replace('src="build/', 'src="build/{}/'.format(GIT_VERSION))) + f.write(tags.replace('src="build/', 'src="build/{}/'.format(git_version))) with path('build/versioned-build.html').open('w') as f: - f.write('\n'.format(GIT_VERSION)) + f.write('\n'.format(git_version)) @task def build_version(): "Displays build version only (use -q to suppress paver garbage)." - print GIT_VERSION + sh("git show --oneline . | head -n1 | cut -d ' ' -f 1") @task @needs('update_version') @@ -88,6 +90,35 @@ def build(): pass @task +@cmdopts([ + ('depends=', 'd', 'Show all modules that depend on listed modules (separate with commas)'), + ('module=', 'm', 'Show only specified modules (separate with commas)') +]) +def deps(options): + "Lists dependencies optionally filtered by module or substring." + patterns = [] + pattern = None + depends = options.deps.get('depends', None) + if depends: + depends_pat = r'|'.join(depends.replace('.', r'\.').split(',')) + patterns.append(r'(?:(?<=, | )(%s)(?=,|$))' % depends_pat) + + module = options.deps.get('module', None) + if module: + mod_pat = r'|'.join(module.replace('.', r'\.').split(',')) + patterns.append(r'(?:(%s)(?=.*?\-\>))' % mod_pat) + + if patterns: + pattern = re.compile(r'(%s)' % r'|'.join(patterns), re.I) + repl_pat = colored(r'\1', color='magenta')#, attrs=['bold']) + + for line in commonjs(dump='deps', capture=True).split('\n'): + if not pattern: + print line + elif pattern.search(line): + print pattern.subn(repl_pat, line)[0] + +@task def clean(): "Cleans dep cache and build files" commonjs(clean=True) -- 1.7.0.4