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
AttrDeleteTask.py
Go to the documentation of this file.
1 '''
2 @package: dc
3 @author scorp
4 @link: http://hierarchical-cluster-engine.com/
5 @copyright: Copyright © 2013-2014 IOIX Ukraine
6 @license: http://hierarchical-cluster-engine.com/license/
7 @since: 0.1
8 '''
9 
10 import dc.EventObjects
11 from dtm.EventObjects import GeneralResponse
12 from dc_db.BaseTask import BaseTask
13 import dc_db.Constants as Constants
14 from app.Utils import varDump
15 import app.Utils as Utils # pylint: disable=F0401
16 
17 
18 logger = Utils.MPLogger().getLogger()
19 
20 
21 # # AttrDeleteTask Class, implements AttributeDelete task functionality
22 #
24 
25 
26  ATTR_DELETE_TEMPLATE = "DELETE FROM `%s` "
27 
28 
29  # #Class constructor
30  #
31  def __init__(self):
32  super(AttrDeleteTask, self).__init__()
33 
34 
35  # #make all necessary actions to delete attributes data from db
36  #
37  # @param urlDeletes list of AttrDelete objects
38  # @param queryCallback function for queries execution
39  # @return generalResponse instance of GeneralResponse object
40  def process(self, attrDeletes, queryCallback):
41  ret = GeneralResponse()
42  for attrDelete in attrDeletes:
43  if self.isSiteExist(attrDelete.siteId, queryCallback):
44  try:
45  additionWhere = None
46  if attrDelete.name is None:
47  additionWhere = self.generateCriterionSQL(attrDelete.criterions)
48  else:
49  additionWhere = ("WHERE `Name` = '%s'" % attrDelete.name)
50  logger.debug(">>> additionWhere = " + str(additionWhere))
51  if additionWhere is not None and len(additionWhere) > 0:
52  query = AttrDeleteTask.ATTR_DELETE_TEMPLATE % ((Constants.DC_ATT_TABLE_NAME_TEMPLATE % attrDelete.siteId))
53  queryCallback(query + additionWhere, Constants.ATT_DB_ID)
54  ret.statuses.append(True)
55  else:
56  ret.statuses.append(False)
57  except Exception as excp:
58  logger.debug(">>> [AttributeDelete] Some Exception = " + str(type(excp)) + " " + str(excp))
59  ret.statuses.append(False)
60  else:
61  ret.statuses.append(False)
62  return ret
63 
64 
65  # #fetchUrlsAttributes static method, fetches and returns attributes by urlMd5
66  #
67  # @param siteId incoming siteId
68  # @param urlMd5 incoming urlMd5
69  # @param queryCallback function for queries execution
70  @staticmethod
71  def deleteUrlsAttributes(siteId, urlMd5, queryCallback):
72  attrDeleteTask = AttrDeleteTask()
73  attrDeletes = [dc.EventObjects.AttributeDelete(siteId, None, {"WHERE": ("`URLMd5` = '%s'" % urlMd5)})]
74  res = attrDeleteTask.process(attrDeletes, queryCallback)
75  logger.debug(">>> AttrDeleteTask.deleteUrlsAttributes operation result = " + varDump(res))
def isSiteExist(self, siteId, queryCallback, userId=None)
Definition: BaseTask.py:29
GeneralResponse event object, represents general state response for multipurpose usage.
def deleteUrlsAttributes(siteId, urlMd5, queryCallback)
def process(self, attrDeletes, queryCallback)
def generateCriterionSQL(self, criterions, additionWhere=None, siteId=None)
Definition: BaseTask.py:46
def varDump(obj, stringify=True, strTypeMaxLen=256, strTypeCutSuffix='...', stringifyType=1, ignoreErrors=False, objectsHash=None, depth=0, indent=2, ensure_ascii=False, maxDepth=10)
Definition: Utils.py:410