blob: b4c385ae6ed3c9a6934930337fbb8a9511938e93 [file] [log] [blame]
Dennis Kempin351024d2013-02-06 11:18:21 -08001#! /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
Harry Cutts0edf1572020-01-21 15:42:10 -08006from __future__ import print_function
7
Dennis Kempinb049d542013-06-13 13:55:18 -07008from mtedit import MTEdit
9from mtlib import Log
Dennis Kempin13d948e2014-04-18 11:23:32 -070010from mtlib.feedback import FeedbackDownloader
Dennis Kempin351024d2013-02-06 11:18:21 -080011from optparse import OptionParser
12import sys
13
14
Dennis Kempin136b7322013-02-06 13:20:57 -080015usage = """Multitouch Editor Usage Examples:
Dennis Kempin351024d2013-02-06 11:18:21 -080016
17Viewing logs:
18$ %prog filename.log (from file)
19$ %prog 172.22.75.0 (from device ip address)
20$ %prog http://feedback.google.com/... (from feedback report url)
21
22Edit log and save result into output.log:
23$ %prog log -o output.log
24
25Download log and save without editing:
26$ %prog log -d -o output.log"""
27
28
29def main(argv):
30 parser = OptionParser(usage=usage)
Dennis Kempin17766a62013-06-17 14:09:33 -070031 parser.add_option('-o',
32 dest='out', default=None,
33 help='set target filename for storing results',
34 metavar='output.log')
35 parser.add_option('-d', '--download',
36 dest='download', action='store_true', default=False,
37 help='download file only, don\'t edit.')
38 parser.add_option('-e', '--evdev',
39 dest='evdev', default=None,
40 help='path to local evdev log file')
41 parser.add_option('-n', '--new',
42 dest='new', action='store_true', default=False,
43 help='Create new device logs before downloading. '+
44 '[Default: False]')
45 parser.add_option('-p', '--persistent',
46 dest='persistent', action='store_true', default=False,
47 help='Keep server alive until killed in the terminal '+
48 'via CTRL-C [Default: False]')
49 parser.add_option('-s', '--serve',
50 dest='serve', action='store_true', default=False,
51 help='Serve a standalone MTEdit.')
52 parser.add_option('-c', '--screenshot',
53 dest='screenshot', action='store_true', default=False,
54 help='Force an attempt to find and download a screenshot.')
Dennis Kempin13d948e2014-04-18 11:23:32 -070055 parser.add_option('--login',
56 dest='login', action='store_true', default=False,
57 help='Force (re-)login to feedback.corp.google.com')
Dennis Kempin351024d2013-02-06 11:18:21 -080058 (options, args) = parser.parse_args()
59
Dennis Kempinb049d542013-06-13 13:55:18 -070060 editor = MTEdit(persistent=options.persistent)
Dennis Kempin351024d2013-02-06 11:18:21 -080061
62 if options.serve:
63 editor.Serve()
64 return
65
Dennis Kempin13d948e2014-04-18 11:23:32 -070066 if options.login:
67 FeedbackDownloader(force_login=True)
68
Dennis Kempin351024d2013-02-06 11:18:21 -080069 if len(args) != 1:
70 parser.print_help()
71 exit(-1)
72
73 log = Log(args[0], options)
74
75 if options.download:
76 if not options.out:
Harry Cutts0edf1572020-01-21 15:42:10 -080077 print('--download requires -o to be set.')
Dennis Kempin351024d2013-02-06 11:18:21 -080078 exit(-1)
79 log.SaveAs(options.out)
80 else:
81 if options.out is None:
82 editor.View(log)
83 else:
84 log = editor.Edit(log)
Dennis Kempin58d9a742014-05-08 18:34:59 -070085 if log:
86 log.SaveAs(options.out)
Dennis Kempin351024d2013-02-06 11:18:21 -080087
WeiNan-Peter, Wen9aab26a2013-05-13 09:32:29 -040088 log.CleanUp()
89
90
Dennis Kempin17766a62013-06-17 14:09:33 -070091if __name__ == '__main__':
Dennis Kempin351024d2013-02-06 11:18:21 -080092 main(sys.argv)