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)
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
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")
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())
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')
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)
def setUp(self): '''Test a generic Image class''' self.image = Image('debian:jessie')
def load_images_for_display(results): images = Image.get_images_info_for_display(results) return render_template("gallery.html", images=images)
def get_image(image_id): result = Image.get_by_id(es, image_id) return jsonify(result)
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)
def test_load_all_images(self): time.sleep(10) assert (len(Image.load_all_images(es, index=self.index_name)) == 3)
def test_get_by_id(self): assert (Image.get_by_id(es, self.test_id, index=self.index_name)['_id'] == self.test_id)
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)
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)