Skip to content

Commit

Permalink
修改配置导出
Browse files Browse the repository at this point in the history
  • Loading branch information
yy199595 committed Nov 9, 2023
1 parent d688868 commit 57aaa6f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 32 deletions.
6 changes: 4 additions & 2 deletions script/network/http_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function HttpClient:send_request(url, timeout, querys, headers, method, datas)
local fmt_url = self:format_url(url, querys)
local request, curl_handle = curlm_mgr.create_request(fmt_url, to)
if not request then
log_err("[HttpClient][send_request] failed : %s", curl_handle)
log_err("[HttpClient][send_request] failed : {}", curl_handle)
return false
end
Expand All @@ -112,15 +113,15 @@ function HttpClient:send_request(url, timeout, querys, headers, method, datas)
end
local ok, err = request[method](datas or "")
if not ok then
log_err("[HttpClient][send_request] curl %s failed: %s!", method, err)
log_err("[HttpClient][send_request] curl {} failed: {}!", method, err)
return false
end

local session_id = thread_mgr:build_session_id()
self.contexts[curl_handle] = {
request = request,
session_id = session_id,
time = os.clock() * 1000 + to,
time = quanta.clock_ms + to,
}
return thread_mgr:yield(session_id, url, to)
end
Expand Down Expand Up @@ -148,3 +149,4 @@ end
quanta.http_client = HttpClient()

return HttpClient

84 changes: 54 additions & 30 deletions tools/config/download.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import("kernel.lua")
import("sandbox.lua")
import("basic/basic.lua")
Expand All @@ -8,48 +9,71 @@ import("kernel/timer_mgr.lua")
import("kernel/event_mgr.lua")
import("kernel/update_mgr.lua")
import("network/http_client.lua")
local ssplit = qstring.split
local lstdfs = require("lstdfs")

local ldir = lstdfs.dir

local log_debug = logger.debug
local event_mgr = quanta.get("event_mgr")
local thread_mgr = quanta.get("thread_mgr")
local http_client = quanta.get("http_client")
local tinster = table.insert
local sformat = string.format
local ssplit = qstring.split
local log_debug = logger.debug
local lstdfs = require("lstdfs")
local lmkdir = lstdfs.mkdir
local thread_mgr = quanta.get("thread_mgr")
local http_client = quanta.get("http_client")
local server_id = quanta.getenv("QUANTA_SERVER_ID")
local host = quanta.getenv("QUANTA_HOST") or "http://10.96.8.40:18080"

quanta.startup(function()

ldir("./conf")
thread_mgr:fork(function()
local data = {
server_id = 11
server_id = server_id
}

local ok, status, result = http_client:call_get("http://10.98.8.97:18080/env/render_server", data)
local url = sformat("%s/env/render_server", host)
print("url = ", url)
local ok, status, result = http_client:call_get(url, data)
--print(ok, status, result)
local response = json.decode(result)
print(response)
for _, value in pairs(response.data.files) do
local name = value.name
local fs = io.open(string.format("./conf/%s", name), 'w')
if fs then
local contents = { }
if value.include and next(value.include) then
for _, conf in pairs(value.include) do
table.insert(contents, string.format("dofile(%s)\n", conf))
if type(response) ~= 'table' then
return
end
if response.data.env and response.data.files then
local env = response.data.env
print(lmkdir(sformat("./%s", env)))
for _, value in pairs(response.data.files) do
local name = value.name
local path = sformat("./%s/%s", env, name)
local fs = io.open(path, 'w')
if fs then
local contents = { }
if value.include and next(value.include) then
for _, conf in pairs(value.include) do
tinster(contents, sformat("dofile('%s/%s')\n", env, conf))
end
end
end
for _, val in pairs(value.value) do
local split_desc = ssplit(val.desc, '\n')
for _, text in ipairs(split_desc) do
table.insert(contents, string.format("--%s\n", text))
for _, val in pairs(value.value) do
if val.desc ~= '' then
local split_desc = ssplit(val.desc, '\n')
for _, text in pairs(split_desc) do
if text ~= '' and text ~= '[[' then
tinster(contents, sformat("--%s\n", text))
end
end
end

if not val.enable then
tinster(contents, "--")
end
if string.match(val.value, "^%[%[.-%]%]$") then
tinster(contents, sformat("set_env('%s', %s)\n", val.key, val.value))
else
tinster(contents, sformat("set_env('%s', '%s')\n", val.key, val.value))
end
end
table.insert(contents, string.format("set_env('%s', '%s')\n", val.key, val.value))
fs:write(table.concat(contents))
fs:close()
log_debug("write {} successful", name)
end
fs:write(table.concat(contents))
fs:close()
log_debug("write {} successful", name)
end
end
quanta.run = nil
end)
end)

0 comments on commit 57aaa6f

Please sign in to comment.