OLD | NEW |
| (Empty) |
1 #!/usr/bin/python2.4 | |
2 # | |
3 # Copyright 2009 Google Inc. | |
4 # | |
5 # Licensed under the Apache License, Version 2.0 (the "License"); | |
6 # you may not use this file except in compliance with the License. | |
7 # You may obtain a copy of the License at | |
8 # | |
9 # http://www.apache.org/licenses/LICENSE-2.0 | |
10 # | |
11 # Unless required by applicable law or agreed to in writing, software | |
12 # distributed under the License is distributed on an "AS IS" BASIS, | |
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 # See the License for the specific language governing permissions and | |
15 # limitations under the License. | |
16 # ======================================================================== | |
17 | |
18 import getopt | |
19 import os.path | |
20 import sys | |
21 import tarfile | |
22 import urllib | |
23 | |
24 TEST_PREFIX = 'TEST_' | |
25 | |
26 def GenerateTarball(output_filename, members): | |
27 """ | |
28 Given a tarball name and a sequence of filenames, creates a tarball | |
29 containing the named files. | |
30 """ | |
31 tarball = tarfile.open(output_filename, 'w') | |
32 for filename in members: | |
33 # A hacky convention to get around the spaces in filenames is to | |
34 # urlencode them. So at this point we unescape those characters. | |
35 scrubbed_filename = urllib.unquote(os.path.basename(filename)) | |
36 if scrubbed_filename.startswith(TEST_PREFIX): | |
37 scrubbed_filename = scrubbed_filename[len(TEST_PREFIX):] | |
38 tarball.add(filename, scrubbed_filename) | |
39 tarball.close() | |
40 | |
41 (opts, args) = getopt.getopt(sys.argv[1:], 'i:o:p:') | |
42 | |
43 output_filename = '' | |
44 | |
45 for (o, v) in opts: | |
46 if o == '-o': | |
47 output_filename = v | |
48 | |
49 GenerateTarball(output_filename, args) | |
OLD | NEW |