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
get_statistic_variable Namespace Reference

Functions

def getArgs ()
 
def getFilesList (dirName, pattern)
 
def getValueFromDict (path, itemObject, delimiter=':')
 
def extractData (fileName, paramName)
 
def outputData (jsonDict, outputFile)
 

Variables

string FILES_FIELD_NAME = 'files'
 
 dirName
 
 pattern
 
 paramName
 
 outputFile
 
int totalCount = 0
 
dictionary filesDict = {}
 
def filesList = getFilesList(dirName, pattern)
 
 value = int(extractData(fileName, paramName))
 
dictionary jsonDict = {}
 

Detailed Description

HCE project, Tools for get statistic variable main functional.

@package: bin
@file get_statistic_variable.py
@author Alexander Vybornyh <alexander.hce.cluster@gmail.com>
@link: http://hierarchical-cluster-engine.com/
@copyright: Copyright &copy; 2013-2017 IOIX Ukraine
@license: http://hierarchical-cluster-engine.com/license/
@since: 0.1

Function Documentation

◆ extractData()

def get_statistic_variable.extractData (   fileName,
  paramName 
)

Definition at line 98 of file get_statistic_variable.py.

98 def extractData(fileName, paramName):
99  # variable for result
100  ret = 0
101  try:
102  with open(fileName) as f:
103  dataDict = json.load(f)
104  ret = int(getValueFromDict(paramName, dataDict))
105 
106  except Exception, err:
107  sys.stderr.write("Extract data from % failed. Error: %s\n" % (fileName, str(err)))
108 
109  return ret
110 
111 
112 # # output data
113 #
114 # @param jsonDict - output dictionary
115 # @param outputFile - output file name
116 # @return - None
def getValueFromDict(path, itemObject, delimiter=':')
def extractData(fileName, paramName)
Here is the call graph for this function:

◆ getArgs()

def get_statistic_variable.getArgs ( )

Definition at line 28 of file get_statistic_variable.py.

28 def getArgs():
29  # variables for result
30  dirName = pattern = paramName = None
31 
32  app = foundation.CementApp('get_statistic_variable')
33  app.setup()
34  app.add_arg('-d', '--dir', action='store', metavar='input_directory_name', help='input directory name', required=True)
35  app.add_arg('-p', '--pattern', action='store', metavar='pattern_file_name', help='pattern file name for search in dirrectory', required=True)
36  app.add_arg('-n', '--name', action='store', metavar='parameter_name', help='parameter name in found files', required=True)
37  app.add_arg('-o', '--output', action='store', metavar='output_file_name', help='output file name. If not set output in stdout')
38  app.run()
39 
40  dirName = app.pargs.dir
41  pattern = app.pargs.pattern
42  paramName = app.pargs.name
43  outputFile = app.pargs.output if app.pargs.output else None
44  app.close()
45 
46  return dirName, pattern, paramName, outputFile
47 
48 
49 # # get files list
50 #
51 # @param dirName - dirrectory name for search files
52 # @param pattern - re pattern for search files
53 # @return files list

◆ getFilesList()

def get_statistic_variable.getFilesList (   dirName,
  pattern 
)

Definition at line 54 of file get_statistic_variable.py.

54 def getFilesList(dirName, pattern):
55  # variable for result
56  filesList = []
57  if dirName is not None and pattern is not None:
58  try:
59  files = os.listdir(dirName)
60  for fileName in files:
61  fullName = dirName + os.sep + fileName
62  if os.path.isdir(fullName):
63  internalFilesList = getFilesList(fullName, pattern)
64  filesList += internalFilesList
65  else:
66  if re.search(pattern, fullName, re.U + re.I) is not None:
67  filesList.append(fullName)
68  except Exception:
69  pass
70 
71  return filesList
72 
73 
74 # # get value from dict
75 #
76 # @param path - path to parameter
77 # @param itemObject - item object
78 # @param delimiter - delimiter used for split
79 # @return extracted value
def getFilesList(dirName, pattern)

◆ getValueFromDict()

def get_statistic_variable.getValueFromDict (   path,
  itemObject,
  delimiter = ':' 
)

Definition at line 80 of file get_statistic_variable.py.

80 def getValueFromDict(path, itemObject, delimiter=':'):
81  # variable for result
82  ret = 0 # itemObject
83  fieldNamesList = path.split(delimiter)
84  for fieldName in fieldNamesList:
85  if isinstance(ret, dict) and fieldName in ret:
86  ret = ret[fieldName]
87  elif isinstance(ret, list) and fieldName.isdigit():
88  ret = ret[int(fieldName)]
89 
90  return ret
91 
92 
93 # # extract data from file
94 #
95 # @param fileName - file name
96 # @param paramName - parameter name
97 # @return integer value extracted from file
def getValueFromDict(path, itemObject, delimiter=':')
Here is the caller graph for this function:

◆ outputData()

def get_statistic_variable.outputData (   jsonDict,
  outputFile 
)

Definition at line 117 of file get_statistic_variable.py.

117 def outputData(jsonDict, outputFile):
118  try:
119  if isinstance(jsonDict, dict):
120  jsonData = json.dumps(jsonDict)
121 
122  if outputFile is None:
123  sys.stdout.write(jsonData)
124  else:
125  with open(outputFile, 'w') as f:
126  f.write(jsonData)
127 
128  except Exception, err:
129  sys.stderr.write("Ouput data failed. Error: %s\n" % str(err))
130 
131 
132 # # Main processing
def outputData(jsonDict, outputFile)

Variable Documentation

◆ dirName

get_statistic_variable.dirName

Definition at line 138 of file get_statistic_variable.py.

◆ FILES_FIELD_NAME

string get_statistic_variable.FILES_FIELD_NAME = 'files'

Definition at line 135 of file get_statistic_variable.py.

◆ filesDict

dictionary get_statistic_variable.filesDict = {}

Definition at line 141 of file get_statistic_variable.py.

◆ filesList

def get_statistic_variable.filesList = getFilesList(dirName, pattern)

Definition at line 142 of file get_statistic_variable.py.

◆ jsonDict

dictionary get_statistic_variable.jsonDict = {}

Definition at line 149 of file get_statistic_variable.py.

◆ outputFile

get_statistic_variable.outputFile

Definition at line 138 of file get_statistic_variable.py.

◆ paramName

get_statistic_variable.paramName

Definition at line 138 of file get_statistic_variable.py.

◆ pattern

get_statistic_variable.pattern

Definition at line 138 of file get_statistic_variable.py.

◆ totalCount

int get_statistic_variable.totalCount = 0

Definition at line 140 of file get_statistic_variable.py.

◆ value

get_statistic_variable.value = int(extractData(fileName, paramName))

Definition at line 144 of file get_statistic_variable.py.