MCPcopy Index your code
hub / github.com/lzhoang2801/OpCore-Simplify / run

Method run

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

Source from the content-addressed store, hash-verified

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

Calls 2

_run_commandMethod · 0.95
_stream_outputMethod · 0.95

Tested by

no test coverage detected