Esempio n. 1
0
    def test_parser_parse(self):
        parser = Parser(filename=self.filename, options=self.options)
        parser.parse()
        self.assertEqual(parser.file_count, 2)

        parser.process()
        self.assertTrue(os.path.isfile(self.file_600000))
        self.assertTrue(os.path.isfile(self.file_600001))
Esempio n. 2
0
    def on_created(self, event):
        """ """
        super(ProcessEventHandler, self).on_created(event)
        time.sleep(5)  # TODO: remove
        log.info(event.src_path)
        filename = event.src_path

        # timeout settings
        if self.options.delay > 0:
            time.sleep(self.options.delay)
        else:
            try_count = 0
            while try_count < 10:
                can_read = True
                if not os.path.exists(filename):
                    can_read = False
                elif not os.path.isfile(filename):
                    can_read = False
                elif not os.access(filename, os.R_OK):
                    can_read = False
                if can_read:
                    break
                time.sleep(1)
                try_count += 1
            log.debug('waited for %s seconds' % try_count)
        # Parse the file
        try:
            log.debug('Creating Parser() object for %s' % filename)
            parser = Parser(filename=filename, options=self.options)
            log.debug('Starting to parse file')
            parser.parse()
            log.debug('Processing parsed file')
            parser.process()
            if self.options.archive:
                log.debug('Arching parsed file')
                parser.archive()

            parser.delete()
        except Exception as ex:
            log.error("%s: Error: %s" % (filename, ex))