def __init__(self, options): """Init the server. Must be called at the begin of the children class. """ self._stopevent = threading.Event() self.options = JNTOptions(options) signal.signal(signal.SIGTERM, self.sigterm_handler) #Need more tests signal.signal(signal.SIGHUP, self.sighup_handler) signal.signal(signal.SIGUSR1, self.sigusr1_handler) self._threads = [] if 'conf_file' in self.options.data and self.options.data['conf_file'] is not None: logging_fileConfig(self.options.data['conf_file']) self.loop_sleep = 0.25 loop_sleep = self.options.get_option('system','loop_sleep') if loop_sleep is not None: try: self.loop_sleep = int(loop_sleep) except: logger.exception("[%s] - Exception when retrieving value of loop_sleep. Use default value instead", self.__class__.__name__) self.slow_start = 0.05 slow_start = self.options.get_option('system','slow_start') if slow_start is not None: try: self.slow_start = int(slow_start) except: logger.exception("[%s] - Exception when retrieving value of slow_start. Use default value instead", self.__class__.__name__)
def test_021_rotate_cycle(self): logging_fileConfig(self.conf_file) with mock.patch('sys.argv', [self.prog, 'start', '--conf_file=%s'%self.conf_file]): options = vars(jnt_parse_args()) self.options = JNTOptions(options) bus = FishtankBus(options=self.options) bus.nodeman=FakeNodeman() #~ bus.start(None) bc = MoonComponent(bus=bus, cycle=28, current=0, min=0, max=60, options=self.options, node_uuid='fishtank__moon') print bc.values['current'].get_data_index(node_uuid='moon', index=0) bc.current_rotate() print bc.values['current'].get_data_index(node_uuid='moon', index=0)
def __init__(self, app=None, options=None, db=None): self._app = app self._db = db self.options = options if self.options is not None and 'conf_file' in self.options and self.options['conf_file'] is not None: logging_fileConfig(self.options['conf_file']) self._listener = None self._listener_lock = None self._sleep = 0.25 self.menu_left = [] # Bower self.bower = Bower() # Caching self.cache = Cache()
def __init__(self, options): """Init the server. Must be called at the begin of the children class. """ self._stopevent = threading.Event() self._reloadevent = threading.Event() self.options = JNTOptions(options) signal.signal(signal.SIGTERM, self.sigterm_handler) #Need more tests signal.signal(signal.SIGHUP, self.sighup_handler) signal.signal(signal.SIGUSR1, self.sigusr1_handler) self._threads = [] if 'conf_file' in self.options.data and self.options.data['conf_file'] is not None: logging_fileConfig(self.options.data['conf_file']) self.loop_sleep = 0.25 self.gc_delay = 0 self.slow_start = 0.05
def init_app(self, app, options, db=None): """ """ if app is not None: self._app = app if options is not None: self.options = options if db is not None: self._db = db if self.options is not None and 'conf_file' in self.options and self.options['conf_file'] is not None: logging_fileConfig(self.options['conf_file']) # Flask-Cache self.cache.init_app(self._app) # Flask-Bower self.bower.init_app(self._app) self._event_manager = EventManager(self._app) self._app.jinja_env.globals["emit_event"] = self._event_manager.template_emit if not hasattr(self._app, 'extensions'): self._app.extensions = {} self._app.extensions['options'] = self.options self._app.extensions['bower'] = self.bower self._app.extensions['cache'] = self.cache self._app.extensions['janitoo'] = self try: self._sleep = int(self._app.config['FLASKJANITOO_SLEEP']) if self._sleep <= 0 : self._sleep = 0.25 except KeyError: self._sleep = 0.25 except ValueError: self._sleep = 0.25 # Use the newstyle teardown_appcontext if it's available, # otherwise fall back to the request context if hasattr(self._app, 'teardown_appcontext'): self._app.teardown_appcontext(self.teardown) else: self._app.teardown_request(self.teardown) signal.signal(signal.SIGTERM, self.signal_term_handler) signal.signal(signal.SIGINT, self.signal_term_handler) self._listener_lock = threading.Lock() self.create_listener()
import ConfigParser import logging from logging.config import fileConfig as logging_fileConfig from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker cfg = ConfigParser.ConfigParser() cfg.read('./config.ini') # FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s" # logging.basicConfig(filename='example.log', # level=logging.DEBUG, format = FORMAT) # logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG) logging_fileConfig('./log.ini') logger = logging.getLogger() logger.setLevel(logging.DEBUG) engine = create_engine(cfg.get('DB', 'CXN')) Base = declarative_base() Base.metadata.bind = engine Session = sessionmaker(bind=engine)