~ubuntu-branches/debian/jessie/armory/jessie

« back to all changes in this revision

Viewing changes to extras/createTestBlocksForReadBlkUpdate.py

  • Committer: Package Import Robot
  • Author(s): Joseph Bisch
  • Date: 2014-10-07 10:22:45 UTC
  • Revision ID: package-import@ubuntu.com-20141007102245-2s3x3rhjxg689hek
Tags: upstream-0.92.3
ImportĀ upstreamĀ versionĀ 0.92.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from sys import path
 
2
path.append('..')
 
3
 
 
4
from armoryengine import *
 
5
 
 
6
TheBDM.setBlocking(True)
 
7
TheBDM.setOnlineMode(True)
 
8
 
 
9
if not os.path.exists('testmultiblock'):
 
10
   os.mkdir('testmultiblock')
 
11
 
 
12
fout = []
 
13
fout.append([0,   101, 'testmultiblock/blk00000.dat'])
 
14
fout.append([0,   102, 'testmultiblock/blk00000_test1.dat']) # Add 1 block
 
15
fout.append([0,   105, 'testmultiblock/blk00000_test2.dat']) # Add 3 blocks
 
16
fout.append([106, 106, 'testmultiblock/blk00001_test3.dat']) # Just block split
 
17
fout.append([107, 109, 'testmultiblock/blk00002_test4.dat']) # Another block split 3 blks
 
18
fout.append([107, 110, 'testmultiblock/blk00002_test5.dat']) # Add block 
 
19
fout.append([110, 113, 'testmultiblock/blk00003_test5.dat']) #      and split
 
20
 
 
21
 
 
22
for start,end,theFile in fout:
 
23
   if os.path.exists(theFile):
 
24
      os.remove(theFile)
 
25
 
 
26
lastLocation = [0]*len(fout)
 
27
openfiles    = [[trip[0], trip[1], open(trip[2],'wb')] for trip in fout]
 
28
 
 
29
# Assume we are only reading into blk000000.dat, no split
 
30
for h in range(120):
 
31
   head = TheBDM.getHeaderByHeight(h)
 
32
   blk = head.serializeWholeBlock(MAGIC_BYTES, True)
 
33
   for i,trip in enumerate(openfiles):
 
34
      start,end,theFile = trip
 
35
      if (start <= h <= end):
 
36
         theFile.write(blk)
 
37
         lastLocation[i] += len(blk)
 
38
   
 
39
 
 
40
for start,end,opnfil in openfiles:
 
41
   opnfil.close()
 
42
   
 
43
   
 
44
for i,trip in enumerate(fout):
 
45
   start,end,theFile = trip
 
46
   sz = os.path.getsize(theFile)
 
47
   f = open(theFile,'ab')
 
48
   if i<3:
 
49
      f.write('\x00'*(22000-sz))
 
50
   else:
 
51
      f.write('\x00'*(1000-sz))
 
52
   f.close()
 
53
 
 
54
print 'Blocks written out:'
 
55
for start,end,fn in fout:
 
56
   if end-start==0:
 
57
      print '\t%d    in file: %s' % (end,fn)
 
58
   else:
 
59
      print '\t%d-%d in file: %s' % (start,end,fn)
 
60