MCPcopy
hub / github.com/corpnewt/gibMacOS / run

Method run

Scripts/run.py:97–151  ·  view source on GitHub ↗
(self, command_list, leave_on_fail = False)

Source from the content-addressed store, hash-verified

95 return (self._decode(c[0]), self._decode(c[1]), p.returncode)
96
97 def run(self, command_list, leave_on_fail = False):
98 # Command list should be an array of dicts
99 if type(command_list) is dict:
100 # We only have one command
101 command_list = [command_list]
102 output_list = []
103 for comm in command_list:
104 args = comm.get("args", [])
105 shell = comm.get("shell", False)
106 stream = comm.get("stream", False)
107 sudo = comm.get("sudo", False)
108 stdout = comm.get("stdout", False)
109 stderr = comm.get("stderr", False)
110 mess = comm.get("message", None)
111 show = comm.get("show", False)
112
113 if not mess == None:
114 print(mess)
115
116 if not len(args):
117 # nothing to process
118 continue
119 if sudo:
120 # Check if we have sudo
121 out = self._run_command(["which", "sudo"])
122 if "sudo" in out[0]:
123 # Can sudo
124 if type(args) is list:
125 args.insert(0, out[0].replace("\n", "")) # add to start of list
126 elif type(args) is str:
127 args = out[0].replace("\n", "") + " " + args # add to start of string
128
129 if show:
130 print(" ".join(args))
131
132 if stream:
133 # Stream it!
134 out = self._stream_output(args, shell)
135 else:
136 # Just run and gather output
137 out = self._run_command(args, shell)
138 if stdout and len(out[0]):
139 print(out[0])
140 if stderr and len(out[1]):
141 print(out[1])
142 # Append output
143 output_list.append(out)
144 # Check for errors
145 if leave_on_fail and out[2] != 0:
146 # Got an error - leave
147 break
148 if len(output_list) == 1:
149 # We only ran one command - just return that output
150 return output_list[0]
151 return output_list

Callers 15

check_7zMethod · 0.80
diskpart_flagMethod · 0.80
diskpart_eraseMethod · 0.80
select_packageMethod · 0.80
dd_imageMethod · 0.80
install_ocMethod · 0.80
install_cloverMethod · 0.80
mount_dmgMethod · 0.80
unmount_dmgMethod · 0.80
mainMethod · 0.80
mainMethod · 0.80
__init__Method · 0.80

Calls 2

_run_commandMethod · 0.95
_stream_outputMethod · 0.95

Tested by

no test coverage detected