11from os.path
import join, splitext
13from optparse
import OptionParser
14from datetime
import date
22 tar = tarfile.open(tar_path, mode=mode_string)
23 for input_file_name
in files:
25 archive_file_name = input_file_name[
len(client_root):]
27 archive_file_name = archive_file_name.replace(
"\\",
"/")
29 with open(input_file_name,
'rb')
as input_file:
30 tarInfo = tarfile.TarInfo(name=archive_file_name)
32 tarInfo.size = input_file.tell()
35 tar.addfile(tarInfo, fileobj=input_file)
38 with open(tar_path,
"rb")
as fin:
39 uncompressed = fin.read()
40 with open(tar_path,
"wb")
as fout:
42 gz = gzip.GzipFile(fileobj=fout, mode=
"wb", filename=
"", mtime=0)
43 gz.write(uncompressed)
48 if not options.client_root:
49 sys.stderr.write(
'--client_root not specified')
53 for dirname, dirnames, filenames
in os.walk(options.client_root):
55 filenames = [f
for f
in filenames
if not f[0] ==
'.']
56 dirnames[:] = [d
for d
in dirnames
if not d[0] ==
'.']
58 src_path = os.path.join(dirname, f)
59 if (os.path.isdir(src_path)):
61 files.append(src_path)
79 with open(output_file,
'w')
as out:
81// Copyright (c) %d, the Dart project authors. Please see the AUTHORS file
82// for details. All rights reserved. Use of this source code
is governed by a
83// BSD-style license that can be found
in the LICENSE file.
85''' % date.today().year)
91 out.write(
'namespace %s {\n' % outer_namespace)
92 if inner_namespace !=
None:
93 out.write(
'namespace %s {\n' % inner_namespace)
97 out.write(
'static const uint8_t %s_[] = {\n' % name)
100 for byte
in tar_archive:
101 line +=
r" %d," % (byte
if isinstance(byte, int)
else ord(byte))
103 if lineCounter == 10:
104 out.write(line +
'\n')
108 out.write(line +
'\n')
110 out.write(
'\nunsigned int %s_len = %d;\n' % (name,
len(tar_archive)))
111 out.write(
'\nconst uint8_t* %s = %s_;\n\n' % (name, name))
112 if inner_namespace !=
None:
113 out.write(
'} // namespace %s\n' % inner_namespace)
114 out.write(
'} // namespace %s\n' % outer_namespace)
118 if not options.output:
119 sys.stderr.write(
'--output not specified\n')
122 sys.stderr.write(
'--name not specified\n')
124 if not options.tar_input:
125 sys.stderr.write(
'--tar_input not specified\n')
129 with open(options.tar_input,
'rb')
as tar_file:
130 tar_archive = tar_file.read()
133 WriteCCFile(options.output, options.outer_namespace,
134 options.inner_namespace, options.name, tar_archive)
141 parser = OptionParser()
143 "--output", action=
"store", type=
"string", help=
"output file name")
144 parser.add_option(
"--tar_input",\
145 action=
"store", type=
"string",
146 help=
"input tar archive")
151 help=
"tar output file name")
156 help=
"outer C++ namespace",
162 help=
"inner C++ namespace",
168 help=
"name of tar archive symbol")
169 parser.add_option(
"--compress", action=
"store_true", default=
False)
174 help=
"root directory client resources")
176 (options, args) = parser.parse_args()
178 if options.tar_output:
183 except Exception
as inst:
184 sys.stderr.write(
'create_archive.py exception\n')
185 sys.stderr.write(str(inst))
186 sys.stderr.write(
'\n')
190if __name__ ==
'__main__':
191 sys.exit(
Main(sys.argv))
def WriteCCFile(output_file, outer_namespace, inner_namespace, name, tar_archive)
def CreateTarArchive(tar_path, client_root, compress, files)