mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-03 19:04:40 +01:00
Some output from the Linux VM!!
This commit is contained in:
parent
49a3f880fe
commit
ad8d8f50d1
6 changed files with 53 additions and 49 deletions
|
@ -1,6 +1,6 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
var tmp_prefix = OS.get_user_data_dir() + "/tmp/"
|
var tmp_prefix = get_tmp_prefix()
|
||||||
var global_shell
|
var global_shell
|
||||||
var fake_editor
|
var fake_editor
|
||||||
|
|
||||||
|
@ -17,6 +17,12 @@ var state = {}
|
||||||
|
|
||||||
var mutex
|
var mutex
|
||||||
|
|
||||||
|
func get_tmp_prefix():
|
||||||
|
if OS.get_name() == "Web":
|
||||||
|
return "/tmp/"
|
||||||
|
else:
|
||||||
|
OS.get_user_data_dir() + "/tmp/"
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
mutex = Mutex.new()
|
mutex = Mutex.new()
|
||||||
load_state()
|
load_state()
|
||||||
|
|
|
@ -96,6 +96,8 @@ func careful_delete(path_inside):
|
||||||
# Windows treats paths case-insensitively:
|
# Windows treats paths case-insensitively:
|
||||||
expected_prefix = expected_prefix.to_lower()
|
expected_prefix = expected_prefix.to_lower()
|
||||||
path_inside = path_inside.to_lower()
|
path_inside = path_inside.to_lower()
|
||||||
|
elif os == "Web":
|
||||||
|
expected_prefix = "/tmp"
|
||||||
|
|
||||||
if path_inside.substr(0,expected_prefix.length()) != expected_prefix:
|
if path_inside.substr(0,expected_prefix.length()) != expected_prefix:
|
||||||
helpers.crash("Refusing to delete directory %s that does not start with %s" % [path_inside, expected_prefix])
|
helpers.crash("Refusing to delete directory %s that does not start with %s" % [path_inside, expected_prefix])
|
||||||
|
|
|
@ -12,7 +12,7 @@ func _init():
|
||||||
# Create required directories and move into the tmp directory.
|
# Create required directories and move into the tmp directory.
|
||||||
_cwd = "/tmp"
|
_cwd = "/tmp"
|
||||||
run("mkdir -p '%s/repos'" % game.tmp_prefix)
|
run("mkdir -p '%s/repos'" % game.tmp_prefix)
|
||||||
_cwd = game.tmp_prefixls
|
_cwd = game.tmp_prefix
|
||||||
|
|
||||||
func cd(dir):
|
func cd(dir):
|
||||||
_cwd = dir
|
_cwd = dir
|
||||||
|
@ -39,6 +39,13 @@ func run_async(command, crash_on_fail=true):
|
||||||
|
|
||||||
return shell_command
|
return shell_command
|
||||||
|
|
||||||
|
func run_async_web(command, crash_on_fail=true):
|
||||||
|
var shell_command = ShellCommand.new()
|
||||||
|
shell_command.command = command
|
||||||
|
shell_command.crash_on_fail = crash_on_fail
|
||||||
|
run_async_thread(shell_command)
|
||||||
|
return shell_command
|
||||||
|
|
||||||
func run_async_thread(shell_command):
|
func run_async_thread(shell_command):
|
||||||
var debug = false
|
var debug = false
|
||||||
|
|
||||||
|
@ -86,28 +93,26 @@ func run_async_thread(shell_command):
|
||||||
helpers.write_file(script_path, hacky_command)
|
helpers.write_file(script_path, hacky_command)
|
||||||
result = helpers.exec(_shell_binary(), [script_path], crash_on_fail)
|
result = helpers.exec(_shell_binary(), [script_path], crash_on_fail)
|
||||||
elif _os == "Web":
|
elif _os == "Web":
|
||||||
hacky_command = hacky_command.replace("\\", "\\\\").replace("'", "\\'").replace("\n", "\\n")
|
#hacky_command = hacky_command.replace("\\", "\\\\").replace("'", "\\'").replace("\n", "\\n")
|
||||||
#var js_code = "await run_in_vm('" + hacky_command + "')"
|
#var js_code = "await run_in_vm('" + hacky_command + "')"
|
||||||
#print(js_code)
|
#print(js_code)
|
||||||
#var output = JavaScriptBridge.eval(js_code, true)
|
#var output = JavaScriptBridge.eval(js_code, true)
|
||||||
|
|
||||||
var output = JavaScriptBridge.eval("testy()")
|
#var output = JavaScriptBridge.eval("testy()")
|
||||||
|
|
||||||
#print(hacky_command)
|
#print(hacky_command)
|
||||||
#var output = web_shell.run_in_vm(hacky_command)
|
shell_command.js_callback = JavaScriptBridge.create_callback(Callable(shell_command, "callback"))
|
||||||
|
web_shell.run_in_vm(hacky_command).then(shell_command.js_callback)
|
||||||
result = {}
|
|
||||||
result["output"] = output
|
|
||||||
result["exit_code"] = 0
|
|
||||||
else:
|
else:
|
||||||
helpers.crash("Unimplemented OS: %s" % _os)
|
helpers.crash("Unimplemented OS: %s" % _os)
|
||||||
|
|
||||||
if debug:
|
if _os != "Web":
|
||||||
print(result["output"])
|
if debug:
|
||||||
|
print(result["output"])
|
||||||
|
|
||||||
shell_command.output = result["output"]
|
shell_command.output = result["output"]
|
||||||
shell_command.exit_code = result["exit_code"]
|
shell_command.exit_code = result["exit_code"]
|
||||||
shell_command.emit_signal("done")
|
shell_command.emit_signal("done")
|
||||||
|
|
||||||
func _shell_binary():
|
func _shell_binary():
|
||||||
if _os == "Linux" or _os == "OSX":
|
if _os == "Linux" or _os == "OSX":
|
||||||
|
@ -117,25 +122,8 @@ func _shell_binary():
|
||||||
else:
|
else:
|
||||||
helpers.crash("Unsupported OS: %s" % _os)
|
helpers.crash("Unsupported OS: %s" % _os)
|
||||||
|
|
||||||
#var _t
|
func callback(args):
|
||||||
#func run_async(command):
|
print(args)
|
||||||
# _t = Thread.new()
|
|
||||||
# _t.start(self, "run_async_thread", command)
|
|
||||||
#
|
|
||||||
#func run_async_thread(command):
|
|
||||||
# var port = 1000 + (randi() % 1000)
|
|
||||||
# var s = TCP_Server.new()
|
|
||||||
# s.listen(port)
|
|
||||||
# var _pid = OS.execute("ncat", ["127.0.0.1", str(port), "-c", command], false, [], true)
|
|
||||||
# while not s.is_connection_available():
|
|
||||||
# pass
|
|
||||||
# var c = s.take_connection()
|
|
||||||
# while c.get_status() == StreamPeerTCP.STATUS_CONNECTED:
|
|
||||||
# read_from(c)
|
|
||||||
# OS.delay_msec(1000/30)
|
|
||||||
# read_from(c)
|
|
||||||
# c.disconnect_from_host()
|
|
||||||
# s.stop()
|
|
||||||
|
|
||||||
func read_from(c):
|
func read_from(c):
|
||||||
var total_available = c.get_available_bytes()
|
var total_available = c.get_available_bytes()
|
||||||
|
|
|
@ -8,7 +8,15 @@ var output
|
||||||
var exit_code
|
var exit_code
|
||||||
var crash_on_fail = true
|
var crash_on_fail = true
|
||||||
var thread
|
var thread
|
||||||
|
var js_callback # For JavaScriptBridge
|
||||||
|
|
||||||
func _unused():
|
func _unused():
|
||||||
# This is just to suppress a warning about the signal never being emitted.
|
# This is just to suppress a warning about the signal never being emitted.
|
||||||
emit_signal("done")
|
emit_signal("done")
|
||||||
|
|
||||||
|
func callback(_output):
|
||||||
|
#print(_output)
|
||||||
|
print(_output[0])
|
||||||
|
output = _output[0]
|
||||||
|
exit_code = 0
|
||||||
|
emit_signal("done")
|
||||||
|
|
|
@ -90,16 +90,16 @@ func send_command(command):
|
||||||
|
|
||||||
shell.cd(repository.path)
|
shell.cd(repository.path)
|
||||||
|
|
||||||
#var cmd = shell.run_async(command, false)
|
var cmd = shell.run_async_web(command, false)
|
||||||
#await cmd.done
|
await cmd.done
|
||||||
#call_deferred("command_done", cmd)
|
call_deferred("command_done", cmd)
|
||||||
|
|
||||||
var output = shell.run(command, false)
|
# var output = shell.run(command, false)
|
||||||
var shell_command = ShellCommand.new()
|
# var shell_command = ShellCommand.new()
|
||||||
shell_command.exit_code = 0
|
# shell_command.exit_code = 0
|
||||||
shell_command.output = output
|
# shell_command.output = output
|
||||||
shell_command.command = command
|
# shell_command.command = command
|
||||||
command_done(shell_command)
|
# command_done(shell_command)
|
||||||
|
|
||||||
func command_done(cmd):
|
func command_done(cmd):
|
||||||
if cmd.exit_code == 0:
|
if cmd.exit_code == 0:
|
||||||
|
|
|
@ -3,11 +3,11 @@ var emulator;
|
||||||
// Whether or not to restore the VM state from a file. Set to false to perform a regular boot.
|
// Whether or not to restore the VM state from a file. Set to false to perform a regular boot.
|
||||||
let restoreState = true;
|
let restoreState = true;
|
||||||
|
|
||||||
async function testy() {
|
function testy(cmd) {
|
||||||
return await new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
resolve("testy");
|
resolve("testy!!" + cmd);
|
||||||
}, 1000);
|
}, 100);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
window.testy = testy;
|
window.testy = testy;
|
||||||
|
@ -40,7 +40,7 @@ function run_in_vm(cmd) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
window.run_in_vm = run_in_vm;
|
window.run_in_vm = run_in_vm;
|
||||||
window.web_shell = { run_in_vm: run_in_vm };
|
window.web_shell = { run_in_vm, testy };
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue