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
dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB Class Reference
Inheritance diagram for dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB:
Collaboration diagram for dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB:

Classes

class  Meta
 

Public Member Functions

def __init__ (self)
 
def setup (self)
 
def run (self)
 
def process (self)
 
def putContentToDB (self)
 
def processBatch (self)
 
def loadConfig (self)
 
def loadLogConfigFile (self)
 
def loadOptions (self)
 
def getExitCode (self)
 

Public Attributes

 exit_code
 
 logger
 
 config_db_dir
 
 sqliteTimeout
 
 input_data
 
 raw_contents_tbl
 
 config
 

Detailed Description

Definition at line 42 of file ProcessorStoreContentKVDB.py.

Constructor & Destructor Documentation

◆ __init__()

def dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.__init__ (   self)

Definition at line 54 of file ProcessorStoreContentKVDB.py.

54  def __init__(self):
55  # call base class __init__ method
56  foundation.CementApp.__init__(self)
57  self.exit_code = CONSTS.EXIT_SUCCESS
58  self.logger = None
59  self.config_db_dir = None
60  self.sqliteTimeout = SQLITE_TIMEOUT
61  self.input_data = None
62  self.raw_contents_tbl = None
63 
64 
def __init__(self)
constructor
Definition: UIDGenerator.py:19

Member Function Documentation

◆ getExitCode()

def dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.getExitCode (   self)

Definition at line 193 of file ProcessorStoreContentKVDB.py.

193  def getExitCode(self):
194  return self.exit_code

◆ loadConfig()

def dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.loadConfig (   self)

Definition at line 153 of file ProcessorStoreContentKVDB.py.

153  def loadConfig(self):
154  try:
155  self.config = ConfigParser.ConfigParser()
156  self.config.optionxform = str
157  if self.pargs.config:
158  self.config.read(self.pargs.config)
159  except Exception as err:
160  print MSG_ERROR_LOAD_CONFIG + err.message
161  raise
162 
163 
Here is the caller graph for this function:

◆ loadLogConfigFile()

def dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.loadLogConfigFile (   self)

Definition at line 167 of file ProcessorStoreContentKVDB.py.

167  def loadLogConfigFile(self):
168  try:
169  log_conf_file = self.config.get("Application", "log")
170  logging.config.fileConfig(log_conf_file)
171  self.logger = Utils.MPLogger().getLogger()
172  except Exception as err:
173  print MSG_ERROR_LOAD_LOG_CONFIG_FILE + err.message
174  raise
175 
176 
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadOptions()

def dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.loadOptions (   self)

Definition at line 180 of file ProcessorStoreContentKVDB.py.

180  def loadOptions(self):
181  try:
182  self.config_db_dir = self.config.get(self.__class__.__name__, "config_db_dir")
183  self.raw_contents_tbl = self.config.get("sqlite", "raw_contents_tbl")
184  self.sqliteTimeout = self.config.getint("sqlite", "timeout")
185  except Exception as err:
186  print MSG_ERROR_LOAD_OPTIONS + err.message
187  raise
188 
189 
Here is the caller graph for this function:

◆ process()

def dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.process (   self)

Definition at line 98 of file ProcessorStoreContentKVDB.py.

98  def process(self):
99  self.putContentToDB()
100  # return response.get()
101 
102 
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processBatch()

def dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.processBatch (   self)

Definition at line 134 of file ProcessorStoreContentKVDB.py.

134  def processBatch(self):
135  try:
136  # read pickled batch object from stdin and unpickle it
137  input_pickled_object = sys.stdin.read()
138  stored_in_data = pickle.loads(input_pickled_object)
139  self.input_data = stored_in_data
140  # self.logger.info("input scraper object: " + str(vars(stored_in_data)))
141  # TODO main processing over every url from list of urls in the batch object
142  self.process()
143  # self.logger.info("output : " + str(output))
144  # send response to the stdout
145  # print input_pickled_object
146  except Exception as err:
147  ExceptionLog.handler(self.logger, err, MSG_ERROR_PROCESS, (err))
148  self.exit_code = CONSTS.EXIT_FAILURE
149 
150 
Here is the call graph for this function:
Here is the caller graph for this function:

◆ putContentToDB()

def dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.putContentToDB (   self)

Definition at line 103 of file ProcessorStoreContentKVDB.py.

103  def putContentToDB(self):
104  # get appropriate db name, depending on siteId
105  if len(self.input_data.siteId):
106  db_name = self.config_db_dir + "/" + self.input_data.siteId + ".db"
107  else:
108  db_name = self.config_db_dir + "/0.db"
109  self.logger.info("db_name: " + db_name)
110  connector = None
111  try:
112  # put parsed resource to the db
113  connector = sqlite3.connect(db_name, timeout=self.sqliteTimeout) # @UndefinedVariable
114  connector.text_factory = str
115  with connector:
116  cur = connector.cursor()
117  query = "CREATE TABLE IF NOT EXISTS \
118  %s(id VARCHAR(32) PRIMARY KEY UNIQUE, data TEXT, CDate DATETIME DEFAULT CURRENT_TIMESTAMP)" \
119  % (self.raw_contents_tbl)
120  cur.execute(query)
121  cur.execute("INSERT OR REPLACE INTO raw_contents VALUES(?,?,datetime('now','localtime'))",
122  (self.input_data.urlId, self.input_data.raw_content))
123 
124  except Exception as err:
125  # Connection objects can be used as context managers that automatically commit or rollback transactions.
126  # In the event of an exception, the transaction is rolled back; otherwise, the transaction is committed:
127  # connector.rollback()
128  ExceptionLog.handler(self.logger, err, 'putContentToDB')
129  raise
130 
131 
Here is the caller graph for this function:

◆ run()

def dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.run (   self)

Definition at line 75 of file ProcessorStoreContentKVDB.py.

75  def run(self):
76  # call base class run method
77  foundation.CementApp.run(self)
78 
79  # config section
80  self.loadConfig()
81 
82  # load logger config file
83  self.loadLogConfigFile()
84 
85  # load sqlite db backend
86  # self.loadSqliteDBBackend()
87 
88  # sqlite
89  # self.loadDBBackend()
90 
91  # options
92  self.loadOptions()
93 
94 
Here is the call graph for this function:

◆ setup()

def dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.setup (   self)

Definition at line 67 of file ProcessorStoreContentKVDB.py.

67  def setup(self):
68  # call base class setup method
69  foundation.CementApp.setup(self)
70  self.args.add_argument('-c', '--config', action='store', metavar='config_file', help='config ini-file')
71 
72 

Member Data Documentation

◆ config

dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.config

Definition at line 155 of file ProcessorStoreContentKVDB.py.

◆ config_db_dir

dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.config_db_dir

Definition at line 59 of file ProcessorStoreContentKVDB.py.

◆ exit_code

dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.exit_code

Definition at line 57 of file ProcessorStoreContentKVDB.py.

◆ input_data

dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.input_data

Definition at line 61 of file ProcessorStoreContentKVDB.py.

◆ logger

dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.logger

Definition at line 58 of file ProcessorStoreContentKVDB.py.

◆ raw_contents_tbl

dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.raw_contents_tbl

Definition at line 62 of file ProcessorStoreContentKVDB.py.

◆ sqliteTimeout

dc_processor.ProcessorStoreContentKVDB.ProcessorStoreContentKVDB.sqliteTimeout

Definition at line 60 of file ProcessorStoreContentKVDB.py.


The documentation for this class was generated from the following file: