def log_setting(): if tools.check_dir(config.log_dir): log_file = os.path.join(config.log_dir, "log.txt") logging.basicConfig(level=config.log_level, format=config.log_format, filename=log_file) console = logging.StreamHandler() console.setLevel(logging.INFO) logging.getLogger('').addHandler(console) else: logging.basicConfig(level=config.log_level, format=config.log_format)
def get_db_file(town, city): if tools.check_dir(config.db_dir): db_dir = config.db_dir else: logging.error("按照配置文件构建数据库存储目录失败,将在当前目录构建数据库文件!") db_dir = "./" today = datetime.datetime.today() pretend = "%s@%s" % (town.strip(), city) \ if town and town.strip() \ else "%s" % city db_file = ".".join([pretend, config.db, today.strftime("%Y%m%d")]) return get_new_db_file(db_dir, db_file)
def check_dir(self, directory): return tools.check_dir(directory)
import pickle_file import log import tools import porter_stemming import search import cache if __name__ == '__main__': # get configuration conf = confparse.confparse('./engine.ini') conf = conf.getall() # log log_dir = conf['log_directory'] ret = tools.check_dir(log_dir) if not ret: log_dir = './' log_file = os.path.join(log_dir, conf['search_log']) logger = log.init('engine_search', log_file) # pickle ranks and index directory = conf['dump_directory'] pkfile = pickle_file.pickle_file() ret = pkfile.check_dir(directory) if not ret: print('error: ', directory, 'use current dir as default.') directory = './' ranks = pkfile.load_file(directory, 'ranks_pickle') index = pkfile.load_file(directory, 'index_pickle') if ranks == False or index == False: print('No data can be load. Program exit.')