コード例 #1
0
 def test_resume_producing_no_existing_manifest(self, node):
     fs_carriage = FilesystemProducerImpl(self.test_dir_path)
     node.process_document = MagicMock(side_effect=EndOfData())
     node.document_sequence.sequence_identifier = "testSeq"
     fs_carriage.register(node)
     fs_carriage.resume_producing()
     assert node.process_document.called
コード例 #2
0
 def test_emit_document(self):
     data = 'test'
     node = MagicMock(spec=IProducerNode)
     node.provides.return_value = six.text_type
     test_time = timedelta(hours=42,
                           minutes=42,
                           seconds=42,
                           milliseconds=67)
     node.resume_producing.side_effect = EndOfData()
     fs_carriage = FilesystemProducerImpl(self.test_dir_path)
     fs_carriage.register_producer_node(node)
     fs_carriage.resume_producing()
     fs_carriage.emit_data(data,
                           availability_time=test_time,
                           sequence_identifier='testSeq',
                           sequence_number=1,
                           time_base='clock',
                           clock_mode='local')
     exported_document_path = os.path.join(self.test_dir_path,
                                           'testSeq_1.xml')
     assert os.path.exists(exported_document_path)
     manifest_path = os.path.join(self.test_dir_path,
                                  'manifest_testSeq.txt')
     assert os.path.exists(manifest_path)
     assert fs_carriage._default_clocks == {}
コード例 #3
0
 def test_resume_producing_no_existing_manifest(self, node):
     fs_carriage = FilesystemProducerImpl(self.test_dir_path)
     node.process_document = MagicMock(side_effect=EndOfData())
     node.document_sequence.sequence_identifier = "testSeq"
     fs_carriage.register(node)
     fs_carriage.resume_producing()
     assert node.process_document.called
コード例 #4
0
 def test_resume_producing_existing_manifest(self, node):
     manifest_path = os.path.join(self.test_dir_path, "manifest_testSeq.txt")
     with open(manifest_path, "w") as f:
         f.write("00:00:00.123678,testSeq_177.xml")
     fs_carriage = FilesystemProducerImpl(self.test_dir_path)
     node.process_document = MagicMock(side_effect=EndOfData())
     node.document_sequence.sequence_identifier = "testSeq"
     fs_carriage.register(node)
     fs_carriage.resume_producing()
     assert node.process_document.called
     self.assertEqual(node.document_sequence.last_sequence_number, 177)
コード例 #5
0
 def test_resume_producing_existing_manifest(self, node):
     manifest_path = os.path.join(self.test_dir_path, "manifest_testSeq.txt")
     with open(manifest_path, 'w') as f:
         f.write("00:00:00.123678,testSeq_177.xml")
     fs_carriage = FilesystemProducerImpl(self.test_dir_path)
     node.process_document = MagicMock(side_effect=EndOfData())
     node.document_sequence.sequence_identifier = "testSeq"
     fs_carriage.register(node)
     fs_carriage.resume_producing()
     assert node.process_document.called
     self.assertEqual(node.document_sequence.last_sequence_number, 177)
コード例 #6
0
    def test_resume_producing_no_existing_manifest(self):
        node = MagicMock(spec=IProducerNode)
        node.provides.return_value = six.text_type

        def side_effect():
            raise EndOfData()

        node.resume_producing.side_effect = side_effect

        fs_carriage = FilesystemProducerImpl(self.test_dir_path)
        fs_carriage.register_producer_node(node)
        fs_carriage.resume_producing()
        node.resume_producing.assert_called_once()
コード例 #7
0
 def test_emit_document(self):
     document = MagicMock(sequence_identifier="testSeq", sequence_number=1)
     document.get_xml = MagicMock(return_value="test")
     node = MagicMock()
     test_time = timedelta(hours=42, minutes=42, seconds=42, milliseconds=67)
     node.reference_clock.get_time.return_value = test_time
     node.process_document = MagicMock(side_effect=EndOfData())
     node.document_sequence.sequence_identifier = "testSeq"
     node.reference_clock.time_base = "clock"
     fs_carriage = FilesystemProducerImpl(self.test_dir_path)
     fs_carriage.register(node)
     fs_carriage.resume_producing()
     fs_carriage.emit_document(document)
     exported_document_path = os.path.join(self.test_dir_path, "testSeq_1.xml")
     assert os.path.exists(exported_document_path)
     manifest_path = os.path.join(self.test_dir_path, "manifest_testSeq.txt")
     assert os.path.exists(manifest_path)
コード例 #8
0
 def test_emit_document(self):
     document = MagicMock(sequence_identifier="testSeq", sequence_number=1)
     document.get_xml = MagicMock(return_value="test")
     node = MagicMock()
     test_time = timedelta(hours=42, minutes=42, seconds=42, milliseconds=67)
     node.reference_clock.get_time.return_value = test_time
     node.process_document = MagicMock(side_effect=EndOfData())
     node.document_sequence.sequence_identifier = "testSeq"
     node.reference_clock.time_base = "clock"
     fs_carriage = FilesystemProducerImpl(self.test_dir_path)
     fs_carriage.register(node)
     fs_carriage.resume_producing()
     fs_carriage.emit_document(document)
     exported_document_path = os.path.join(self.test_dir_path, 'testSeq_1.xml')
     assert os.path.exists(exported_document_path)
     manifest_path = os.path.join(self.test_dir_path, 'manifest_testSeq.txt')
     assert os.path.exists(manifest_path)
コード例 #9
0
def main():
    create_loggers()

    parsed_args = parser.parse_args()

    do_export = False
    if parsed_args.folder_export:
        do_export = True

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    document_sequence = EBUTT3DocumentSequence(
        sequence_identifier='TestSequence1',
        lang='en-GB',
        reference_clock=reference_clock
    )

    if parsed_args.reference_clock:
        subtitle_tokens = None  # Instead of text we provide the availability time as content.
    else:
        # Let's read our example conversation
        full_text = get_example_data('simple_producer.txt')
        if do_export:
            subtitle_tokens = iter(tokenize_english_document(full_text))
        else:
            # This makes the source cycle infinitely.
            subtitle_tokens = cycle(tokenize_english_document(full_text))

    # This object is used as flexible binding to the carriage mechanism and twisted integrated as dependency injection
    prod_impl = None
    if do_export:
        prod_impl = FilesystemProducerImpl(parsed_args.folder_export)
    else:
        prod_impl = TwistedProducerImpl()

    simple_producer = SimpleProducer(
        node_id='simple-producer',
        carriage_impl=prod_impl,
        document_sequence=document_sequence,
        input_blocks=subtitle_tokens
    )

    if do_export:
        prod_impl.resume_producing()
    else:
        factory = wsFactory(u"ws://127.0.0.1:9000")

        factory.protocol = StreamingServerProtocol

        factory.listen()

        # We are using a pull producer because it is the looping_task timer that triggers the production from the websocket
        # level. Every time the factory gets a pull signal from the timer it tells the producer to generate data.
        TwistedPullProducer(
            consumer=factory,
            custom_producer=prod_impl
        )

        looping_task = task.LoopingCall(factory.pull)

        looping_task.start(2.0)

        reactor.run()
コード例 #10
0
def main():
    create_loggers()

    parsed_args = parser.parse_args()

    sequence_identifier = 'TestSequence1'

    do_export = False
    if parsed_args.folder_export:
        do_export = True

    reference_clock = LocalMachineClock()
    reference_clock.clock_mode = 'local'

    document_sequence = EBUTT3DocumentSequence(
        sequence_identifier=sequence_identifier,
        lang='en-GB',
        reference_clock=reference_clock
    )

    if parsed_args.reference_clock:
        subtitle_tokens = None  # Instead of text we provide the availability time as content.
    else:
        # Let's read our example conversation
        full_text = get_example_data('simple_producer.txt')
        if do_export:
            subtitle_tokens = iter(tokenize_english_document(full_text))
        else:
            # This makes the source cycle infinitely.
            subtitle_tokens = cycle(tokenize_english_document(full_text))

    # This object is used as flexible binding to the carriage mechanism and twisted integrated as dependency injection
    prod_impl = None
    if do_export:
        prod_impl = FilesystemProducerImpl(parsed_args.folder_export, reference_clock)
    else:
        prod_impl = WebsocketProducerCarriage()
        prod_impl.sequence_identifier = sequence_identifier

    simple_producer = SimpleProducer(
        node_id='simple-producer',
        producer_carriage=None,
        document_sequence=document_sequence,
        input_blocks=subtitle_tokens
    )

    # Chaining a converter
    ProducerNodeCarriageAdapter(
        producer_carriage=prod_impl,
        producer_node=simple_producer
    )

    if do_export:
        prod_impl.resume_producing()
    else:

        twisted_producer = TwistedWSPushProducer(
            custom_producer=prod_impl
        )

        factory = BroadcastServerFactory(
            url=u"ws://127.0.0.1:9000",
            producer=twisted_producer
        )

        factory.protocol = BroadcastServerProtocol

        factory.listen()

        # Here we schedule in the simple producer to create content responding to a periodic interval timer.
        looping_task = task.LoopingCall(simple_producer.process_document)

        looping_task.start(2.0)

        reactor.run()