def __init__(self, config_path, **kwargs):
super(LocalControl_Agent, self).__init__(**kwargs)
self.Config = utils.load_config(config_path)
self.zonenum = self.Config["zonenum"]
self.deadband = settings[2]
self.min_switch_time = settings[1]
self.setpoint = settings[0]
self.last_switch_time = time.time()
self.usr_mode = 0
python类Settings()的实例源码
def get_baudrate_list():
ret = [115200, 250000, 230400, 57600, 38400, 19200, 9600]
prev = WebConfig.settings().get(["serial", "baudrate"])
if prev == "AUTO":
ret.insert(0, "AUTO")
elif prev in ret:
ret.remove(prev)
ret.insert(0, prev)
else:
pass
return ret
def __init__(self):
tornado.web.Application.__init__(self, url_patterns, **settings)
self._redis = _db.redis_client
self._motor = get_mongodb(CONFIG.MONGO.DATABASE, client='motor')
connect(CONFIG.MONGO.DATABASE, host=CONFIG.MONGO.HOST,
port=CONFIG.MONGO.PORT,
io_loop=tornado.ioloop.IOLoop.current()) # motorengine
def app_settings(cls):
dirname = os.path.dirname(os.path.abspath(__file__))
return {
"debug": options.debug,
"cookie_secret": options.cookie_secret,
"xsrf_cookies": options.xsrf_cookies,
"twitter_consumer_key": options.twitter_consumer_key,
"twitter_consumer_secret": options.twitter_consumer_secret,
# invariant settings
"login_url": "/sign-in",
"static_path": os.path.join(dirname, "static"),
"template_path": os.path.join(dirname, "templates"),
"ui_modules": lib.uimodules,
}
def __init__(self, *args, **settings):
self.db = register_connection(host=options.database_host,
name=options.database_name,
user=options.database_user,
password=options.database_password,
charset="utf8mb4")
if options.use_query_cache:
lib.flyingcow.cache.use_query_cache = True
if options.stripe_secret_key:
stripe.api_key = options.stripe_secret_key
super(MltshpApplication, self).__init__(*args, **settings)
def __init__(self):
tornado.web.Application.__init__(self, url_patterns, **settings)
def main():
db_path = "{root_path}/{db}".format(root_path=settings['sqlite'], db=settings['db'])
if not db_init(db_path):
print "Init DB Failed"
sys.exit(999)
print "Init DB Success"
app = LittleFSApp()
http_server = tornado.httpserver.HTTPServer(app, max_buffer_size=1024 * 1024 * 1024)
http_server.listen(options.port)
print "Start PyWeedFS Success"
tornado.ioloop.IOLoop.instance().start()
def __init__(self):
print '\ninside Application __init__()'
tornado.web.Application.__init__(self, urls, **settings)
print 'Aapplication __init__ caleed with web.Application()'
print 'returning from Application __init__'
def __init__(self):
tornado.web.Application.__init__(self, urls, **settings)
def __init__(self):
logging.info("init MainApplication with settings: %s" % str(settings))
tornado.web.Application.__init__(self, url_patterns, **settings)
def __init__(self):
tornado.web.Application.__init__(self, urls, **settings)
def __init__(self):
tornado.web.Application.__init__(self, urls, **settings)
def main_app(env, start_response):
"""Provides following features:
- Serves static files
- /debug route for mobile debugging
- /command route for interacting with computer
"""
request_path = env['PATH_INFO']
if request_path == '/debug':
return debug(env, start_response)
elif request_path == '/settings':
return get_settings(env, start_response)
elif request_path == '/get_gif':
ret, stdout, stderr = run_command(settings['gifScriptCommand'])
print('STDOUT')
print('------')
print(stdout)
print('STDERR')
print('------')
print(stderr)
if ret != 0:
response = 'Error'
start_response('500 OK', HEADERS)
return [json.dumps(response)]
preview_path = path.get_resource('static/img/preview.gif')
if not os.path.isfile(preview_path):
response = 'Error'
start_response('500 OK', HEADERS)
return [json.dumps(response)]
response = 'OK'
start_response('200 OK', HEADERS)
return [json.dumps(response)]
elif request_path == '/save_gif':
directory = os.path.abspath(settings['gifsDirectory'])
new_name = str(int(time.time())) + '.gif'
os.rename(path.get_resource('static/img/preview.gif'),
path.get_resource('static/img/%s' % new_name))
shutil.move(path.get_resource('static/img/%s' % new_name), directory)
response = 'OK'
start_response('200 OK', HEADERS)
return [json.dumps(response)]
# Serve a file if it's found.
else:
if request_path == '/':
request_path = '/static/index.html'
return file_response(request_path, start_response)