3
Helper script to rebuild virtualenv.py from virtualenv_support
10
here = os.path.dirname(__file__)
11
script = os.path.join(here, '..', 'virtualenv.py')
13
file_regex = re.compile(
14
r'##file (.*?)\n([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*convert\("""(.*?)"""\)',
16
file_template = '##file %(filename)s\n%(varname)s = convert("""\n%(data)s""")'
19
f = open(script, 'rb')
25
for match in file_regex.finditer(content):
26
parts.append(content[last_pos:match.start()])
27
last_pos = match.end()
28
filename = match.group(1)
29
varname = match.group(2)
31
print('Found reference to file %s' % filename)
32
pathname = os.path.join(here, '..', 'virtualenv_embedded', filename)
33
f = open(pathname, 'rb')
36
new_data = c.encode('zlib').encode('base64')
38
print(' Reference up to date (%s bytes)' % len(c))
39
parts.append(match.group(0))
41
print(' Content changed (%s bytes -> %s bytes)' % (
42
zipped_len(data), len(c)))
43
new_match = file_template % dict(
47
parts.append(new_match)
48
parts.append(content[last_pos:])
49
new_content = ''.join(parts)
50
if new_content != content:
51
sys.stdout.write('Content updated; overwriting... ')
52
f = open(script, 'wb')
57
print('No changes in content')
59
print('No variables were matched/found')
65
return len(data.decode('base64').decode('zlib'))
69
if __name__ == '__main__':