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

Unified Diff: services/android/add_manifest_entry.py

Issue 1126393005: Fix java handler. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | services/android/rules.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/android/add_manifest_entry.py
diff --git a/services/android/add_manifest_entry.py b/services/android/add_manifest_entry.py
new file mode 100755
index 0000000000000000000000000000000000000000..a00052e90aa1fe3c86b079bf58a2d42e363899cc
--- /dev/null
+++ b/services/android/add_manifest_entry.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+#
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Add an entry into the manifest file of a jar file."""
+
+import optparse
+import os
+import os.path
+import sys
+import shutil
+import tempfile
+import zipfile
+
+def AddKey(input_jar, output, key, value):
+ working_dir = tempfile.mkdtemp()
+ extracted_dir = os.path.join(working_dir, 'extracted')
+ try:
+ with zipfile.ZipFile(input_jar) as zf:
+ zf.extractall(extracted_dir)
+ manifest_file = os.path.join(extracted_dir, 'META-INF', 'MANIFEST.MF')
+ manifest_content = ''
+ if os.path.isfile(manifest_file):
+ with open(manifest_file, 'r') as f:
+ manifest_content = f.read().strip()
+ if len(manifest_content):
+ manifest_content += '\n'
+ os.unlink(manifest_file)
+ manifest_content += '%s: %s\n' % (key, value)
+ with open(manifest_file, 'w') as f:
+ f.write(manifest_content)
+ shutil.make_archive(os.path.join(working_dir, 'output'), 'zip',
+ extracted_dir, '.')
+ shutil.move(os.path.join(working_dir, 'output.zip'), output)
+ finally:
+ shutil.rmtree(working_dir)
+
+
+def main():
+ parser = optparse.OptionParser()
+
+ parser.add_option('--input', help='Name of the input jar.')
+ parser.add_option('--output', help='Name of the output jar.')
+ parser.add_option('--key', help='Name of the key to add to the manifest.')
+ parser.add_option('--value', help='Name of the value to add to the manifest.')
+
+ options, _ = parser.parse_args()
+ AddKey(options.input, options.output, options.key, options.value)
+
+
+if __name__ == '__main__':
+ sys.exit(main())
« no previous file with comments | « no previous file | services/android/rules.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698