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

Public Member Functions

def __init__ (self)
 
def saveElement (self, storageDir, domain, siteId, element)
 
def loadElement (self, storageDir, host, siteId, externalElement=None, readFromFS=False)
 
def fetchLowFreqHeaders (self, fileStorageElements, siteStorageElements=None, fileCacheOnly=False)
 
def extractSiteStorageElement (self, jsonBuf)
 

Public Attributes

 storeDict
 

Static Public Attributes

string JSON_EXTENSION = ".json"
 

Detailed Description

Definition at line 23 of file LFSDataStorage.py.

Constructor & Destructor Documentation

◆ __init__()

def app.LFSDataStorage.LFSDataStorage.__init__ (   self)

Definition at line 30 of file LFSDataStorage.py.

30  def __init__(self):
31  self.storeDict = {}
32 
33 
def __init__(self)
constructor
Definition: UIDGenerator.py:19

Member Function Documentation

◆ extractSiteStorageElement()

def app.LFSDataStorage.LFSDataStorage.extractSiteStorageElement (   self,
  jsonBuf 
)

Definition at line 159 of file LFSDataStorage.py.

159  def extractSiteStorageElement(self, jsonBuf):
160  ret = None
161  try:
162  ret = json.loads(jsonBuf)
163  except Exception as exp:
164  logger.debug(">>> LFSDataStorage.extractSiteStorageElement can't load data from incoming jsonBuf " +
165  "(may be not json format...) exception=" + str(exp))
166  return ret
167 
168 

◆ fetchLowFreqHeaders()

def app.LFSDataStorage.LFSDataStorage.fetchLowFreqHeaders (   self,
  fileStorageElements,
  siteStorageElements = None,
  fileCacheOnly = False 
)

Definition at line 131 of file LFSDataStorage.py.

131  def fetchLowFreqHeaders(self, fileStorageElements, siteStorageElements=None, fileCacheOnly=False):
132  ret = []
133 
134  if isinstance(fileStorageElements, dict):
135  for headerKey in fileStorageElements:
136  minValue = None
137  t = None
138  for valueKey in fileStorageElements[headerKey]:
139  if (minValue is None or minValue > fileStorageElements[headerKey][valueKey]) and \
140  (\
141  # siteStorageElements is None or \
142  siteStorageElements is not None and
143  (headerKey in siteStorageElements and isinstance(siteStorageElements[headerKey], list) and \
144  valueKey in siteStorageElements[headerKey])):
145  minValue = fileStorageElements[headerKey][valueKey]
146  t = tuple([headerKey, valueKey])
147  elif (minValue is None or minValue > fileStorageElements[headerKey][valueKey]) and fileCacheOnly is True:
148  t = tuple([headerKey, valueKey])
149  if t is not None:
150  ret.append(t)
151 
152  return ret
153 
154 

◆ loadElement()

def app.LFSDataStorage.LFSDataStorage.loadElement (   self,
  storageDir,
  host,
  siteId,
  externalElement = None,
  readFromFS = False 
)

Definition at line 75 of file LFSDataStorage.py.

75  def loadElement(self, storageDir, host, siteId, externalElement=None, readFromFS=False):
76  nodeElem = None
77  if not readFromFS and host in self.storeDict and siteId in self.storeDict[host]:
78  nodeElem = self.storeDict[host][siteId]
79  if nodeElem is None:
80  if not os.path.isdir(storageDir):
81  os.makedirs(storageDir)
82 
83  if os.path.isdir(storageDir):
84  localDir = storageDir
85  if localDir[-1] != "/":
86  localDir += "/"
87  localDir += host
88  if os.path.isdir(localDir):
89  localFileName = localDir
90  localFileName += "/"
91  localFileName += str(siteId)
92  localFileName += self.JSON_EXTENSION
93  try:
94  fd = open(localFileName, "r")
95  fileBuf = fd.read()
96  if fileBuf is not None and fileBuf != "":
97  nodeElem = json.loads(fileBuf)
98  fd.close()
99  except IOError:
100  logger.debug(">>> LFSDataStorage.loadElement can't open file to read, file=" + str(localFileName))
101  except Exception as exp:
102  logger.debug(">>> LFSDataStorage.loadElement some exception, = " + str(exp))
103  else:
104  logger.debug(">>> LFSDataStorage.loadElement can't find storage dir, dir=" + str(localDir))
105  else:
106  logger.debug(">>> LFSDataStorage.loadElement can't find root dir, dir=" + str(storageDir))
107  # save nodeElem in class storage hash
108  if nodeElem is not None:
109  if host not in self.storeDict:
110  self.storeDict[host] = {}
111  self.storeDict[host][siteId] = nodeElem
112  if externalElement is not None:
113  if nodeElem is None:
114  nodeElem = {}
115  for headerKey in externalElement:
116  if headerKey not in nodeElem:
117  nodeElem[headerKey] = {}
118  for valueKey in externalElement[headerKey]:
119  if valueKey not in nodeElem[headerKey]:
120  nodeElem[headerKey][valueKey] = 0
121  return nodeElem
122 
123 

◆ saveElement()

def app.LFSDataStorage.LFSDataStorage.saveElement (   self,
  storageDir,
  domain,
  siteId,
  element 
)

Definition at line 40 of file LFSDataStorage.py.

40  def saveElement(self, storageDir, domain, siteId, element):
41  jsonStr = json.dumps(element, indent=4)
42  if jsonStr is not None and jsonStr != "":
43  if os.path.isdir(storageDir):
44  localDir = storageDir
45  if localDir[-1] != "/":
46  localDir += "/"
47  localDir += domain
48  if not os.path.isdir(localDir):
49  try:
50  os.makedirs(localDir)
51  except Exception:
52  pass
53  localFileName = localDir
54  localFileName += "/"
55  localFileName += str(siteId)
56  localFileName += self.JSON_EXTENSION
57  try:
58  fd = open(localFileName, "w")
59  fd.write(jsonStr)
60  fd.close()
61  except IOError:
62  logger.debug(">>> LFSDataStorage.saveElement can't open file to write, file=" + localFileName)
63  else:
64  logger.debug(">>> LFSDataStorage.saveElement can't find root dir, dir=" + storageDir)
65 
66 

Member Data Documentation

◆ JSON_EXTENSION

string app.LFSDataStorage.LFSDataStorage.JSON_EXTENSION = ".json"
static

Definition at line 25 of file LFSDataStorage.py.

◆ storeDict

app.LFSDataStorage.LFSDataStorage.storeDict

Definition at line 31 of file LFSDataStorage.py.


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