CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
ztail.Decoder Class Reference
Inheritance diagram for ztail.Decoder:

Public Member Functions

def __init__ (self, fname, last_n_lines)
 
def decode (self, bytes, if_start=False)
 
def follow (self)
 
def initial (self)
 
def initial_synchronize (self)
 
def output_line (self, line)
 
def reset (self)
 

Public Attributes

 f
 
 known_size
 
 last_n_lines
 
 sync
 
 zstream
 

Detailed Description

Definition at line 42 of file ztail.py.

Constructor & Destructor Documentation

def ztail.Decoder.__init__ (   self,
  fname,
  last_n_lines 
)

Definition at line 43 of file ztail.py.

43  def __init__(self, fname, last_n_lines):
44  self.f = open(fname, "rb")
45  self.last_n_lines = last_n_lines
46  self.reset()
47 
def __init__(self, fname, last_n_lines)
Definition: ztail.py:43
def reset(self)
Definition: ztail.py:48

Member Function Documentation

def ztail.Decoder.decode (   self,
  bytes,
  if_start = False 
)

Definition at line 55 of file ztail.py.

References ztail.strip_gzip_header(), ztail.Decoder.sync, and ztail.Decoder.zstream.

Referenced by ztail.Decoder.follow(), and ztail.Decoder.initial_synchronize().

55  def decode(self, bytes, if_start=False):
56  if not bytes:
57  return ""
58 
59  if if_start:
60  self.sync = True
61  #self.zstream = zlib.decompressobj(zlib.MAX_WBITS | 32)
62  bytes = strip_gzip_header(bytes)
63  elif not self.sync:
64  x = bytes.find(BLOCK_MAGIC)
65  if x != -1:
66  bytes = bytes[x + len(BLOCK_MAGIC):]
67  self.sync = True
68 
69  if not self.sync:
70  # not in sync, can't decode
71  return ""
72 
73  text = self.zstream.decompress(bytes)
74  #print "decoded:", len(text), len(self.zstream.unused_data)
75  if len(self.zstream.unused_data) == 8:
76  # this usually means checksum and len is left
77  # but we don't care about any of those!
78  self.zstream.flush()
79  self.zstream = None
80 
81  return text
82 
def strip_gzip_header(body)
Definition: ztail.py:16
def decode(self, bytes, if_start=False)
Definition: ztail.py:55
def ztail.Decoder.follow (   self)

Definition at line 111 of file ztail.py.

References mySiStripNoises.decode(), ztail.Decoder.decode(), DTPosNeg.decode(), l1t::HGCFETriggerDigi.decode(), SiStripPedestals.decode(), SiStripBadStrip.decode(), SiStripNoises.decode(), ztail.Decoder.initial_synchronize(), ztail.Decoder.known_size, ztail.Decoder.output_line(), ztail.Decoder.sync, and ztail.Decoder.zstream.

111  def follow(self):
112  if self.known_size is None:
113  raise Exception("Call initial() first.")
114 
115  while self.zstream:
116  size = os.fstat(self.f.fileno()).st_size
117 
118  if self.known_size > size:
119  sys.stderr.write("%s: file truncated\n" % sys.argv[0])
120  sys.stderr.write("%s: waiting for the next write\n" % sys.argv[0])
121  sys.stderr.flush()
122 
123  if self.sync:
124  self.sync = False
125  self.zstream.flush()
126  self.zstream = zlib.decompressobj(-zlib.MAX_WBITS)
127 
128  text = self.initial_synchronize()
129  continue
130  elif self.known_size == size:
131  time.sleep(1)
132  continue
133 
134  assert self.f.tell() == self.known_size
135  body = self.f.read(size - self.known_size)
136 
137  text = self.decode(body, self.known_size == 0)
138  self.output_line(text)
139 
140  self.known_size = size
141 
def follow(self)
Definition: ztail.py:111
def initial_synchronize(self)
Definition: ztail.py:87
def decode(self, bytes, if_start=False)
Definition: ztail.py:55
def output_line(self, line)
Definition: ztail.py:83
def ztail.Decoder.initial (   self)

Definition at line 101 of file ztail.py.

References ztail.Decoder.initial_synchronize(), ztail.Decoder.last_n_lines, and ztail.Decoder.output_line().

101  def initial(self):
102  text = self.initial_synchronize()
103 
104  n_lines = self.last_n_lines
105  lines = text.rsplit(ENDLINE_MAGIC, n_lines + 1)
106  if len(lines) > n_lines:
107  lines = lines[1:]
108 
109  self.output_line(ENDLINE_MAGIC.join(lines))
110 
def initial(self)
Definition: ztail.py:101
def initial_synchronize(self)
Definition: ztail.py:87
def output_line(self, line)
Definition: ztail.py:83
def ztail.Decoder.initial_synchronize (   self)

Definition at line 87 of file ztail.py.

References mySiStripNoises.decode(), ztail.Decoder.decode(), DTPosNeg.decode(), l1t::HGCFETriggerDigi.decode(), SiStripPedestals.decode(), SiStripBadStrip.decode(), SiStripNoises.decode(), CondFormats_BTauObjects::dictionary.f, FunctionMinSelector< F >.f, approx_math::binary32.f, DQMIO2histo.DQMIO.f, DTMuonLocalAlignment.f, ztail.Decoder.f, PixelToFEDAssociateFromAscii::Bdu.f, electronCompare.flushfile.f, electronStore.flushfile.f, l1t::emtf::AMC13Trailer.f, DTMuonMillepede.f, TSFit.f, hippyaddtobaddatafiles.KeepWhileOpenFile.f, cond::SmallWORMDict::IterHelp.f, HcalGainsCheck.f, SiPixel2DTemplateDBObject::char2float.f, SiPixelGenErrorDBObject::char2float.f, SiStripHotStripAlgorithmFromClusterOccupancy.f, ElectronCalibration.f, MuonDTLocalMillepedeAlgorithm.f, SiPixelTemplateDBObject::char2float.f, ElectronCalibrationUniv.f, SiStripBadAPVAlgorithmFromClusterOccupancy.f, SiStripBadAPVandHotStripAlgorithmFromClusterOccupancy.f, svgfig.Curve.f, svgfig.Line.f, svgfig.Rect.f, svgfig.Ellipse.f, svgfig.Ticks.f, svgfig.LineAxis.f, and SiStripPI.max.

Referenced by ztail.Decoder.follow(), and ztail.Decoder.initial().

88  f = self.f
89 
90  f.seek(0, 2)
91  end = f.tell()
92  start = max(0, end - DECOMPRESS_BUF_SIZE)
93  f.seek(start, 0)
94 
95  body = f.read(end - start)
96  text = self.decode(body, start == 0)
97 
98  self.known_size = end
99  return text
100 
def initial_synchronize(self)
Definition: ztail.py:87
def decode(self, bytes, if_start=False)
Definition: ztail.py:55
def ztail.Decoder.output_line (   self,
  line 
)

Definition at line 83 of file ztail.py.

Referenced by ztail.Decoder.follow(), and ztail.Decoder.initial().

83  def output_line(self, line):
84  sys.stdout.write(line)
85  sys.stdout.flush()
86 
def output_line(self, line)
Definition: ztail.py:83
def ztail.Decoder.reset (   self)

Definition at line 48 of file ztail.py.

48  def reset(self):
49  self.sync = False
50  if hasattr(self, 'zstream'):
51  self.zstream.flush()
52 
53  self.zstream = zlib.decompressobj(-zlib.MAX_WBITS)
54 
def reset(self)
Definition: ztail.py:48

Member Data Documentation

ztail.Decoder.f
ztail.Decoder.known_size

Definition at line 98 of file ztail.py.

Referenced by ztail.Decoder.follow().

ztail.Decoder.last_n_lines

Definition at line 45 of file ztail.py.

Referenced by ztail.Decoder.initial().

ztail.Decoder.sync

Definition at line 49 of file ztail.py.

Referenced by ztail.Decoder.decode(), and ztail.Decoder.follow().

ztail.Decoder.zstream

Definition at line 53 of file ztail.py.

Referenced by ztail.Decoder.decode(), ztee.GZipLog.flush_block(), and ztail.Decoder.follow().