mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-25 06:55:45 +00:00
rewrited run function
This commit is contained in:
parent
108930ee43
commit
2b72146b26
@ -1,38 +1,17 @@
|
|||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
def run(command, path=None, file_name=None):
|
def run(commands: list, config: dict):
|
||||||
config = {
|
sshProcess = subprocess.Popen(['%s %s' % (config["service"], config["host"])],
|
||||||
"login": "admin",
|
stdin=subprocess.PIPE,
|
||||||
"host": "admin:pass@127.0.0.1:3301",
|
stdout=subprocess.PIPE,
|
||||||
"service": "tarantoolctl connect"
|
universal_newlines=True,
|
||||||
}
|
bufsize=0,
|
||||||
if file_name is not None:
|
shell=True)
|
||||||
file = open(file_name, 'r')
|
|
||||||
commands = [line + '\n' for line in file.readlines() if len(str(line)) > 1]
|
|
||||||
file.close()
|
|
||||||
process = subprocess.Popen(command + config["host"],
|
|
||||||
stdin=subprocess.PIPE,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
universal_newlines=True,
|
|
||||||
bufsize=0,
|
|
||||||
shell=True)
|
|
||||||
|
|
||||||
for cmd in commands:
|
for cmd in commands:
|
||||||
process.stdin.write(cmd)
|
sshProcess.stdin.write(cmd)
|
||||||
process.stdin.close()
|
sshProcess.stdin.close()
|
||||||
|
# TODO To add here Exception Handler for stdout
|
||||||
for line in process.stdout:
|
# for line in sshProcess.stdout:
|
||||||
print(line)
|
# print(line)
|
||||||
|
|
||||||
if path is not None:
|
|
||||||
os.chdir(path)
|
|
||||||
process = subprocess.Popen(command, stdin=subprocess.PIPE,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
universal_newlines=True,
|
|
||||||
bufsize=0,
|
|
||||||
shell=True)
|
|
||||||
output, error = process.communicate()
|
|
||||||
if process.returncode != 0:
|
|
||||||
print(str(process.returncode) + "\n" + str(output) + "\n" + str(error))
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user