changeset 1641:48c24eedb8b2

host cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 21 Dec 2021 17:21:37 -0700
parents 570f3d483a31
children 0a46dbd36208
files host/Config.luan host/run.luan src/luan/host/Config.luan src/luan/host/run.luan
diffstat 4 files changed, 102 insertions(+), 111 deletions(-) [+]
line wrap: on
line diff
diff -r 570f3d483a31 -r 48c24eedb8b2 host/Config.luan
--- a/host/Config.luan	Tue Dec 21 16:54:26 2021 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-local Luan = require "luan:Luan.luan"
-local error = Luan.error
-local ipairs = Luan.ipairs or error()
-local Io = require "luan:Io.luan"
-local uri = Io.uri or error()
-local Package = require "luan:Package.luan"
-local load = Package.load or error()
-local Logging = require "luan:logging/Logging.luan"
-local logger = Logging.logger "Config"
-
-
-uri("file:local").mkdir()
-local password_file = uri("file:local/password.txt")
-local password = password_file.exists() and password_file.read_text() or "password"
-local site_config = nil
-local site_name
-for _, site_dir in ipairs( uri("file:sites").children() or {} ) do
-	local name = site_dir.name()
-	local config = load("file:sites/"..name.."/site/private/host/Config.luan")
-	if config == false then
-		continue
-	end
-	if config.password ~= password and config.old_password ~= password then
-		logger.warn("wrong password for "..name)
-		continue
-	end
-	if site_config == nil then
-		site_config = config
-		site_name = name
-	else
-		logger.error("conflicting Config in "..name.." and "..site_name)
-	end
-end
-if site_config ~= nil then
-	logger.info("using Config from "..site_name)
-	local site_password = site_config.password or error()
-	if site_password ~= password then
-		password_file.write_text(password)
-	end
-	return site_config
-end
-if password ~= "password" then
-	password_file.write_text("password")
-end
-
-
-local Config = {}
-
-Config.password = "password"
-
---[[  an example
-Config.postgres = {
-	class = "org.postgresql.Driver"
-	url = "jdbc:postgresql://localhost:5432/postgres"
-	user = "someone"
-	password = "password"
-}
-]]
-
-return Config
diff -r 570f3d483a31 -r 48c24eedb8b2 host/run.luan
--- a/host/run.luan	Tue Dec 21 16:54:26 2021 -0700
+++ b/host/run.luan	Tue Dec 21 17:21:37 2021 -0700
@@ -1,50 +1,2 @@
-require "java"
 local Luan = require "luan:Luan.luan"
-local error = Luan.error
-local ipairs = Luan.ipairs or error()
-local Number = require "luan:Number.luan"
-local long = Number.long or error()
-local Logging = require "luan:logging/Logging.luan"
-
-local log_to_console = false
-for _, arg in ipairs{...} do
-	if arg == "console" then
-		log_to_console = true
-	end
-end
-if not log_to_console then
-	local LuanLogger = require "java:luan.modules.logging.LuanLogger"
-	local Layouts = require "java:goodjava.logger.Layouts"
-	local DateLayout = require "java:goodjava.logger.DateLayout"
-	local ListLayout = require "java:goodjava.logger.ListLayout"
-	local Level = require "java:goodjava.logger.Level"
-	local RollingFileAppender = require "java:goodjava.logger.RollingFileAppender"
-	local LevelAppender = require "java:goodjava.logger.LevelAppender"
-	local ListAppender = require "java:goodjava.logger.ListAppender"
-
-	local one_mb = long(1024*1024)
-	local layout = ListLayout.new(DateLayout.new("yyyy-MM-dd HH:mm:ss,SSS")," ",Layouts.LEVEL_PADDED," ",Layouts.LOGGER," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE)
-
-	local function new_appender(file,level)
-		local appender = RollingFileAppender.new(layout, file)
-		appender.maxFileSize = one_mb
-		appender = LevelAppender.new(appender,level)
-		return appender
-	end
-
-	local err = new_appender("logs/luan_error.log",Level.ERROR)
-	local warn = new_appender("logs/luan_warn.log",Level.WARN)
-	local info = new_appender("logs/luan_info.log",Level.INFO)
-	local appender = ListAppender.new(err,warn,info)
-	LuanLogger.configure(appender)
-end
-
-local logger = Logging.logger "luanhost-run"
-
-
-local do_file = Luan.do_file or error()
-local WebHandler = require "java:luan.host.WebHandler"
-
-WebHandler.config = require "file:Config.luan"
-
-do_file "classpath:luan/host/run.luan"
+Luan.load_file("classpath:luan/host/run.luan")(...)
diff -r 570f3d483a31 -r 48c24eedb8b2 src/luan/host/Config.luan
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/luan/host/Config.luan	Tue Dec 21 17:21:37 2021 -0700
@@ -0,0 +1,60 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local ipairs = Luan.ipairs or error()
+local Io = require "luan:Io.luan"
+local uri = Io.uri or error()
+local Package = require "luan:Package.luan"
+local load = Package.load or error()
+local Logging = require "luan:logging/Logging.luan"
+local logger = Logging.logger "Config"
+
+
+uri("file:local").mkdir()
+local password_file = uri("file:local/password.txt")
+local password = password_file.exists() and password_file.read_text() or "password"
+local site_config = nil
+local site_name
+for _, site_dir in ipairs( uri("file:sites").children() or {} ) do
+	local name = site_dir.name()
+	local config = load("file:sites/"..name.."/site/private/host/Config.luan")
+	if config == false then
+		continue
+	end
+	if config.password ~= password and config.old_password ~= password then
+		logger.warn("wrong password for "..name)
+		continue
+	end
+	if site_config == nil then
+		site_config = config
+		site_name = name
+	else
+		logger.error("conflicting Config in "..name.." and "..site_name)
+	end
+end
+if site_config ~= nil then
+	logger.info("using Config from "..site_name)
+	local site_password = site_config.password or error()
+	if site_password ~= password then
+		password_file.write_text(password)
+	end
+	return site_config
+end
+if password ~= "password" then
+	password_file.write_text("password")
+end
+
+
+local Config = {}
+
+Config.password = "password"
+
+--[[  an example
+Config.postgres = {
+	class = "org.postgresql.Driver"
+	url = "jdbc:postgresql://localhost:5432/postgres"
+	user = "someone"
+	password = "password"
+}
+]]
+
+return Config
diff -r 570f3d483a31 -r 48c24eedb8b2 src/luan/host/run.luan
--- a/src/luan/host/run.luan	Tue Dec 21 16:54:26 2021 -0700
+++ b/src/luan/host/run.luan	Tue Dec 21 17:21:37 2021 -0700
@@ -1,13 +1,52 @@
 require "java"
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
+local ipairs = Luan.ipairs or error()
 local do_file = Luan.do_file or error()
-local ipairs = Luan.ipairs or error()
+local Number = require "luan:Number.luan"
+local long = Number.long or error()
 local Io = require "luan:Io.luan"
 local Hosted = require "luan:host/Hosted.luan"
+local WebHandler = require "java:luan.host.WebHandler"
 local Logging = require "luan:logging/Logging.luan"
+
+local log_to_console = false
+for _, arg in ipairs{...} do
+	if arg == "console" then
+		log_to_console = true
+	end
+end
+if not log_to_console then
+	local LuanLogger = require "java:luan.modules.logging.LuanLogger"
+	local Layouts = require "java:goodjava.logger.Layouts"
+	local DateLayout = require "java:goodjava.logger.DateLayout"
+	local ListLayout = require "java:goodjava.logger.ListLayout"
+	local Level = require "java:goodjava.logger.Level"
+	local RollingFileAppender = require "java:goodjava.logger.RollingFileAppender"
+	local LevelAppender = require "java:goodjava.logger.LevelAppender"
+	local ListAppender = require "java:goodjava.logger.ListAppender"
+
+	local one_mb = long(1024*1024)
+	local layout = ListLayout.new(DateLayout.new("yyyy-MM-dd HH:mm:ss,SSS")," ",Layouts.LEVEL_PADDED," ",Layouts.LOGGER," - ",Layouts.MESSAGE,"\n",Layouts.THROWABLE)
+
+	local function new_appender(file,level)
+		local appender = RollingFileAppender.new(layout, file)
+		appender.maxFileSize = one_mb
+		appender = LevelAppender.new(appender,level)
+		return appender
+	end
+
+	local err = new_appender("logs/luan_error.log",Level.ERROR)
+	local warn = new_appender("logs/luan_warn.log",Level.WARN)
+	local info = new_appender("logs/luan_info.log",Level.INFO)
+	local appender = ListAppender.new(err,warn,info)
+	LuanLogger.configure(appender)
+end
+
 local logger = Logging.logger "run"
-local WebHandler = require "java:luan.host.WebHandler"
+
+
+WebHandler.config = require "classpath:luan/host/Config.luan"
 Hosted.WebHandler = WebHandler