def main(): """ main() -> None Main entry point function for raptor. """ options = sys.argv[1:] command = "" try: command = options[0] except IndexError: pass aliases = get_aliases() if command in aliases: command = aliases[command] recognized_commands = { commit_exports[0]: commit_exports[1], push_exports[0] : push_exports[1] } if command in recognized_commands: if recognized_commands[command](sys.argv): passthrough(options) else: print_colored('Raptor raised unresolved issues.', color='red') else: passthrough(options)
def lint(files): """ lint(files: [str]) -> boolean Runs the configured linter for each file in files, and returns True if no linter issues are found, False otherwise. """ config = get_config() try: lint_engine = config['linter'] except KeyError: print_colored('No linter configured for this project.', color='yellow') return True print_colored('Running Linter...', color='none') err_codes = 0 for filename in files: for lint_rule in lint_engine: regex = lint_rule['pattern'] if re.match(regex, filename): linter = lint_rule['command'] cmd = '%s %s' % (linter, filename) err_codes += call_command(cmd) break return err_codes == 0
def prompt_lint(files): """ prompt_lint(files: [str]) -> boolean Higher level wrapper around lint() which prompts user upon success or failure. """ if not lint(files): return prompt('Lint raised unresolved issues. Continue?', False) else: print_colored('Lint raised no issues', color='green') return True
def callback(args): """ push_callback() -> bool runs custom push hooks, returns True if everythink ok, False if should abort. """ try: remote_name = args[2] branch_name = args[3].split(':')[1] except IndexError: print_colored('Raptor doesnt support pushing without '+\ 'arguments (yet). Sadface.', color='red') return False # fetch the remote so we have the most up-to-date information call_command('git fetch %s' % (remote_name, )) output = run_command('git diff HEAD %s/%s --name-status' %\ (remote_name, branch_name)) stdout = output['stdout'].strip() stderr = output['stderr'].strip() if stderr.startswith('fatal'): print 'remote has no branch "%s"' % (branch_name,), \ '- falling back to master' output = run_command('git diff HEAD %s/master --name-status' %\ (remote_name, )) stdout = output['stdout'].strip() stderr = output['stderr'].strip() if stderr.startswith('fatal'): print "couldn't push to master. bailing." return False git_files = get_diffed_files(stdout) return prompt_lint(git_files)