2 HCE project, Python bindings, Distributed Tasks Manager application. 3 Converter of the list of the URLs object from the URLFetch request to the DBTask. 6 @file URLFetchToJsonDBTaskConvertor.py 7 @author Oleksii <developers.hce@gmail.com>, Alexander Vybornyh <alexander.hce.cluster@gmail.com> 8 @link: http://hierarchical-cluster-engine.com/ 9 @copyright: Copyright © 2013-2015 IOIX Ukraine 10 @license: http://hierarchical-cluster-engine.com/license/ 19 from subprocess
import Popen
20 from subprocess
import PIPE
22 import cPickle
as pickle
25 from cement.core
import foundation
40 CMD_DEFAULT =
"cd ~/hce-node-bundle/api/python/bin && ./db-task.py --c=../ini/db-task.ini" 43 MSG_ERROR_EMPTY_CONFIG_FILE_NAME =
"Config file name is empty." 44 MSG_ERROR_WRONG_CONFIG_FILE_NAME =
"Config file name is wrong" 45 MSG_ERROR_LOAD_APP_CONFIG =
"Error loading application config file." 46 MSG_ERROR_READ_LOG_CONFIG =
"Error read log config file." 47 MSG_ERROR_EXIT_STATUS =
"Exit failure. " 49 MSG_DEBUG_INPUT_PICKLE =
"Input pickle: " 50 MSG_DEBUG_OUTPUT_PICKLE =
"Output pickle: " 51 MSG_DEBUG_SEND_PICKLE =
"Send pickle. Done." 53 MSG_INFO_PROCESSOR_EXIT_CODE =
"Scraper exit_code: " 54 MSG_INFO_PROCESSOR_OUTPUT =
"Scraper output: " 55 MSG_INFO_PROCESSOR_ERROR =
"Scraper err: " 58 URLS_FETCH_JSON_TO_DBTASK_OPTION_LOG =
"log" 59 URLS_FETCH_JSON_TO_DBTASK_OPTION_CMD =
"cmd" 64 label = APP_CONSTS.URLS_FETCH_JSON_TO_DBTASK_APP_NAME
72 foundation.CementApp.__init__(self)
82 foundation.CementApp.setup(self)
88 foundation.CementApp.run(self)
97 self.
logger.info(APP_CONSTS.LOGGER_DELIMITER_LINE)
105 if self.pargs.config:
120 config = ConfigParser.ConfigParser()
121 config.optionxform = str
123 readOk = config.read(configName)
128 if config.has_section(APP_CONSTS.CONFIG_APPLICATION_SECTION_NAME):
129 confLogFileName = str(config.get(APP_CONSTS.CONFIG_APPLICATION_SECTION_NAME,
131 self.
cmd = str(config.get(APP_CONSTS.CONFIG_APPLICATION_SECTION_NAME,
134 except Exception, err:
137 return confLogFileName
146 if isinstance(configName, str)
and len(configName) == 0:
149 logging.config.fileConfig(configName)
154 except Exception, err:
159 inputUrlFetchJson = sys.stdin.read()
162 return json.loads(inputUrlFetchJson)
166 eventType = DC_CONSTS.EVENT_TYPES.URL_FETCH
168 eventObj = convertor.URLFetchDeserialize(inputUrlFetchJson)
170 drceSyncTasksCoverObj = DC_CONSTS.DRCESyncTasksCover(eventType, eventObj)
171 outputPickle = pickle.dumps(drceSyncTasksCoverObj)
178 process = Popen(self.
cmd, stdout=PIPE, stdin=PIPE, shell=
True, close_fds=
True)
179 (output, err) = process.communicate(input=outputPickle)
189 sys.stdout.write(output_pickle)
195 self.
logger.info(
'self.cmd: ' + str(self.
cmd))
199 except Exception, err:
201 self.
exitCode = APP_CONSTS.EXIT_FAILURE
string MSG_DEBUG_OUTPUT_PICKLE
string MSG_DEBUG_SEND_PICKLE
def createOutputPickle(self, inputUrlFetchJson)
def sendPickle(self, output_pickle)
def __loadAppConfig(self, configName)
string MSG_ERROR_LOAD_APP_CONFIG
string MSG_ERROR_EMPTY_CONFIG_FILE_NAME
def __loadLogConfig(self, configName)
string URLS_FETCH_JSON_TO_DBTASK_OPTION_CMD
string MSG_DEBUG_INPUT_PICKLE
string MSG_ERROR_WRONG_CONFIG_FILE_NAME
string URLS_FETCH_JSON_TO_DBTASK_OPTION_LOG
string MSG_INFO_PROCESSOR_EXIT_CODE
string MSG_ERROR_EXIT_STATUS
def varDump(obj, stringify=True, strTypeMaxLen=256, strTypeCutSuffix='...', stringifyType=1, ignoreErrors=False, objectsHash=None, depth=0, indent=2, ensure_ascii=False, maxDepth=10)
string MSG_INFO_PROCESSOR_OUTPUT
string MSG_ERROR_READ_LOG_CONFIG
string MSG_INFO_PROCESSOR_ERROR
def getURLFetchJson(self)
def sendToDbTask(self, outputPickle)