OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
cjhopman
2014/09/15 22:27:36
Could you add a docstring here (something really s
jbudorick
2014/09/16 02:50:41
Manifest functionality moved into javac.py. Added
| |
5 | |
6 import argparse | |
7 import os | |
8 import sys | |
9 | |
10 _MAX_LINE_LEN = 72 | |
11 | |
12 def _wrap(str_to_wrap): | |
13 """Wraps lines according to manifest requirements. | |
14 | |
15 Java requires that lines in a manifest file be no longer than | |
16 72 characters and that wrapped lines begin with a space. | |
17 | |
18 Args: | |
19 str_to_wrap: the string to wrap. | |
20 Returns: | |
21 The wrapped string. | |
22 """ | |
23 output = [] | |
cjhopman
2014/09/15 22:27:36
could probably use textwrap
return '\r\n'.join(te
jbudorick
2014/09/16 02:50:41
Didn't realize this existed. Nice.
| |
24 for line in str_to_wrap.splitlines(): | |
25 s = ([0] + range(_MAX_LINE_LEN - 2, len(line), _MAX_LINE_LEN - 3) | |
26 + [len(line)]) | |
27 lsplit = [line[s[i]:s[i+1]] for i in xrange(len(s) - 1)] | |
28 output.append('\r\n '.join(lsplit)) | |
29 return '\r\n'.join(output) | |
30 | |
31 def main(): | |
32 parser = argparse.ArgumentParser( | |
33 description='Generate a manifest file for a JAR.') | |
34 parser.add_argument('--main-class', dest='main_class', | |
cjhopman
2014/09/15 22:27:36
Is there a reason to not just infer dest from the
jbudorick
2014/09/16 02:50:41
Nope. I think I was in the habit of being explicit
| |
35 help='The class containing the main method.') | |
36 parser.add_argument('--classpath', help='The JAR\'s classpath.') | |
37 parser.add_argument('--output-file', dest='output_file', | |
38 help='The output manifest file path.') | |
39 args = parser.parse_args() | |
40 | |
41 try: | |
42 output = ['Manifest-Version: 1.0'] | |
43 if args.main_class: | |
44 output.append('Main-Class: %s' % args.main_class) | |
45 if args.classpath: | |
46 paths = args.classpath.split() | |
47 sanitized_paths = [] | |
48 for path in paths: | |
49 sanitized_paths.append(os.path.basename(path.strip('"'))) | |
50 output.append('Class-Path: %s' % ' '.join(sanitized_paths)) | |
51 output.append('Created-By: ') | |
52 output.append('') | |
53 | |
54 output = _wrap('\r\n'.join(output)) | |
55 | |
56 if args.output_file: | |
57 with open(args.output_file, 'w') as f: | |
58 f.write(output) | |
59 else: | |
60 sys.stdout.write(output) | |
61 except Exception as e: | |
62 print 'Error while writing JAR manifest file: %s' % str(e) | |
63 return 1 | |
64 | |
65 return 0 | |
66 | |
67 if __name__ == '__main__': | |
68 sys.exit(main()) | |
69 | |
OLD | NEW |