bmSearch  0.0.4
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
updateCyrusTags.updateCyrusTags Class Reference

Public Member Functions

def __init__ (self)
 
def parseContent (self)
 
def setParam (self, kwargs)
 

Public Attributes

 cyrusDelivered
 
 dates
 
 Dates
 
 indexmax
 
 initFirstLinePattern
 
 maillog
 
 startLine
 
 timeInterval
 

Static Public Attributes

 initpos
 
 now
 

Detailed Description

updateCyrusTags :
        Has to open mail.log file,
        parse each line since a block address 
        try to update ELK entries (messages)

Constructor & Destructor Documentation

def updateCyrusTags.updateCyrusTags.__init__ (   self)
__init__ : 
        constructor
Regex :

Cyrus/IMAP : this line is relative to a délivery success
39  def __init__(self):
40  """
41  __init__ :
42  constructor
43  """
44 
45  """
46  Regex :
47 
48  Cyrus/IMAP : this line is relative to a délivery success
49  """
50  self.cyrusDelivered = cyrusDelivered
51 
52 
53  """
54  DATE
55  """
56  self.dates = bmDate().getCyrusUpdatePoolDates()
57  self.Dates = bmDate().getDates()
Definition: bmDate.py:1

Member Function Documentation

def updateCyrusTags.updateCyrusTags.parseContent (   self)
parseContent :
        read line from getFileContent(), and call cf parseLine()
150  def parseContent(self):
151  """
152  parseContent :
153  read line from getFileContent(), and call cf parseLine()
154 
155  """
156 
157  for line in self.getFileContent():
158  self.parseLine(line)
159 
160 
161 
162  def parseLine(self, line):
163  """
164  parseLine :
165  read line and extract data, and try to update an ELK entry (cf requestToELK Class)
166 
167  """
168 
169  thisLine = line.rstrip()
170 
171  cyrusDeliveredEntries = self.cyrusDelivered.match(thisLine)
172  if cyrusDeliveredEntries is not None:
173  date = self.Dates[cyrusDeliveredEntries.group('date')]
174  hour = cyrusDeliveredEntries.group('hour')
175  messageid = cyrusDeliveredEntries.group('messageid').replace("<","").replace(">","")
176  domain = cyrusDeliveredEntries.group('domain')
177  user = cyrusDeliveredEntries.group('user')
178 
179  recip = user.replace("^", ".") + "@" + domain
180  deliveredRecip = ""
181  deliveredRecip = recip + ": the " + date + " at " + hour
182 
183  u = requestToELK()
184  time.sleep(self.timeInterval)
185  u.retrieveBmsearchId(messageid)
186  u.updateDeliveredRecip(deliveredRecip)
187 
188 
189 
190 
191 
192 
193 
194 
Definition: requestToELK.py:1
def updateCyrusTags.updateCyrusTags.setParam (   self,
  kwargs 
)
setParam : 
        set paramaters from config file or kwagrs
        
        **kwargs
                file   : path to file to parse. I can be plain text, gzip or bzip2 compressed. By default what configured in /etc/bmSearch/config.py
                
                timeInterval : time expressed in second when to sleep the update process between two ELK connection 
67  def setParam(self, **kwargs):
68  """
69  setParam :
70  set paramaters from config file or kwagrs
71 
72  **kwargs
73  file : path to file to parse. I can be plain text, gzip or bzip2 compressed. By default what configured in /etc/bmSearch/config.py
74 
75  timeInterval : time expressed in second when to sleep the update process between two ELK connection
76 
77  """
78  # For Python re
79  linesStartWithPattern = "^("+ "|".join(self.dates)+")"
80  self.startLine = re.compile(linesStartWithPattern)
81 
82  # For file seek
83  self.indexmax = 5
84 
85  if self.now == "00:00":
86  self.maillog = config.oldermaillog
87  else:
88  self.maillog = config.maillog
89 
90  if "file" in kwargs.keys():
91  self.maillog = kwargs['file']
92 
93 
94  self.timeInterval = config.timeInterval
95  if "timeInterval" in kwargs.keys():
96  self.timeInterval = kwargs['timeInterval']
97 
98 
99 
100  def getStartsBlockReading(self):
101  '''
102  getStartsBlockReading:
103  Retrieve the file block address where to start reading when line matches with self.initFirstLinePattern (cf setParam)
104 
105  '''
106  n = 0
107  while n < self.indexmax:
108  initFirstLinePattern = self.initFirstLinePattern = '"^'+self.dates[n]+'"'
109 
110  grepCmd="grep -m 1 -b -e " + initFirstLinePattern + " " + self.maillog + " |cut -d':' -f1"
111  r = subprocess.Popen(grepCmd, shell=True, stdout=subprocess.PIPE)
112  pos = r.communicate()[0]
113 
114  if pos.rstrip().isdigit():
115  self.initpos = int(pos.rstrip())
116  break
117  n +=1
118 
119 
120 
121  def getFileContent(self):
122  """
123  getFileContent :
124  Read a file from a starting block address. The filename is from config or from kwargs "file" (cf setParam).
125 
126 
127  """
128  self.getStartsBlockReading()
129 
130  if self.initpos is None or isinstance( self.initpos, ( int, long ) ):
131  exit
132 
133  try:
134  self.maillog = self.maillog.encode('utf8')
135  f = open(self.maillog , 'r' )
136  f.seek(self.initpos, 0)
137  content = f.readlines()
138  f.close()
139 
140  for line in content:
141  thisLine = line.rstrip()
142  startLineEntries = self.startLine.match(thisLine)
143  if startLineEntries is not None:
144  yield line
145  except Exception as error:
146  pass
147 
148 
149 

Member Data Documentation

updateCyrusTags.updateCyrusTags.cyrusDelivered
updateCyrusTags.updateCyrusTags.dates
updateCyrusTags.updateCyrusTags.Dates
updateCyrusTags.updateCyrusTags.indexmax
updateCyrusTags.updateCyrusTags.initFirstLinePattern
updateCyrusTags.updateCyrusTags.initpos
static
updateCyrusTags.updateCyrusTags.maillog
updateCyrusTags.updateCyrusTags.now
static
updateCyrusTags.updateCyrusTags.startLine
updateCyrusTags.updateCyrusTags.timeInterval

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