Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(799)

Side by Side Diff: runtime/tools/create_archive.py

Issue 1534523002: Compress Observatory assets (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/vmservice_dartium.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 # Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 # for details. All rights reserved. Use of this source code is governed by a 2 # for details. All rights reserved. Use of this source code is governed by a
3 # BSD-style license that can be found in the LICENSE file. 3 # BSD-style license that can be found in the LICENSE file.
4 # 4 #
5 # This python script creates a tar archive and a C++ source file which contains 5 # This python script creates a tar archive and a C++ source file which contains
6 # the tar archive as an array of bytes. 6 # the tar archive as an array of bytes.
7 7
8 import os 8 import os
9 import sys 9 import sys
10 from os.path import join, splitext 10 from os.path import join, splitext
11 import time 11 import time
12 from optparse import OptionParser 12 from optparse import OptionParser
13 from datetime import date 13 from datetime import date
14 import tarfile 14 import tarfile
15 import tempfile 15 import tempfile
16 16
17 def makeArchive(tar_path, client_root, files): 17 def makeArchive(tar_path, client_root, compress, files):
18 tar = tarfile.open(tar_path, mode='w') 18 mode_string = 'w'
19 if compress:
20 mode_string = 'w:gz'
21 tar = tarfile.open(tar_path, mode=mode_string)
19 for input_file_name in files: 22 for input_file_name in files:
20 # Chop off client_root. 23 # Chop off client_root.
21 archive_file_name = input_file_name[ len(client_root) : ] 24 archive_file_name = input_file_name[ len(client_root) : ]
22 # Replace back slash with forward slash. So we do not have Windows paths. 25 # Replace back slash with forward slash. So we do not have Windows paths.
23 archive_file_name = archive_file_name.replace("\\", "/") 26 archive_file_name = archive_file_name.replace("\\", "/")
24 # Open input file and add it to the archive. 27 # Open input file and add it to the archive.
25 with open(input_file_name, 'rb') as input_file: 28 with open(input_file_name, 'rb') as input_file:
26 tarInfo = tarfile.TarInfo(name=archive_file_name) 29 tarInfo = tarfile.TarInfo(name=archive_file_name)
27 input_file.seek(0,2) 30 input_file.seek(0,2)
28 tarInfo.size = input_file.tell() 31 tarInfo.size = input_file.tell()
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 action="store", type="string", 94 action="store", type="string",
92 help="outer C++ namespace", 95 help="outer C++ namespace",
93 default="dart") 96 default="dart")
94 parser.add_option("--inner_namespace", 97 parser.add_option("--inner_namespace",
95 action="store", type="string", 98 action="store", type="string",
96 help="inner C++ namespace", 99 help="inner C++ namespace",
97 default="bin") 100 default="bin")
98 parser.add_option("--name", 101 parser.add_option("--name",
99 action="store", type="string", 102 action="store", type="string",
100 help="name of tar archive symbol") 103 help="name of tar archive symbol")
104 parser.add_option("--compress", action="store_true", default=False)
101 parser.add_option("--client_root", 105 parser.add_option("--client_root",
102 action="store", type="string", 106 action="store", type="string",
103 help="root directory client resources") 107 help="root directory client resources")
104 108
105 (options, args) = parser.parse_args() 109 (options, args) = parser.parse_args()
106 if not options.output: 110 if not options.output:
107 sys.stderr.write('--output not specified\n') 111 sys.stderr.write('--output not specified\n')
108 return -1 112 return -1
109 if not options.tar_output: 113 if not options.tar_output:
110 sys.stderr.write('--tar_output not specified\n') 114 sys.stderr.write('--tar_output not specified\n')
(...skipping 11 matching lines...) Expand all
122 # strip out all dot files. 126 # strip out all dot files.
123 filenames = [f for f in filenames if not f[0] == '.'] 127 filenames = [f for f in filenames if not f[0] == '.']
124 dirnames[:] = [d for d in dirnames if not d[0] == '.'] 128 dirnames[:] = [d for d in dirnames if not d[0] == '.']
125 for f in filenames: 129 for f in filenames:
126 src_path = os.path.join(dirname, f) 130 src_path = os.path.join(dirname, f)
127 if (os.path.isdir(src_path)): 131 if (os.path.isdir(src_path)):
128 continue 132 continue
129 files.append(src_path) 133 files.append(src_path)
130 134
131 # Write out archive. 135 # Write out archive.
132 makeArchive(options.tar_output, options.client_root, files) 136 makeArchive(options.tar_output,
137 options.client_root,
138 options.compress,
139 files)
133 140
134 # Read it back in. 141 # Read it back in.
135 with open(options.tar_output, 'rb') as tar_file: 142 with open(options.tar_output, 'rb') as tar_file:
136 tar_archive = tar_file.read() 143 tar_archive = tar_file.read()
137 144
138 # Write CC file. 145 # Write CC file.
139 writeCCFile(options.output, 146 writeCCFile(options.output,
140 options.outer_namespace, 147 options.outer_namespace,
141 options.inner_namespace, 148 options.inner_namespace,
142 options.name, 149 options.name,
143 tar_archive) 150 tar_archive)
144 return 0 151 return 0
145 152
146 except Exception, inst: 153 except Exception, inst:
147 sys.stderr.write('create_resources.py exception\n') 154 sys.stderr.write('create_resources.py exception\n')
148 sys.stderr.write(str(inst)) 155 sys.stderr.write(str(inst))
149 sys.stderr.write('\n') 156 sys.stderr.write('\n')
150 return -1 157 return -1
151 158
152 if __name__ == '__main__': 159 if __name__ == '__main__':
153 sys.exit(main(sys.argv)) 160 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « runtime/bin/vmservice_dartium.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698