示例#1
0
    def test_add(self):
        image_counter = ImageCounter()
        image_counter.add(1)

        assert image_counter.get(1) == 0

        image_counter.add(1, 5)

        assert image_counter.get(1) == 5
示例#2
0
    def test_get(self):
        image_counter = ImageCounter()
        image_counter.add(1)

        assert image_counter.get(1) == 0

        image_counter.next(1)

        assert image_counter.get(1) == 1
示例#3
0
def camera_streams(app, ftp_client, image_downloader):
    ic = ImageCounter()
    with app.app_context():
        while is_enabled():
            time.sleep(2)
            app.logger.info('sending stream')
            ip_cameras = IPCamera.query.all()
            for cam in ip_cameras:
                if not cam.ftp:
                    # check if remote folder exists
                    if cam.name not in ftp_client.ls():
                        app.logger.warning('Folder ' + cam.name + " not found")
                        continue
                    files = ftp_client.ls(cam.name)
                    image_counter = ic.extract_next(cam.id, files)
                    image_name = ic.build_name(image_counter)

                    remote_file_path = os.path.join(cam.name, image_name)

                    # image_downloader = ImageDownloader(cam.host, cam.port)
                    image_content = image_downloader.get_image(
                        cam.host, cam.port)
                    app.logger.info('uploading file:' + remote_file_path)
                    ftp_client.upload_content(remote_file_path, image_content)
示例#4
0
    def gen_serve_upload(self, app):
        # it bounds the life of the thread to the life of the flask app
        with app.app_context():
            ic = ImageCounter()
            while self.is_enabled():
                file_path = self.image_generator.generate()
                app.logger.info('serving')
                self.serve(file_path)
                if self.is_ftp_supported():

                    # check if remote folder exists
                    if self.camera_name not in self.ftp_client.ls():
                        app.logger.warning('Folder ' + self.camera_name +
                                           " not found")
                        continue
                    files = self.ftp_client.ls(self.camera_name)
                    image_counter = ic.extract_next(1, files)

                    image_name = ic.build_name(image_counter)

                    remote_file_path = os.path.join(self.camera_name,
                                                    image_name)

                    self.ftp_client.upload_file(remote_file_path, file_path)
示例#5
0
    def test_extract_next_empty(self):
        image_counter = ImageCounter()

        files = []

        assert image_counter.extract_next(1, files) == 1
示例#6
0
    def test_extract_next(self):
        image_counter = ImageCounter()

        files = ['image0001.jpg', 'image0002.jpg', 'image0003.jpg']

        assert image_counter.extract_next(1, files) == 4
示例#7
0
    def test_build_name(self):
        counter = 1
        expected = 'image0001.jpg'

        assert ImageCounter.build_name(counter) == expected
示例#8
0
    def test_parse(self):
        file_name = 'image0001.jpg'

        assert ImageCounter.parse(file_name) == 1
示例#9
0
 def test_add_negative(self):
     with pytest.raises(ValueError):
         image_counter = ImageCounter()
         image_counter.add(1, -1)
示例#10
0
    def test_exists(self):
        image_counter = ImageCounter()
        image_counter.add(1)

        assert image_counter.exists(1)