Rizin
unix-like reverse engineering framework and cli tools
meson_git_wrapper.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # SPDX-FileCopyrightText: 2021 ret2libc <sirmy15@gmail.com>
4 # SPDX-License-Identifier: LGPL-3.0-only
5 
6 """ Portable python script to execute git -C (even on system where -C is not available) """
7 
8 import os
9 import subprocess
10 import sys
11 
12 
13 def isCArgSupported(executable, path):
14  try:
15  subprocess.run(
16  [executable, "-C", path, "status"],
17  stdout=subprocess.PIPE,
18  stderr=subprocess.PIPE,
19  check=True,
20  )
21  return True
22  except subprocess.CalledProcessError:
23  return False
24 
25 
27  try:
28  called = subprocess.run(args, check=True)
29  sys.exit(called.returncode)
30  except subprocess.CalledProcessError as e:
31  sys.exit(e.returncode)
32 
33 
34 def parse():
35  if len(sys.argv) <= 3:
36  print(
37  "Usage: {} <git_executable_path> <repo_path> [git_args...]".format(
38  sys.argv[0]
39  )
40  )
41  sys.exit(1)
42 
43  git_exe = sys.argv[1]
44  repo_path = sys.argv[2]
45  args = sys.argv[3:]
46 
47  return git_exe, repo_path, args
48 
49 
50 def main():
51  git_exe, repo_path, args = parse()
52 
53  if isCArgSupported(git_exe, repo_path):
54  simple_git_execution([git_exe, "-C", repo_path] + args)
55  else:
56  os.chdir(repo_path)
57  simple_git_execution([git_exe] + args)
58 
59 
60 if __name__ == "__main__":
61  main()
size_t len
Definition: 6502dis.c:15
def simple_git_execution(args)
def isCArgSupported(executable, path)
Definition: regcomp.c:57