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

Side by Side Diff: services/android/add_manifest_entry.py

Issue 1239353002: Move rules for building Android Mojo services to //mojo/android (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months 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 | « mojo/android/rules.gni ('k') | services/android/rules.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # Copyright 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Add an entry into the manifest file of a jar file."""
8
9 import optparse
10 import os
11 import os.path
12 import sys
13 import shutil
14 import tempfile
15 import zipfile
16
17 def AddKey(input_jar, output, key, value):
18 working_dir = tempfile.mkdtemp()
19 extracted_dir = os.path.join(working_dir, 'extracted')
20 try:
21 with zipfile.ZipFile(input_jar) as zf:
22 zf.extractall(extracted_dir)
23 manifest_file = os.path.join(extracted_dir, 'META-INF', 'MANIFEST.MF')
24 manifest_content = ''
25 if os.path.isfile(manifest_file):
26 with open(manifest_file, 'r') as f:
27 manifest_content = f.read().strip()
28 if len(manifest_content):
29 manifest_content += '\n'
30 os.unlink(manifest_file)
31 manifest_content += '%s: %s\n' % (key, value)
32 with open(manifest_file, 'w') as f:
33 f.write(manifest_content)
34 shutil.make_archive(os.path.join(working_dir, 'output'), 'zip',
35 extracted_dir, '.')
36 shutil.move(os.path.join(working_dir, 'output.zip'), output)
37 finally:
38 shutil.rmtree(working_dir)
39
40
41 def main():
42 parser = optparse.OptionParser()
43
44 parser.add_option('--input', help='Name of the input jar.')
45 parser.add_option('--output', help='Name of the output jar.')
46 parser.add_option('--key', help='Name of the key to add to the manifest.')
47 parser.add_option('--value', help='Name of the value to add to the manifest.')
48
49 options, _ = parser.parse_args()
50 AddKey(options.input, options.output, options.key, options.value)
51
52
53 if __name__ == '__main__':
54 sys.exit(main())
OLDNEW
« no previous file with comments | « mojo/android/rules.gni ('k') | services/android/rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698