def run_hook_cmd(command, files): """ Prepare system command. """ splited_args = shlex.split(command) cmd = splited_args[0] args = splited_args[1:] builtin_path = "" # backward compatibility to 0.1.x if cmd[0] == "_": cmd = "h4g/" + cmd[1:] display.say( "WARN", "Please upgrade your ini file to call built in scripts prefixed by 'h4g/'" ) # backward compatibility to early 0.2.x if cmd[0:8] == "scripts/": cmd = "h4g/" + cmd[8:] display.say( "WARN", "Please upgrade your ini file to call built in scripts prefixed by 'h4g/'" ) # backward compatibility to 0.3.x if cmd[0:21] == "h4g/check_branch_name": _command = shlex.split(command) command = _command[0] if "Windows" not in get_platform(): if len(_command) > 1: command = command + ' "' + _command[1] + '"' # end cmd_list = cmd.split("/") git_root = os_call("git rev-parse --show-toplevel")[1].replace("\n", "") if cmd_list[0] == "h4g": sys.path.insert(0, git_root) add_usersitepackages_to_path("python") add_usersitepackages_to_path("python2") add_usersitepackages_to_path("python3") for path in sys.path: builtin_path = os.path.realpath(path + "/hooks4git/h4g/") _cmd = os.path.realpath(os.path.join(builtin_path, cmd_list[1])) if os.path.exists(_cmd): cmd = os.path.join(builtin_path, cmd_list[1]) break display_message = "%s" % (command) if cmd == "echo": if files: _arg = "--filename=%s" % ",".join(files) args.append(_arg) display_message += " " + _arg.replace( git_root, ".")[:(66 - len(display_message))] + "..." display.say("STEP", "$ %s" % display_message) params = "" try: params = command.split(" ", 1)[1] except: # noqa # nosec pass code, result, err = os_call("%s %s" % (cmd, params)) result = result.strip().replace("\n", "\n".ljust(display.cmdbarwidth + 1) + "| ") err = err.strip().replace("\n", "\n".ljust(display.cmdbarwidth + 1) + "| ") if len(result) > 0: display.say("SOUT", result) if len(err) > 0: display.say("SERR", err) return code, result, err
def test_get_platform_invalid(self): platform = get_platform() self.assertTrue(platform == "FakeOS")
def test_get_platform_win32git(self): platform = get_platform() self.assertTrue(platform == "WindowsGitBash")
def test_get_platform_win32(self): platform = get_platform() self.assertTrue(platform == "Windows")
def test_get_platform_darwin(self): platform = get_platform() self.assertTrue(platform == "Mac")
def test_get_platform_linux2(self): platform = get_platform() self.assertTrue(platform == "Linux")