예제 #1
0
    def test_search(self):
        time.sleep(10)
        result = Image.search(es, "NYC", index=self.index_name)
        assert (len(result) == 1)

        result = Image.search(es, "happy", index=self.index_name)
        assert (len(result) == 2)

        result = Image.search(es, "computers", index=self.index_name)
        assert (len(result) == 0)
예제 #2
0
def get_dockerfile_packages():
    '''Given a Dockerfile return an approximate image object. This is mosty
    guess work and shouldn't be relied on for accurate information. Add
    Notice messages indicating as such:
        1. Create an image with a placeholder repotag
        2. For each RUN command, create a package list
        3. Create layer objects with incremental integers and add the package
        list to that layer with a Notice about parsing
        4. Return stub image'''
    stub_image = Image('easteregg:cookie')
    layer_count = 0
    for inst in docker.docker_commands:
        if inst[0] == 'RUN':
            layer_count = layer_count + 1
            layer = ImageLayer(layer_count)
            install_commands, msg = common.filter_install_commands(inst[1])
            if msg:
                layer.origins.add_notice_to_origins(
                    inst[1], Notice(msg, 'info'))
            pkg_names = []
            for command in install_commands:
                pkg_names.append(common.get_installed_package_names(command))
            for pkg_name in pkg_names:
                pkg = Package(pkg_name)
                # shell parser does not parse version pins yet
                # when that is enabled, Notices for no versions need to be
                # added here
                layer.add_package(pkg)
    return stub_image
예제 #3
0
def new_image():
    if request.method == 'POST':
        title = request.form['title']
        tags = request.form['tags']
        url = request.form['url']

        try:
            img = Image(title, tags, url)
        except Exception as e:
            return render_template("error.html", message=str(e))

        img.add_to_db(es)

        return render_template("success.html")
    else:
        return render_template("form.html")
예제 #4
0
 def detect(self, frame, count):
     image_url = f"./prueba/{count}.png"
     cv2.imwrite(os.path.join('./prueba', '%d.png') % count, frame)
     print(image_url)
     image = Image(self.yolo, image_url)
     detector = Detector(self.yolo, image)
     print(detector.detect())
예제 #5
0
def search():
    if request.method == 'POST':
        keyword = request.form['keyword']

        result = Image.search(es, keyword)

        return jsonify(result)  # load_images_for_display(result)
    else:
        return render_template('search.html')
예제 #6
0
    def detect(self, frame, count):
        image_with_extension = f"{count}.png"
        image_url = f"./prueba/{image_with_extension}"
        cv2.imwrite(os.path.join('./prueba', '%d.png') % count, frame)
        print(image_url)
        image = Image(self.yolo, image_url)
        detector = Detector(self.yolo, image)

        # si dentro de detector encuentro algo raro pues mando a llamar la api de aws
        array_of_labels = detector.detect()

        print(array_of_labels)

        if "cell phone" in array_of_labels:
            self.communication.post_image(image_url)
예제 #7
0
 def setUp(self):
     '''Test a generic Image class'''
     self.image = Image('debian:jessie')
예제 #8
0
def load_images_for_display(results):
    images = Image.get_images_info_for_display(results)

    return render_template("gallery.html", images=images)
예제 #9
0
def get_image(image_id):
    result = Image.get_by_id(es, image_id)

    return jsonify(result)
예제 #10
0
def index():
    all_images = Image.load_all_images(es)
    images = Image.get_images_info_for_display(all_images)

    return render_template('index.html', images=images)
예제 #11
0
 def test_load_all_images(self):
     time.sleep(10)
     assert (len(Image.load_all_images(es, index=self.index_name)) == 3)
예제 #12
0
 def test_get_by_id(self):
     assert (Image.get_by_id(es, self.test_id,
                             index=self.index_name)['_id'] == self.test_id)
예제 #13
0
 def test_add_to_db(self):
     img = Image(self.img_name, self.img_tags, self.img_url)
     id = img.add_to_db(es, index=self.index_name)['_id']
     es.get(index=self.index_name, id=id)
     es.delete(index=self.index_name, id=id)
예제 #14
0
 def test_image_success(self):
     img = Image(self.img_name, self.img_tags, self.img_url)
     assert (img.title == self.img_name
             and img.tags == self.img_tags.split(',')
             and img.url == self.img_url)