Skip to content

Commit

Permalink
Use hex format for display of crc32
Browse files Browse the repository at this point in the history
Use python-version idempotent version as well.
  • Loading branch information
Ivoz committed Apr 8, 2016
1 parent 70d70cf commit 998330c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bin/rebuild-script.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
import os
import re
import codecs
from zlib import crc32
from zlib import crc32 as _crc32


def crc32(data):
"""Python version idempotent"""
return _crc32(data) & 0xffffffff


here = os.path.dirname(__file__)
script = os.path.join(here, '..', 'virtualenv.py')
Expand All @@ -20,6 +26,7 @@
re.S)
file_template = b'##file %(filename)s\n%(varname)s = convert("""\n%(data)s""")'


def rebuild(script_path):
with open(script_path, 'rb') as f:
script_content = f.read()
Expand All @@ -42,12 +49,12 @@ def rebuild(script_path):
new_data = b64.encode(gzip.encode(embedded)[0])[0]

if new_data == data:
print(' File up to date (crc: %s)' % new_crc)
print(' File up to date (crc: %08x)' % new_crc)
parts += [match.group(0)]
continue
# Else: content has changed
crc = crc32(gzip.decode(b64.decode(data)[0])[0])
print(' Content changed (crc: %s -> %s)' %
print(' Content changed (crc: %08x -> %08x)' %
(crc, new_crc))
new_match = file_template % {
b'filename': filename,
Expand Down

0 comments on commit 998330c

Please sign in to comment.