Exemple #1
0
def do_main():
    global _log
    logging.basicConfig(level=logging.DEBUG)
    _log = util.get_syslog_logger("main")
    rules.init()
    config_file_list = [ os.path.dirname(os.path.realpath(__file__)) + '/jim.cfg', '/etc/jim.cfg', './jim.cfg' ]
    config_file_parser = ConfigParser.RawConfigParser()
    config_ok = True
    try:
        config_file_list = config_file_parser.read(config_file_list)
    except:
        _log.error("cannot parse configuration file(s)")
        config_ok = False
    if len(config_file_list) == 0:
        _log.error("no configuration file found")
        config_ok = False
    else:
        _log.info("using configuration files {}".format(config_file_list))
    if config_ok:
        cfg = read_config(config_file_parser)
        _log.info("server configuration: {}".format(cfg))
        _log.info("starting server")
        db_file = cfg.get('db_file')
        if db_file:
            database = db.Database(db_file)
        else:
            database = None
        news = cfg.get('news_file') 
        certs_path = cfg.get('certs_path')
        if certs_path:
            ssl_options = { 'certfile' : certs_path + '/cert.pem',
                            'keyfile': certs_path + '/key.pem' }
        else:
            ssl_options = util.test_ssl_options
        web.run_server(ssl_options = ssl_options, http_port = cfg.get('http_port'), https_port = cfg.get('https_port'), bounce_port = cfg.get('bounce_port'), html_root = cfg.get('html_root'), template_root = cfg.get('template_root'), database = database, news = news, bootstrap_token = cfg.get('bootstrap_token'), player_reports_matches = cfg.get('player_reports_matches'), autoreload = cfg.get('autoreload'))
        _log.info("server exited")
    else:
        _log.error("configuration error")
Exemple #2
0
    def __init__(self, pwd):
        '''
        Attribute:
        - self.data: dict of dicts; for each lexical category, maps
          each word's index to the instance of the word.
        '''

        self.rules = {}
        rules.init(self.rules)

        self.data = {}

        for category in grammar.EXTRA_LIST:
            self.data[category] = {}
            grammar.init(category, self.data[category], self.rules, pwd)

        # Associates contractions to corresponding prepositions
        for contraction in self.data['contraction'].values():
            preposition = self.data['preposition'][contraction.preposition]
            preposition.set_contraction(
                (contraction.next, contraction.category),
                self.data['contraction'][contraction.index]
            )
Exemple #3
0
    if not os.path.exists(logs_basedir):
        os.mkdir(logs_basedir)
    logfile = "%s/piautomator.log" % logs_basedir
    formatting = logging.Formatter(log_format, None)
    handler = RotatingFileHandler(logfile, maxBytes=1024 * 1024 * 100, backupCount=3)
    handler.setFormatter(formatting)
    logging.root.addHandler(handler)
else:
    logging.basicConfig(format=log_format)

# Initialize all components
global automation_context
automation_context = AutomationContext(config)
automation_context.receivers = receivers.init(automation_context)
automation_context.inputs = inputs.init(automation_context)
automation_context.rule_context = rules.init(automation_context)

automation_context.start()

# Setup the handler that will terminate our event loops.
global running
running = True

def signal_handler(signal, frame):
    global running
    running = False
    automation_context.stop()
    print 'Terminated'


signal.signal(signal.SIGINT, signal_handler)
Exemple #4
0
    logfile = "%s/piautomator.log" % logs_basedir
    formatting = logging.Formatter(log_format, None)
    handler = RotatingFileHandler(logfile,
                                  maxBytes=1024 * 1024 * 100,
                                  backupCount=3)
    handler.setFormatter(formatting)
    logging.root.addHandler(handler)
else:
    logging.basicConfig(format=log_format)

# Initialize all components
global automation_context
automation_context = AutomationContext(config)
automation_context.receivers = receivers.init(automation_context)
automation_context.inputs = inputs.init(automation_context)
automation_context.rule_context = rules.init(automation_context)

automation_context.start()

# Setup the handler that will terminate our event loops.
global running
running = True


def signal_handler(signal, frame):
    global running
    running = False
    automation_context.stop()
    print 'Terminated'