MCPcopy Create free account
hub / github.com/ElementsProject/elements / BlockDataCopier

Class BlockDataCopier

contrib/linearize/linearize-data.py:122–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120BlockExtent = namedtuple('BlockExtent', ['fn', 'offset', 'inhdr', 'blkhdr', 'size'])
121
122class BlockDataCopier:
123 def __init__(self, settings, blkindex, blkmap):
124 self.settings = settings
125 self.blkindex = blkindex
126 self.blkmap = blkmap
127
128 # Get first occurring block file id - for pruned nodes this
129 # will not necessarily be 0
130 self.inFn = getFirstBlockFileId(self.settings['input'])
131 self.inF = None
132 self.outFn = 0
133 self.outsz = 0
134 self.outF = None
135 self.outFname = None
136 self.blkCountIn = 0
137 self.blkCountOut = 0
138
139 self.lastDate = datetime.datetime(2000, 1, 1)
140 self.highTS = 1408893517 - 315360000
141 self.timestampSplit = False
142 self.fileOutput = True
143 self.setFileTime = False
144 self.maxOutSz = settings['max_out_sz']
145 if 'output' in settings:
146 self.fileOutput = False
147 if settings['file_timestamp'] != 0:
148 self.setFileTime = True
149 if settings['split_timestamp'] != 0:
150 self.timestampSplit = True
151 # Extents and cache for out-of-order blocks
152 self.blockExtents = {}
153 self.outOfOrderData = {}
154 self.outOfOrderSize = 0 # running total size for items in outOfOrderData
155
156 def writeBlock(self, inhdr, blk_hdr, rawblock):
157 blockSizeOnDisk = len(inhdr) + len(blk_hdr) + len(rawblock)
158 if not self.fileOutput and ((self.outsz + blockSizeOnDisk) > self.maxOutSz):
159 self.outF.close()
160 if self.setFileTime:
161 os.utime(self.outFname, (int(time.time()), self.highTS))
162 self.outF = None
163 self.outFname = None
164 self.outFn = self.outFn + 1
165 self.outsz = 0
166
167 (blkDate, blkTS) = get_blk_dt(blk_hdr)
168 if self.timestampSplit and (blkDate > self.lastDate):
169 print("New month " + blkDate.strftime("%Y-%m") + " @ " + self.hash_str)
170 self.lastDate = blkDate
171 if self.outF:
172 self.outF.close()
173 if self.setFileTime:
174 os.utime(self.outFname, (int(time.time()), self.highTS))
175 self.outF = None
176 self.outFname = None
177 self.outFn = self.outFn + 1
178 self.outsz = 0
179

Callers 1

linearize-data.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected