OLD | NEW |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python2 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # Copyright 2015 Google Inc. All Rights Reserved. | 4 # Copyright 2015 Google Inc. All Rights Reserved. |
5 # | 5 # |
6 # Licensed under the Apache License, Version 2.0 (the "License"); | 6 # Licensed under the Apache License, Version 2.0 (the "License"); |
7 # you may not use this file except in compliance with the License. | 7 # you may not use this file except in compliance with the License. |
8 # You may obtain a copy of the License at | 8 # You may obtain a copy of the License at |
9 # | 9 # |
10 # http://www.apache.org/licenses/LICENSE-2.0 | 10 # http://www.apache.org/licenses/LICENSE-2.0 |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
699 elif record.levelno == logging.WARNING: | 699 elif record.levelno == logging.WARNING: |
700 style = colorama.Fore.YELLOW + colorama.Style.BRIGHT | 700 style = colorama.Fore.YELLOW + colorama.Style.BRIGHT |
701 elif record.levelno == logging.INFO: | 701 elif record.levelno == logging.INFO: |
702 style = colorama.Fore.BLUE | 702 style = colorama.Fore.BLUE |
703 elif record.levelno == logging.DEBUG: | 703 elif record.levelno == logging.DEBUG: |
704 style = colorama.Fore.CYAN + colorama.Style.DIM | 704 style = colorama.Fore.CYAN + colorama.Style.DIM |
705 | 705 |
706 return style + super(Formatter, self).format(record) | 706 return style + super(Formatter, self).format(record) |
707 | 707 |
708 | 708 |
709 def unicode_arg(arg): | |
710 """Converts a bytestring command-line argument into a Unicode string.""" | |
711 return arg.decode(sys.stdin.encoding) | |
712 | |
713 | |
709 def main(): | 714 def main(): |
710 """Executes the script and handles command line arguments.""" | 715 """Executes the script and handles command line arguments.""" |
711 # Set up parsers, then parse the command line arguments. | 716 # Set up parsers, then parse the command line arguments. |
712 desc = 'Semi-automatically convert Chrome Apps into progressive web apps.' | 717 desc = 'Semi-automatically convert Chrome Apps into progressive web apps.' |
713 parser = argparse.ArgumentParser(description=desc) | 718 parser = argparse.ArgumentParser(description=desc) |
714 parser.add_argument('-v', '--verbose', help='Verbose logging', | 719 parser.add_argument('-v', '--verbose', help='Verbose logging', |
715 action='store_true') | 720 action='store_true') |
716 subparsers = parser.add_subparsers(dest='mode') | 721 subparsers = parser.add_subparsers(dest='mode') |
717 | 722 |
718 parser_convert = subparsers.add_parser( | 723 parser_convert = subparsers.add_parser( |
719 'convert', help='Convert a Chrome App into a progressive web app.') | 724 'convert', help='Convert a Chrome App into a progressive web app.') |
720 parser_convert.add_argument('input', help='Chrome App input directory') | 725 parser_convert.add_argument('input', help='Chrome App input directory', |
726 type=unicode_arg) | |
Matt Giuca
2016/01/29 02:46:25
Indent
Matthew Alger
2016/01/29 02:51:18
Done.
| |
721 parser_convert.add_argument( | 727 parser_convert.add_argument( |
722 'output', help='Progressive web app output directory') | 728 'output', help='Progressive web app output directory', type=unicode_arg) |
723 parser_convert.add_argument('-c', '--config', help='Configuration file', | 729 parser_convert.add_argument('-c', '--config', help='Configuration file', |
724 required=True, metavar='config') | 730 required=True, metavar='config', type=unicode_arg) |
725 parser_convert.add_argument('-f', '--force', help='Force output overwrite', | 731 parser_convert.add_argument('-f', '--force', help='Force output overwrite', |
726 action='store_true') | 732 action='store_true') |
727 | 733 |
728 parser_config = subparsers.add_parser( | 734 parser_config = subparsers.add_parser( |
729 'config', help='Print a default configuration file to stdout.') | 735 'config', help='Print a default configuration file to stdout.') |
730 parser_config.add_argument('output', help='Output config file path') | 736 parser_config.add_argument('output', help='Output config file path', |
737 type=unicode_arg) | |
731 parser_config.add_argument('-i', '--interactive', | 738 parser_config.add_argument('-i', '--interactive', |
732 help='Whether to interactively generate the config file', | 739 help='Whether to interactively generate the config file', |
733 action='store_true') | 740 action='store_true') |
734 | 741 |
735 args = parser.parse_args() | 742 args = parser.parse_args() |
736 | 743 |
737 # Set up logging. | 744 # Set up logging. |
738 logging_level = logging.DEBUG if args.verbose else logging.INFO | 745 logging_level = logging.DEBUG if args.verbose else logging.INFO |
739 logging.root.setLevel(logging_level) | 746 logging.root.setLevel(logging_level) |
740 colorama.init(autoreset=True) | 747 colorama.init(autoreset=True) |
741 logging_format = ':%(levelname)s: \t%(message)s' | 748 logging_format = ':%(levelname)s: \t%(message)s' |
742 formatter = Formatter(logging_format) | 749 formatter = Formatter(logging_format) |
743 handler = logging.StreamHandler(sys.stdout) | 750 handler = logging.StreamHandler(sys.stdout) |
744 handler.setFormatter(formatter) | 751 handler.setFormatter(formatter) |
745 logging.root.addHandler(handler) | 752 logging.root.addHandler(handler) |
746 | 753 |
747 # Main program. | 754 # Main program. |
748 if args.mode == 'config': | 755 if args.mode == 'config': |
749 configuration.generate_and_save(args.output, args.interactive) | 756 configuration.generate_and_save(args.output, args.interactive) |
750 | 757 |
751 elif args.mode == 'convert': | 758 elif args.mode == 'convert': |
752 config = configuration.load(args.config) | 759 config = configuration.load(args.config) |
753 convert_app(args.input, args.output, config, args.force) | 760 convert_app(args.input, args.output, config, args.force) |
754 | 761 |
755 | 762 |
756 if __name__ == '__main__': | 763 if __name__ == '__main__': |
757 sys.exit(main()) | 764 sys.exit(main()) |
OLD | NEW |