Esempio n. 1
0
    def test_parser_archive(self):
        filename = os.path.join(WATCH_FOLDER, 'doc_multi_archive.pdf')
        archive_filename = os.path.join(ARCHIVE_FOLDER, 'doc_multi_archive.pdf')
        copy_file(self.filename, filename)
        delete_file(archive_filename)
        self.assertTrue(os.path.exists(filename))  # should

        parser = Parser(filename=filename, options=Options(archive=True, delete=True,
                                                           file_format="%(id)s_archive.pdf"))
        parser.archive()
        self.assertTrue(os.path.exists(archive_filename))  # archived
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))