#!/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):
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')
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)