HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
ftest_PostProcessingApplicationClass.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 # coding: utf-8
3 
4 import os
5 import sys
6 import logging
7 from cement.core import foundation
8 
9 from dc_postprocessor.PostProcessingApplicationClass import PostProcessingApplicationClass
10 from app.Utils import varDump
11 import app.Consts as APP_CONSTS
12 
13 
14 def getLogger():
15  # create logger
16  logger = logging.getLogger(APP_CONSTS.LOGGER_NAME)
17  logger.setLevel(logging.DEBUG)
18 
19  # create console handler and set level to debug
20  ch = logging.StreamHandler()
21  ch.setLevel(logging.DEBUG)
22 
23  # create formatter
24  formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
25 
26  # add formatter to ch
27  ch.setFormatter(formatter)
28 
29  # add ch to logger
30  logger.addHandler(ch)
31 
32  return logger
33 
34 
36 
37  # Mandatory
38  class Meta(object):
39  label = 'TestApplication'
40  def __init__(self):
41  pass
42 
43  def __init__(self, logger=None):
44  PostProcessingApplicationClass.__init__(self, logger)
45 
46 
47  def setup(self):
48  PostProcessingApplicationClass.setup(self)
49 
50 
51  def run(self):
52  PostProcessingApplicationClass.run(self)
53  self.init()
54  self.process()
55  self.finalize()
56  # Finish logging
57  self.logger.info(APP_CONSTS.LOGGER_DELIMITER_LINE)
58 
59 
60  def init(self):
61  self.loadConfig()
62  self.inputBatch()
63 
64 
65  def process(self):
66  pass
67 
68 
69  def loadConfig(self):
70  pass
71 
72 
73  def finalize(self):
74  self.outputBatch()
75 
76 if __name__ == '__main__':
77 
78  logger = getLogger()
79  app = None
80  try:
81  # create the app
82  app = TestApplication(logger)
83  # setup the application
84  app.setup()
85  # add support command line arguments
86  app.args.add_argument('-c', '--config', action='store', metavar='config_file', help='config ini-file',
87  required=False)
88  app.args.add_argument('-i', '--inputFile', action='store', metavar='input_pickle_file', help='input pickle file',
89  required=False)
90 
91  # run the application
92  app.run()
93 
94  # get exit code
95  exit_code = app.exitCode
96 
97  except Exception, err:
98  logger.error("Exception: %s", str(err))
99  exit_code = APP_CONSTS.EXIT_FAILURE
100  except:
101  logger.error('Unknown exception')
102  exit_code = APP_CONSTS.EXIT_FAILURE
103 
104  logger.debug("exit_code = %s", str(exit_code))
105 
def inputBatch(self)
def __init__(self)
def run(self)
def process(self)
def loadConfig(self)
def getLogger()
logger
def setup(self)
def __init__(self, logger=None)
def init(self)
def finalize(self)