44 OTHER_CHANGES = 300 |
44 OTHER_CHANGES = 300 |
45 |
45 |
46 |
46 |
47 def nextcontent(previous_content): |
47 def nextcontent(previous_content): |
48 """utility to produce a new file content from the previous one""" |
48 """utility to produce a new file content from the previous one""" |
49 return hashlib.md5(previous_content).hexdigest() |
49 return hashlib.md5(previous_content).hexdigest().encode('ascii') |
50 |
50 |
51 |
51 |
52 def filecontent(iteridx, oldcontent): |
52 def filecontent(iteridx, oldcontent): |
53 """generate a new file content |
53 """generate a new file content |
54 |
54 |
55 The content is generated according the iteration index and previous |
55 The content is generated according the iteration index and previous |
56 content""" |
56 content""" |
57 |
57 |
58 # initial call |
58 # initial call |
59 if iteridx is None: |
59 if iteridx is None: |
60 current = '' |
60 current = b'' |
61 else: |
61 else: |
62 current = str(iteridx) |
62 current = b"%d" % iteridx |
63 |
63 |
64 for idx in range(NB_LINES): |
64 for idx in range(NB_LINES): |
65 do_change_line = True |
65 do_change_line = True |
66 if oldcontent is not None and ALWAYS_CHANGE_LINES < idx: |
66 if oldcontent is not None and ALWAYS_CHANGE_LINES < idx: |
67 do_change_line = not ((idx - iteridx) % OTHER_CHANGES) |
67 do_change_line = not ((idx - iteridx) % OTHER_CHANGES) |
68 |
68 |
69 if do_change_line: |
69 if do_change_line: |
70 to_write = current + '\n' |
70 to_write = current + b'\n' |
71 current = nextcontent(current) |
71 current = nextcontent(current) |
72 else: |
72 else: |
73 to_write = oldcontent[idx] |
73 to_write = oldcontent[idx] |
74 yield to_write |
74 yield to_write |
75 |
75 |
125 hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1') |
125 hg('bundle', '--all', target, '--config', 'devel.bundle.delta=p1') |
126 with open(target, 'rb') as bundle: |
126 with open(target, 'rb') as bundle: |
127 data = bundle.read() |
127 data = bundle.read() |
128 digest = hashlib.md5(data).hexdigest() |
128 digest = hashlib.md5(data).hexdigest() |
129 with open(target + '.md5', 'wb') as md5file: |
129 with open(target + '.md5', 'wb') as md5file: |
130 md5file.write(digest + '\n') |
130 md5file.write(digest.encode('ascii') + b'\n') |
131 if sys.stdout.isatty(): |
131 if sys.stdout.isatty(): |
132 print('bundle generated at "%s" md5: %s' % (target, digest)) |
132 print('bundle generated at "%s" md5: %s' % (target, digest)) |
133 |
133 |
134 finally: |
134 finally: |
135 shutil.rmtree(tmpdir) |
135 shutil.rmtree(tmpdir) |