Skip to content

Commit

Permalink
Support json as config file instead of properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
kunyavskiy committed Aug 4, 2023
1 parent 4fc1573 commit bda822b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
2 changes: 0 additions & 2 deletions config/_examples/_testsys/events.properties

This file was deleted.

4 changes: 4 additions & 0 deletions config/_examples/_testsys/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "testsys",
"url": "http://acm.math.spbu.ru/cgi-bin/view.pl/n201206.dat"
}
7 changes: 6 additions & 1 deletion src/backend/src/main/kotlin/org/icpclive/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.icpclive.util.defaultJsonSettings
import org.icpclive.util.fileJsonContentFlow
import org.slf4j.event.Level
import java.time.Duration
import kotlin.io.path.exists
import kotlin.system.exitProcess

fun main(args: Array<String>): Unit =
Expand Down Expand Up @@ -115,7 +116,11 @@ fun Application.module() {
// TODO: understand why normal exception propagation doesn't work
exitProcess(1)
}
val path = config.configDirectory.resolve("events.properties")
val path =
config.configDirectory.resolve("events.properties")
.takeIf { it.exists() }
?.also { environment.log.warn("Using events.properties is deprecated, use settings.json instead.") }
?: config.configDirectory.resolve("settings.json")

launch(handler) {
val advancedJsonPath = config.configDirectory.resolve("advanced.json")
Expand Down
9 changes: 8 additions & 1 deletion src/cds-converter/src/main/kotlin/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.slf4j.event.Level
import java.io.File
import java.nio.file.Paths
import java.time.Duration
import kotlin.io.path.exists
import kotlin.system.exitProcess

fun main(args: Array<String>): Unit =
Expand Down Expand Up @@ -87,7 +88,13 @@ fun Application.module() {
Json.decodeFromStream(File(it).inputStream())
} ?: emptyMap()

val loaded = parseFileToCdsSettings(configDirectory.resolve("events.properties"))
val path = configDirectory.resolve("events.properties")
.takeIf { it.exists() }
?.also { environment.log.warn("Using events.properties is deprecated, use settings.json instead.") }
?: configDirectory.resolve("settings.json")


val loaded = parseFileToCdsSettings(path)
.toFlow(creds)
.applyAdvancedProperties(advancedProperties)
.filterUseless()
Expand Down
6 changes: 3 additions & 3 deletions src/reactions-bot/src/main/kotlin/org/icpclive/reacbot/Bot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Bot(private val config: Config) {
@OptIn(DelicateCoroutinesApi::class)
private val reactionsProcessingPool = newFixedThreadPoolContext(config.loaderThreads, "ReactionsProcessing")
private val cds = parseFileToCdsSettings(
Path.of(config.eventPropertiesFile),
Path.of(config.settingsFile),
).toFlow(emptyMap())
.withRunsBefore()
.filterUseless()
Expand Down Expand Up @@ -154,7 +154,7 @@ class Bot(private val config: Config) {
}

class BotCommand : CliktCommand() {
private val events by option(help = "Event.properties file path").default("./events.properties")
private val settings by option(help = "settings file path").default("./settings.json")
private val disableCds by option(help = "Enable loading events from cds").flag()
private val token by option(help = "Telegram bot token").required()
private val threads by option("--threads", "-t", help = "Count of video converter and loader threads").int().default(8)
Expand All @@ -165,7 +165,7 @@ class BotCommand : CliktCommand() {
runBlocking {
Bot(
Config(
eventPropertiesFile = events,
settingsFile = settings,
disableCdsLoader = disableCds,
telegramToken = token,
loaderThreads = threads,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.icpclive.reacbot


class Config(
val eventPropertiesFile: String,
val settingsFile: String,
val disableCdsLoader: Boolean,
val telegramToken: String,
val loaderThreads: Int,
Expand Down

0 comments on commit bda822b

Please sign in to comment.