def main(mode,novel): dbconf = gen_dbconf(mode) #conn = tornado.database.Connection(dbconf['host'],dbconf['db'],user=dbconf['user'],password=dbconf['passwd']) pool = DBPool(host=dbconf['host'],database=dbconf['db'],user=dbconf['user'],password=dbconf['passwd'],min_conn=2,max_conn=3) conn = pool.connect() if not novel: for key in books: if mode == 'pro' and books[key][3] == True: pass else: book_module = book_relative_import(books[key]) book = book_module() path = gen_content_path(mode,book.dir_name) if not os.path.exists(path): os.mkdir(path) os.chdir(path) book.process(conn) else: key = novel if mode == 'pro' and books[key][3] == True: pass else: book_module = book_relative_import(books[key]) book = book_module() path = gen_content_path(mode,book.dir_name) if not os.path.exists(path): os.mkdir(path) os.chdir(path) book.process(conn) conn.close() pool.close()
class Application(tornado.web.Application): def __init__(self, mode): handlers = [("/", IndexHandler), ("/(\w+)$", MainHandler), ("/([^/]+?)/detail/(\S+)$", DetailHandler)] settings = dict( template_path=os.path.join(os.path.dirname(__file__), "./template"), static_path=os.path.join(os.path.dirname(__file__), "./static"), debug=True, autoescape=None, ) super(Application, self).__init__(handlers, **settings) self.mode = mode dbconf = gen_dbconf(self.mode) self.pool = DBPool( host=dbconf["host"], database=dbconf["db"], user=dbconf["user"], password=dbconf["passwd"], min_conn=4, max_conn=7, ) self.books = {} self.book_names = {} for key in books: book_module = book_relative_import(books[key]) book = book_module() self.books[key] = book self.book_names[key] = books[key][2] self.bookcontent_cache = KVCache(cap=200) def __del__(self): self.pool.close()
def __init__(self,mode): handlers = [ ('/',IndexHandler), ('/(\w+)$',MainHandler), ('/([^/]+?)/detail/(\S+)$',DetailHandler) ] settings = dict( template_path=os.path.join(os.path.dirname(__file__), "./template"), static_path=os.path.join(os.path.dirname(__file__), "./static"), debug=True, autoescape=None ) super(Application,self).__init__(handlers,**settings) self.mode = mode dbconf = gen_dbconf(self.mode) self.pool = DBPool(host=dbconf['host'],database=dbconf['db'],user=dbconf['user'],password=dbconf['passwd'],min_conn=4,max_conn=7) self.books = {} self.book_names = {} for key in books: book_module = book_relative_import(books[key]) book = book_module() self.books[key] = book self.book_names[key] = books[key][2] self.bookcontent_cache = KVCache(cap=200)
def main(mode, novel): dbconf = gen_dbconf(mode) #conn = tornado.database.Connection(dbconf['host'],dbconf['db'],user=dbconf['user'],password=dbconf['passwd']) pool = DBPool(host=dbconf['host'], database=dbconf['db'], user=dbconf['user'], password=dbconf['passwd'], min_conn=2, max_conn=3) conn = pool.connect() if not novel: for key in books: if mode == 'pro' and books[key][3] == True: pass else: book_module = book_relative_import(books[key]) book = book_module() path = gen_content_path(mode, book.dir_name) if not os.path.exists(path): os.mkdir(path) os.chdir(path) book.process(conn) else: key = novel if mode == 'pro' and books[key][3] == True: pass else: book_module = book_relative_import(books[key]) book = book_module() path = gen_content_path(mode, book.dir_name) if not os.path.exists(path): os.mkdir(path) os.chdir(path) book.process(conn) conn.close() pool.close()
#!/usr/bin/env python # coding:utf8 # Created on 2016-5-21 # @author: yi.zhiwu import json from time import sleep from fabric.api import env, roles, run, execute, cd, run, env, hosts from dbpool import DBPool # 数据库配置 config = json.load(open('config.json', 'r')) adminPool = DBPool() adminPool.initPool(config['admin']) CONFIG_DB_NAME = config['admin']['db'] queryResult = adminPool.querySql("select * from tb_server", True) hot_list = {} # hot_list = {"1": ['[email protected]:22']} role = [] for ca in queryResult: service_id = str(ca['id']) + str(ca['tcpPort'])[-2:] hot_list[service_id] = ["appuser@" + ca['hostIP'] + ':22'] role.append(service_id) env.roledefs = hot_list env.password = '******' # 服务器统一密码 # env.password = '******' # 服务器统一密码