| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be found | 3 # Use of this source code is governed by a BSD-style license that can be found |
| 4 # in the LICENSE file. | 4 # in the LICENSE file. |
| 5 | 5 |
| 6 """Extracts registration forms from the corresponding HTML files. | 6 """Extracts registration forms from the corresponding HTML files. |
| 7 | 7 |
| 8 Used for extracting forms within HTML files. This script is used in | 8 Used for extracting forms within HTML files. This script is used in |
| 9 conjunction with the webforms_aggregator.py script, which aggregates web pages | 9 conjunction with the webforms_aggregator.py script, which aggregates web pages |
| 10 with fillable forms (i.e registration forms). | 10 with fillable forms (i.e registration forms). |
| 11 | 11 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 with open(numbered_form_filename, 'w') as f: | 221 with open(numbered_form_filename, 'w') as f: |
| 222 f.write(form_location_comment) | 222 f.write(form_location_comment) |
| 223 f.write(form_content) | 223 f.write(form_content) |
| 224 except IOError as e: | 224 except IOError as e: |
| 225 self.logger.error('Error: %s', e) | 225 self.logger.error('Error: %s', e) |
| 226 continue | 226 continue |
| 227 self.logger.info('\tFile "%s" extracted SUCCESSFULLY!', filename) | 227 self.logger.info('\tFile "%s" extracted SUCCESSFULLY!', filename) |
| 228 | 228 |
| 229 | 229 |
| 230 def main(): | 230 def main(): |
| 231 # Command line options. | |
| 232 parser = OptionParser() | 231 parser = OptionParser() |
| 233 parser.add_option( | 232 parser.add_option( |
| 234 '-l', '--log_level', metavar='LOG_LEVEL', default='error', | 233 '-l', '--log_level', metavar='LOG_LEVEL', default='error', |
| 235 help='LOG_LEVEL: debug, info, warning or error [default: %default]') | 234 help='LOG_LEVEL: debug, info, warning or error [default: %default]') |
| 236 parser.add_option( | 235 parser.add_option( |
| 237 '-j', '--js', dest='js', action='store_true', default=False, | 236 '-j', '--js', dest='js', action='store_true', default=False, |
| 238 help='Removes all javascript elements [default: %default]') | 237 help='Removes all javascript elements [default: %default]') |
| 239 | 238 |
| 240 (options, args) = parser.parse_args() | 239 (options, args) = parser.parse_args() |
| 241 options.log_level = options.log_level.upper() | 240 options.log_level = options.log_level.upper() |
| 242 if options.log_level not in ['DEBUG', 'INFO', 'WARNING', 'ERROR']: | 241 if options.log_level not in ['DEBUG', 'INFO', 'WARNING', 'ERROR']: |
| 243 print 'Wrong log_level argument.' | 242 print 'Wrong log_level argument.' |
| 244 parser.print_help() | 243 parser.print_help() |
| 245 sys.exit(1) | 244 return 1 |
| 246 | 245 |
| 247 options.log_level = getattr(logging, options.log_level) | 246 options.log_level = getattr(logging, options.log_level) |
| 248 extractor = FormsExtractor(logging_level=options.log_level) | 247 extractor = FormsExtractor(logging_level=options.log_level) |
| 249 extractor.Extract(options.js) | 248 extractor.Extract(options.js) |
| 249 return 0 |
| 250 | 250 |
| 251 | 251 |
| 252 if __name__ == '__main__': | 252 if __name__ == '__main__': |
| 253 main() | 253 sys.exit(main()) |
| OLD | NEW |