2 HCE project, Python bindings, Processor Manager application. 3 Event objects definitions. 6 @file CrawlingOptimiser.py.py 7 @author Oleksii <developers.hce@gmail.com> 8 @author madk <developers.hce@gmail.com> 9 @link: http://hierarchical-cluster-engine.com/ 10 @copyright: Copyright © 2013-2014 IOIX Ukraine 11 @license: http://hierarchical-cluster-engine.com/license/ 18 from cement.core
import foundation
34 label = CONSTS.APP_NAME
43 foundation.CementApp.__init__(self)
59 foundation.CementApp.setup(self)
60 self.args.add_argument(
'-c',
'--config', action=
'store', metavar=
'config_file', help=
'config ini-file')
61 self.args.add_argument(
'-s',
'--site', action=
'store', metavar=
'site alias', help=
'site alias')
68 foundation.CementApp.run(self)
83 self.
logger.info(APP_CONSTS.LOGGER_DELIMITER_LINE)
91 self.
config = ConfigParser.ConfigParser()
92 self.
config.optionxform = str
96 self.
config.read(self.pargs.config)
97 self.
message_queue.append(CONSTS.MSG_INFO_LOAD_CONFIG_FILE + str(self.pargs.config))
99 self.
config.read(CONSTS.DEFAULT_CFG_FILE)
100 self.
message_queue.append(CONSTS.MSG_INFO_LOAD_DEFAULT_CONFIG_FILE + CONSTS.DEFAULT_CFG_FILE)
105 self.
message_queue.append(CONSTS.MSG_INFO_LOAD_SITE_ID + str(self.pargs.site))
108 self.
message_queue.append(CONSTS.MSG_INFO_LOAD_DEFAULT_SITE_ID + str(CONSTS.SITE_ALL))
110 except Exception, err:
111 print CONSTS.MSG_ERROR_LOAD_CONFIG, err.message
121 log_conf_file = self.
config.get(
"Application",
"log")
122 logging.config.fileConfig(log_conf_file)
124 except Exception, err:
125 print CONSTS.MSG_ERROR_LOAD_LOG_CONFIG_FILE, err.message
135 remote_db_task_ini = self.
config.get(self.__class__.__name__,
"db-task_ini_remote")
136 remote_cfgParser = ConfigParser.ConfigParser()
137 remote_cfgParser.read(remote_db_task_ini)
139 self.
remote_host = remote_cfgParser.get(
"TasksManager",
"db_host")
141 local_db_task_ini = self.
config.get(self.__class__.__name__,
"db-task_ini_local")
142 local_cfgParser = ConfigParser.ConfigParser()
143 local_cfgParser.read(local_db_task_ini)
145 except Exception, err:
146 self.
logger.
error(CONSTS.MSG_ERROR_LOAD_LOG_CONFIG_FILE)
166 except Exception, err:
167 self.
logger.
error(CONSTS.MSG_ERROR_PROCESS_GENERAL +
' ' + str(err))
178 response = self.
remote_wrapper.customRequest(query, CONSTS.DB_URLS)
179 if response
is not None:
180 self.
logger.info(
"response: %s" % str(response))
181 site_data_dict[
"Contents"] = response[0][0]
182 site_data_dict[
"LastAdded"] = response[0][1]
183 site_data_dict[
"minPDate"] = response[0][2]
184 site_data_dict[
"maxPDate"] = response[0][3]
187 query = CONSTS.SQL_QUERY_RECRAWL_PERIOD_START % (self.
site_id)
188 response = self.
remote_wrapper.customRequest(query, CONSTS.DB_URLS)
189 if response
is not None:
190 self.
logger.info(
"response: %s" % str(response))
191 site_data_dict[
"RecrawlStart"] = response[0][0]
194 query = CONSTS.SQL_QUERY_RECRAWL_PERIOD_END % (self.
site_id)
195 response = self.
remote_wrapper.customRequest(query, CONSTS.DB_URLS)
196 if response
is not None:
197 self.
logger.info(
"response: %s" % str(response))
198 site_data_dict[
"RecrawlEnd"] = response[0][0]
200 except Exception, err:
201 self.
logger.
error(CONSTS.MSG_ERROR_COLLECT_SITE_DATA +
' ' + str(err))
202 self.
logger.info(
"site_data_dict: %s" % str(site_data_dict))
203 return site_data_dict
212 query = CONSTS.SQL_QUERY_NEW_SITE_TABLE % (self.
site_id)
213 response = self.
local_wrapper.customRequest(query, CONSTS.DB_CO)
214 if response
is not None:
215 self.
logger.info(
"response: %s" % str(response))
218 query = CONSTS.SQL_QUERY_INSERT_SITE_DATA % \
231 response = self.
local_wrapper.customRequest(query, CONSTS.DB_CO)
232 if response
is not None:
233 self.
logger.info(
"response: %s" % str(response))
235 self.
logger.info(
"Zero contents.")
236 except Exception, err:
237 self.
logger.
error(CONSTS.MSG_ERROR_STORE_SITE_DATA +
' ' + str(err))
def collectSiteData(self)
def loadLogConfigFile(self)