From db5d2ec46f433360552aca8f7043e7f0f6aaeb7b Mon Sep 17 00:00:00 2001 From: Bert van der Weerd Date: Fri, 1 Apr 2022 18:01:09 +0200 Subject: [PATCH] tools.py --- mk.py | 50 ++------------------------------------------------ tools.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 48 deletions(-) create mode 100644 tools.py diff --git a/mk.py b/mk.py index 2360fbe..46c15a4 100644 --- a/mk.py +++ b/mk.py @@ -2,54 +2,8 @@ import os,sys,subprocess,os.path -bash_loc = 'c:/mozilla-build/msys/bin/bash.exe' -do_zip = False - -# native()/bash()/exec() utility functions -def native(cmd,do_print=True): - sys.stdout.flush() - if do_print: - print(cmd) - sys.stdout.flush() - - retval = os.system(cmd) - if retval != 0: - sys.exit(retval) - -def bash(cmd,do_print=True): - tmp = [] - tmp += [bash_loc, '-c', cmd] - sys.stdout.flush() - if do_print: - print(cmd) - sys.stdout.flush() - - retval = subprocess.run(tmp).returncode - if retval != 0: - sys.exit(retval) - -def exec(cmd,do_print=True): - _native = False - if not os.path.isfile(bash_loc): - _native = True - if _native: - return native(cmd,do_print) - return bash(cmd,do_print) - -def patch(patchfile): - cmd = "patch -p1 -i {}".format(patchfile) - sys.stdout.flush() - print("\n*** -> {}".format(cmd)) - sys.stdout.flush() - - retval = os.system(cmd) - if retval != 0: - sys.stdout.flush() - print("fatal error: patch '{}' failed".format(patchfile)) - sys.stdout.flush() - sys.exit(retval) - - +import tools +from tools import exec, patch # # main functions diff --git a/tools.py b/tools.py new file mode 100644 index 0000000..a868301 --- /dev/null +++ b/tools.py @@ -0,0 +1,50 @@ +import os,sys,subprocess,os.path + +bash_loc = 'd:/mozilla-build/msys/bin/bash.exe' +do_zip = False + +# native()/bash()/exec() utility functions +def native(cmd,do_print=True): + sys.stdout.flush() + if do_print: + print(cmd) + sys.stdout.flush() + + retval = os.system(cmd) + if retval != 0: + sys.exit(retval) + +def bash(cmd,do_print=True): + tmp = [] + tmp += [bash_loc, '-c', cmd] + sys.stdout.flush() + if do_print: + print(cmd) + sys.stdout.flush() + + retval = subprocess.run(tmp).returncode + if retval != 0: + sys.exit(retval) + +def exec(cmd,do_print=True): + _native = False + if not os.path.isfile(bash_loc): + _native = True + if _native: + return native(cmd,do_print) + return bash(cmd,do_print) + +def patch(patchfile): + cmd = "patch -p1 -i {}".format(patchfile) + sys.stdout.flush() + print("\n*** -> {}".format(cmd)) + sys.stdout.flush() + + retval = os.system(cmd) + if retval != 0: + sys.stdout.flush() + print("fatal error: patch '{}' failed".format(patchfile)) + sys.stdout.flush() + sys.exit(retval) + +