~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to mozilla/python/virtualenv/bin/rebuild-script.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""
 
3
Helper script to rebuild virtualenv.py from virtualenv_support
 
4
"""
 
5
 
 
6
import re
 
7
import os
 
8
import sys
 
9
 
 
10
here = os.path.dirname(__file__)
 
11
script = os.path.join(here, '..', 'virtualenv.py')
 
12
 
 
13
file_regex = re.compile(
 
14
    r'##file (.*?)\n([a-zA-Z][a-zA-Z0-9_]+)\s*=\s*convert\("""(.*?)"""\)',
 
15
    re.S)
 
16
file_template = '##file %(filename)s\n%(varname)s = convert("""\n%(data)s""")'
 
17
 
 
18
def rebuild():
 
19
    f = open(script, 'rb')
 
20
    content = f.read()
 
21
    f.close()
 
22
    parts = []
 
23
    last_pos = 0
 
24
    match = None
 
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)
 
30
        data = match.group(3)
 
31
        print('Found reference to file %s' % filename)
 
32
        pathname = os.path.join(here, '..', 'virtualenv_embedded', filename)
 
33
        f = open(pathname, 'rb')
 
34
        c = f.read()
 
35
        f.close()
 
36
        new_data = c.encode('zlib').encode('base64')
 
37
        if new_data == data:
 
38
            print('  Reference up to date (%s bytes)' % len(c))
 
39
            parts.append(match.group(0))
 
40
            continue
 
41
        print('  Content changed (%s bytes -> %s bytes)' % (
 
42
            zipped_len(data), len(c)))
 
43
        new_match = file_template % dict(
 
44
            filename=filename,
 
45
            varname=varname,
 
46
            data=new_data)
 
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')
 
53
        f.write(new_content)
 
54
        f.close()
 
55
        print('done.')
 
56
    else:
 
57
        print('No changes in content')
 
58
    if match is None:
 
59
        print('No variables were matched/found')
 
60
 
 
61
def zipped_len(data):
 
62
    if not data:
 
63
        return 'no data'
 
64
    try:
 
65
        return len(data.decode('base64').decode('zlib'))
 
66
    except:
 
67
        return 'unknown'
 
68
 
 
69
if __name__ == '__main__':
 
70
    rebuild()
 
71