class TestParser(unittest.TestCase): def setUp(self): self.parse = Parse('entrada.txt') def test_parse(self): self.parse.parse_file() path = os.getcwd() + '/server_1/5352b590-05ac-11e3-9923-c3e7d8408f3a' self.assertTrue(os.path.isfile(path)) f = open(path,'r') line = f.readlines() self.assertEqual(line[0], '177.126.180.83 - - [15/Aug/2013:13:54:38 -0300] \"GET /meme.jpg HTTP/1.1\" 200 2148 \"-\" \"userid=5352b590-05ac-11e3-9923-c3e7d8408f3a\"\n') self.assertEqual(line[2], '177.126.180.83 - - [15/Aug/2013:13:57:48 -0300] \"GET /lolcats.jpg HTTP/1.1\" 200 5143 \"-\" \"userid=5352b590-05ac-11e3-9923-c3e7d8408f3a\"\n') def test_parse_error(self): self.parse.parse_file() path = os.getcwd() + '/server_1/f85f124a-05cd-11e3-8a11-a8206608c529' self.assertTrue(os.path.isfile(path)) f = open(path,'r') line = f.readlines() self.assertNotEqual(line[0], '177.126.180.83 - - [15/Aug/2013:13:54:38 -0300] \"GET /meme.jpg HTTP/1.1\" 200 2148 \"-\" \"userid=5352b590-05ac-11e3-9923-c3e7d8408f3a\"\n')
help='Log file name for tegrastats data') parser.add_argument( '--verbose', '-v', action='store_true', help='Prints verbose messages while running tegrastats') parser.add_argument( '--only_parse', '-p', action='store_true', help='Parse tegrastats log file without running tegrastats') parser.add_argument( '--graph', '-g', action='store_true', help='Plots some useful graphs from tegrastats data parsed') options = parser.parse_args() tegrastats = Tegrastats(options.interval, options.log_file, options.verbose) parser = Parse(options.interval, options.log_file) if not options.only_parse: status = tegrastats.run() csv_file = parser.parse_file() if options.graph: graph = Graph(csv_file) graph.plots()
class MyHandler(FileSystemEventHandler): def on_modified(self, event): self.parse = Parse() if(event.src_path.endswith(".log")): self.parse.set_file_path(event.src_path) self.parse.parse_file()