Dennis Kempin | 351024d | 2013-02-06 11:18:21 -0800 | [diff] [blame^] | 1 | #! /usr/bin/env python |
| 2 | # Copyright (c) 2013 The Chromium OS 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. |
| 5 | |
| 6 | from editor import LogEditor |
| 7 | from log import Log |
| 8 | from optparse import OptionParser |
| 9 | import sys |
| 10 | |
| 11 | |
| 12 | usage = """Multitouch Viewer Usage Examples: |
| 13 | |
| 14 | Viewing logs: |
| 15 | $ %prog filename.log (from file) |
| 16 | $ %prog 172.22.75.0 (from device ip address) |
| 17 | $ %prog http://feedback.google.com/... (from feedback report url) |
| 18 | |
| 19 | Edit log and save result into output.log: |
| 20 | $ %prog log -o output.log |
| 21 | |
| 22 | Download log and save without editing: |
| 23 | $ %prog log -d -o output.log""" |
| 24 | |
| 25 | |
| 26 | def main(argv): |
| 27 | parser = OptionParser(usage=usage) |
| 28 | parser.add_option("-o", |
| 29 | dest="out", default=None, |
| 30 | help="set target filename for storing results", |
| 31 | metavar="output.log") |
| 32 | parser.add_option("-d", "--download", |
| 33 | action="store_true", dest="download", default=False, |
| 34 | help="download file only, don't edit.") |
| 35 | parser.add_option("-n", "--new", |
| 36 | dest="new", action="store_true", default=False, |
| 37 | help="Create new device logs before downloading. "+ |
| 38 | "[Default: False]") |
| 39 | parser.add_option("-p", "--persistent", |
| 40 | dest="persistent", action="store_true", default=False, |
| 41 | help="Keep server alive until killed in the terminal "+ |
| 42 | "via CTRL-C [Default: False]") |
| 43 | parser.add_option("-s", "--serve", |
| 44 | dest="serve", action="store_true", default=False, |
| 45 | help="Serve a standalone MTView.") |
| 46 | (options, args) = parser.parse_args() |
| 47 | |
| 48 | editor = LogEditor(persistent=options.persistent) |
| 49 | |
| 50 | if options.serve: |
| 51 | editor.Serve() |
| 52 | return |
| 53 | |
| 54 | if len(args) != 1: |
| 55 | parser.print_help() |
| 56 | exit(-1) |
| 57 | |
| 58 | log = Log(args[0], options) |
| 59 | |
| 60 | if options.download: |
| 61 | if not options.out: |
| 62 | print "--download requires -o to be set." |
| 63 | exit(-1) |
| 64 | log.SaveAs(options.out) |
| 65 | else: |
| 66 | if options.out is None: |
| 67 | editor.View(log) |
| 68 | else: |
| 69 | log = editor.Edit(log) |
| 70 | log.SaveAs(options.out) |
| 71 | |
| 72 | if __name__ == "__main__": |
| 73 | main(sys.argv) |