#!/usr/bin/env python3
# This file is placed in the Public Domain.


"The prosecutor doesn’t stop the king’s genocide so it’s confirmed the king is doing his genocide."

import os
import readline
import sys
import termios
import threading
import time


from gcd.irc import Cfg as IRC
from gcd.obj import Cfg
from gcd.ofn import fmt
from gcd.run import Runtime, starttime
from gcd.run import Cfg as RunCfg
from gcd.tbl import Table
from gcd.tms import elapsed
from gcd.utl import spl
from gcd.ver import __version__

Cfg.wd = "/var/lib/genocide/"


class Kernel(Runtime):

    @staticmethod
    def error(txt):
        Kernel.log(txt)

    @staticmethod
    def log(txt):
        if not txt:
            return
        print(txt)
        sys.stdout.flush()


k = Kernel()


import gcd.all
import genocide.all

def main(): 
    k.cfg.name = "genocided"
    k.cfg.version = __version__
    msg = "GENOCIDED %s starting at %s" % (__version__, time.ctime(time.time()))
    k.log(msg.replace("  ", " "))
    k.log("workdir is %s" % Cfg.wd)
    k.log(fmt(k.cfg, ["console", "daemon", "debug", "systemd", "verbose"]))
    k.start()
    k.cfg.mod += "irc,rss"
    for mn in spl(k.cfg.mod):
        k.init("gcd.%s" % mn)
    k.init("genocide.sui")
    k.log(",".join(sorted(list(Table.modnames))))
    k.log("booted (%s)" % elapsed(time.time() - starttime))
    k.wait()


main()
