소스 검색

some stuff; nothing really substantial and probably doesn't work, but I wanted to get this out on paper

tags/v0.1^2
Ben Kurtovic 13 년 전
부모
커밋
e105a8dd78
2개의 변경된 파일53개의 추가작업 그리고 4개의 파일을 삭제
  1. +46
    -0
      core/config.py
  2. +7
    -4
      core/main.py

+ 46
- 0
core/config.py 파일 보기

@@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-

## EarwigBot's Config File Parser

from collections import defaultdict
import ConfigParser as configparser
import os

main_cfg_path = os.path.join("config", "main.cfg")
secure_cfg_path = os.path.join("config", "secure.cfg")

config = dict()

def load_config_file(filename):
parser = configparser.SafeConfigParser()
parser.optionxform = str # don't lowercase option names automatically
parser.read(filename)
return parser

def make_new_config():
print "You haven't configured the bot yet!"
choice = raw_input("Would you like to do this now? [y/n] ")
if choice.lower().startswith("y"):
pass
else:
exit()

def dump_config_to_dict(parsers):
global config
for parser in parsers:
for section in parser.sections():
for option in parser.options(section):
try:
config[section][option] = parser.get(section, option)
except KeyError:
config[section] = defaultdict(lambda: None)
config[section][option] = parser.get(section, option)

def load():
if not os.path.exists(main_cfg_path):
make_new_config()
main_cfg = load_config_file(main_cfg_path)
secure_cfg = load_config_file(secure_cfg_path)
dump_config_to_dict([main_cfg, secure_cfg])

+ 7
- 4
core/main.py 파일 보기

@@ -28,7 +28,7 @@ import os
parent_dir = os.path.split(sys.path[0])[0]
sys.path.append(parent_dir) # make sure we look in the parent directory for modules

from config.main import *
from core import config
from irc import frontend, watcher
from wiki import task_manager

@@ -96,10 +96,13 @@ def irc_frontend():
f_conn.close()
def run():
if enable_irc_frontend: # make the frontend run on our primary thread if enabled, and enable additional components through that function
config.load()
components = config.config["main"]
if components["enable_irc_frontend"]: # make the frontend run on our primary thread if enabled, and enable additional components through that function
irc_frontend()
elif enable_wiki_schedule: # the scheduler is enabled - run it on the main thread, but also run the IRC watcher on another thread if it is enabled
elif components["enable_wiki_schedule"]: # the scheduler is enabled - run it on the main thread, but also run the IRC watcher on another thread if it is enabled
print "\nStarting wiki scheduler..."
task_manager.load_tasks()
if enable_irc_watcher:
@@ -109,7 +112,7 @@ def run():
t_watcher.start()
wiki_scheduler()
elif enable_irc_watcher: # the IRC watcher is our only enabled component, so run its function only and don't worry about anything else
elif components["enable_irc_watcher"]: # the IRC watcher is our only enabled component, so run its function only and don't worry about anything else
irc_watcher()
else: # nothing is enabled!


불러오는 중...
취소
저장