| 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   if sys.stdin.encoding: | 
|  | 712     return arg.decode(sys.stdin.encoding) | 
|  | 713 | 
|  | 714   return arg.decode(sys.getfilesystemencoding()) | 
|  | 715 | 
|  | 716 | 
| 709 def main(): | 717 def main(): | 
| 710   """Executes the script and handles command line arguments.""" | 718   """Executes the script and handles command line arguments.""" | 
| 711   # Set up parsers, then parse the command line arguments. | 719   # Set up parsers, then parse the command line arguments. | 
| 712   desc = 'Semi-automatically convert Chrome Apps into progressive web apps.' | 720   desc = 'Semi-automatically convert Chrome Apps into progressive web apps.' | 
| 713   parser = argparse.ArgumentParser(description=desc) | 721   parser = argparse.ArgumentParser(description=desc) | 
| 714   parser.add_argument('-v', '--verbose', help='Verbose logging', | 722   parser.add_argument('-v', '--verbose', help='Verbose logging', | 
| 715                       action='store_true') | 723                       action='store_true') | 
| 716   subparsers = parser.add_subparsers(dest='mode') | 724   subparsers = parser.add_subparsers(dest='mode') | 
| 717 | 725 | 
| 718   parser_convert = subparsers.add_parser( | 726   parser_convert = subparsers.add_parser( | 
| 719       'convert', help='Convert a Chrome App into a progressive web app.') | 727       'convert', help='Convert a Chrome App into a progressive web app.') | 
| 720   parser_convert.add_argument('input', help='Chrome App input directory') |  | 
| 721   parser_convert.add_argument( | 728   parser_convert.add_argument( | 
| 722       'output', help='Progressive web app output directory') | 729       'input', help='Chrome App input directory', type=unicode_arg) | 
|  | 730   parser_convert.add_argument( | 
|  | 731       'output', help='Progressive web app output directory', type=unicode_arg) | 
| 723   parser_convert.add_argument('-c', '--config', help='Configuration file', | 732   parser_convert.add_argument('-c', '--config', help='Configuration file', | 
| 724                               required=True, metavar='config') | 733                               required=True, metavar='config', type=unicode_arg) | 
| 725   parser_convert.add_argument('-f', '--force', help='Force output overwrite', | 734   parser_convert.add_argument('-f', '--force', help='Force output overwrite', | 
| 726                               action='store_true') | 735                               action='store_true') | 
| 727 | 736 | 
| 728   parser_config = subparsers.add_parser( | 737   parser_config = subparsers.add_parser( | 
| 729     'config', help='Print a default configuration file to stdout.') | 738     'config', help='Print a default configuration file to stdout.') | 
| 730   parser_config.add_argument('output', help='Output config file path') | 739   parser_config.add_argument('output', help='Output config file path', | 
|  | 740       type=unicode_arg) | 
| 731   parser_config.add_argument('-i', '--interactive', | 741   parser_config.add_argument('-i', '--interactive', | 
| 732       help='Whether to interactively generate the config file', | 742       help='Whether to interactively generate the config file', | 
| 733       action='store_true') | 743       action='store_true') | 
| 734 | 744 | 
| 735   args = parser.parse_args() | 745   args = parser.parse_args() | 
| 736 | 746 | 
| 737   # Set up logging. | 747   # Set up logging. | 
| 738   logging_level = logging.DEBUG if args.verbose else logging.INFO | 748   logging_level = logging.DEBUG if args.verbose else logging.INFO | 
| 739   logging.root.setLevel(logging_level) | 749   logging.root.setLevel(logging_level) | 
| 740   colorama.init(autoreset=True) | 750   colorama.init(autoreset=True) | 
| 741   logging_format = ':%(levelname)s:  \t%(message)s' | 751   logging_format = ':%(levelname)s:  \t%(message)s' | 
| 742   formatter = Formatter(logging_format) | 752   formatter = Formatter(logging_format) | 
| 743   handler = logging.StreamHandler(sys.stdout) | 753   handler = logging.StreamHandler(sys.stdout) | 
| 744   handler.setFormatter(formatter) | 754   handler.setFormatter(formatter) | 
| 745   logging.root.addHandler(handler) | 755   logging.root.addHandler(handler) | 
| 746 | 756 | 
| 747   # Main program. | 757   # Main program. | 
| 748   if args.mode == 'config': | 758   if args.mode == 'config': | 
| 749     configuration.generate_and_save(args.output, args.interactive) | 759     configuration.generate_and_save(args.output, args.interactive) | 
| 750 | 760 | 
| 751   elif args.mode == 'convert': | 761   elif args.mode == 'convert': | 
| 752     config = configuration.load(args.config) | 762     config = configuration.load(args.config) | 
| 753     convert_app(args.input, args.output, config, args.force) | 763     convert_app(args.input, args.output, config, args.force) | 
| 754 | 764 | 
| 755 | 765 | 
| 756 if __name__ == '__main__': | 766 if __name__ == '__main__': | 
| 757   sys.exit(main()) | 767   sys.exit(main()) | 
| OLD | NEW | 
|---|