Adds dep grep to build file.
authordsc <david.schoonover@gmail.com>
Sun, 9 Jan 2011 08:27:01 +0000 (00:27 -0800)
committerdsc <david.schoonover@gmail.com>
Sun, 9 Jan 2011 08:27:01 +0000 (00:27 -0800)
pavement.py

index f9866ca..e0df0f0 100755 (executable)
@@ -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('<script>BUILD="build/{}";</script>\n'.format(GIT_VERSION))
+        f.write('<script>BUILD="build/{}";</script>\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)