OLD | NEW |
1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
2 # Copyright 2009, Google Inc. | 2 # Copyright 2009, Google Inc. |
3 # All rights reserved. | 3 # All rights reserved. |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 15 matching lines...) Expand all Loading... |
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 | 31 |
32 """SCons tool for 7zip.""" | 32 """SCons tool for 7zip.""" |
33 | 33 |
34 | 34 |
35 import os | 35 import os |
| 36 import re |
36 import shutil | 37 import shutil |
37 import subprocess | 38 import subprocess |
38 import tempfile | 39 import tempfile |
39 import SCons.Script | 40 import SCons.Script |
40 | 41 |
41 | 42 |
42 def SevenZipGetFiles(env, source): | 43 def SevenZipGetFiles(env, source): |
43 """SCons emitter for 7zip extract. | 44 """SCons emitter for 7zip extract. |
44 | 45 |
45 Examines the source 7z archive to determine the list of files which will be | 46 Examines the source 7z archive to determine the list of files which will be |
46 created by extract/unzip operation. | 47 created by extract/unzip operation. |
47 Args: | 48 Args: |
48 env: The SCons environment to get the 7zip command line from. | 49 env: The SCons environment to get the 7zip command line from. |
49 source: The 7zip archive to examine. | 50 source: The 7zip archive to examine. |
50 Returns: | 51 Returns: |
51 The list of filenames in the archive. | 52 The list of filenames in the archive. |
52 """ | 53 """ |
53 # Expand the command to list archive contents. | 54 # Expand the command to list archive contents. |
54 cmd = env.subst('$SEVEN_ZIP l "%s"' % source) | 55 cmd = env.subst('$SEVEN_ZIP l "%s"' % source) |
55 # Run it and capture output. | 56 # Run it and capture output. |
56 output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] | 57 output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0] |
57 # Strip off 7-line header and 3-line trailer from 7zip output. | 58 # Remove header + footer. |
58 lines = output.split('\r\n')[7:-3] | 59 m = re.match('.*[-]{8}[^\n]*\n(.*)\r\n[-]{8}.*', output, re.DOTALL) |
59 # Trim out just the files and their names. | 60 lines = m.group(1).split('\r\n') |
| 61 # Trim out just the files and their names (skip directories). |
60 files = [i[53:] for i in lines if i[20] != 'D'] | 62 files = [i[53:] for i in lines if i[20] != 'D'] |
61 return files | 63 return files |
62 | 64 |
63 | 65 |
64 def SevenZipEmitter(target, source, env): | 66 def SevenZipEmitter(target, source, env): |
65 """An emitter that decides what nodes are vented from a 7zip archive. | 67 """An emitter that decides what nodes are vented from a 7zip archive. |
66 | 68 |
67 Args: | 69 Args: |
68 target: The target directory node. | 70 target: The target directory node. |
69 source: The source archive node. | 71 source: The source archive node. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 b = SCons.Script.Builder( | 138 b = SCons.Script.Builder( |
137 action=('cd $SOURCE && ' | 139 action=('cd $SOURCE && ' |
138 '$SEVEN_ZIP a $SEVEN_ZIP_ARCHIVE_OPTIONS ${TARGET.abspath} ./')) | 140 '$SEVEN_ZIP a $SEVEN_ZIP_ARCHIVE_OPTIONS ${TARGET.abspath} ./')) |
139 env['BUILDERS']['Archive7zip'] = b | 141 env['BUILDERS']['Archive7zip'] = b |
140 | 142 |
141 b = SCons.Script.Builder( | 143 b = SCons.Script.Builder( |
142 action=('cd ${SOURCE.dir} && ' | 144 action=('cd ${SOURCE.dir} && ' |
143 '$SEVEN_ZIP a $SEVEN_ZIP_COMPRESS_OPTIONS ' | 145 '$SEVEN_ZIP a $SEVEN_ZIP_COMPRESS_OPTIONS ' |
144 '${TARGET.abspath} ${SOURCE.file}')) | 146 '${TARGET.abspath} ${SOURCE.file}')) |
145 env['BUILDERS']['Compress7zip'] = b | 147 env['BUILDERS']['Compress7zip'] = b |
OLD | NEW |