def command_check_ts(tsfiles=None): # Run the basic reference checks by building the jslib if 0 != command_jslib(['--refcheck']): return 1 # Run tslint on all the typescript source if TURBULENZOS == 'win32': tslint = 'tslint.cmd -c .tslintrc -f ' else: tslint = 'tslint -c .tslintrc -f ' tsfiles = tsfiles or ['tslib/*.ts'] files = [] for pattern in tsfiles: for f in iglob(pattern): files.append(f) for f in files: try: sh('%s %s' % (tslint, f), verbose=False) ok(f) except CalledProcessError as e: warning(f) echo(e.output) return 0
def command_check_py(pyfiles=None): def module_glob(pattern): if '*' in pattern or '/' in pattern: return iglob(pattern) else: return [pattern] pylint = 'python -m pylint.lint --rcfile=.pylintrc -f text -r n' pyfiles = pyfiles or ['*.py', 'scripts/*.py'] files = [] for pattern in pyfiles: for p in module_glob(pattern): files.append(p) for f in files: try: sh('%s %s' % (pylint, f), verbose=False) ok(f) except CalledProcessError as e: warning(f) echo(e.output)
def main(): commands = { 'Environment setup': { 'env': (command_env, "initialise the development environment"), 'env-clean': (command_env_clean, "clean the installed environment") }, 'JavaScript build': { 'jslib' : (command_jslib, "build jslib from TypeScript"), 'jslib-clean' : (command_jslib_clean, "clean jslib files built from TypeScript") }, 'Application building': { 'samples': (command_samples, "build the samples"), 'samples-clean': (command_samples_clean, "clean the samples"), 'tools': (command_tools, "build the tools (-h for options)"), 'tools-clean': (command_tools_clean, "clean the tools"), 'apps': (command_apps, "build or clean apps (-h for options)"), 'apps-clean': (command_apps_clean, "clean apps"), }, 'Development': { 'docs': (command_docs, "build the documentation"), 'docs-clean': (command_docs_clean, "clean the documentation"), 'check-docs': (command_check_docs, "build the documentation and check for warnings or errors"), 'check-docs-links': (command_check_docs_links, "check links in the documentation (requires build path e.g. 'builds/docs')"), 'check-ts': (command_check_ts, "check the JavaScript code " \ "generated by TypeScript compiler."), 'check-py': (command_check_py, "check the Python source code"), } } if len(sys.argv) == 1: command_help(commands) return 1 command = sys.argv[1] options = sys.argv[2:] for command_group in commands.itervalues(): try: command_fn, _ = command_group[command] except KeyError: pass else: try: return command_fn(options) except CalledProcessError as e: error(str(e)) return e.retcode except OSError as e: error(str(e)) return e.errno except KeyboardInterrupt as e: error(str(e)) return 1 if command == '--list-commands': for command_group in commands.itervalues(): for command in command_group.iterkeys(): echo(command) return 0 command_help(commands) return 1
def command_help(commands): echo('Usage') echo('=====') echo(' %s command [options]\n' % sys.argv[0]) for title, group in commands.iteritems(): echo('%s commands:' % title) echo((len(title) + 10) * '-') for command, (_, help_txt) in iter(sorted(group.iteritems())): if len(command) > 24: padding = '\n%s' % (' ' * 26) else: padding = ' ' * (24 - len(command)) echo(' %s%s%s' % (command, padding, help_txt)) else: echo() return 1
def command_check_docs_links(args): if len(args) == 0: echo('Path argument required') return 1 return check_documentation_links(args[0])
def command_docs(args): sh(_docs_build_command(), console=True) echo('Docs built to build/docs/html/index.html')
def command_help(commands): echo('Usage') echo('=====') echo(' %s command [options]\n' % sys.argv[0]) for title, group in commands.iteritems(): echo('%s commands:' % title) echo((len(title) + 10) * '-') for command, (_, help_txt) in iter(sorted(group.iteritems())): if len(command) > 24: padding = '\n%s' % (' ' * 26) else: padding = ' ' * (24 - len(command)) echo(' %s%s%s' % (command, padding, help_txt)) echo() return 1