Ejemplo n.º 1
0
 def getFirstFrame(self, at):
     at.tags["actions"] = \
         ",".join((at.tags["actions"].decode('utf-8')).split(",")[1:])
     vidcap = cv2.VideoCapture(at.filepath)
     success, image = vidcap.read()
     if success:
         cv2.imwrite("frame.jpg", image)
     vidcap.release()
     output_attr = XattrFile("frame.jpg")
     for key in at.tags:
         output_attr.tags[key] = at.tags[key]
     output_attr.commit()
     output_attr.move_or_copy("/home/mfdata/var/in/incoming/test")
Ejemplo n.º 2
0
    def image_crop_and_export(self, input_file, x=0, y=0, w=10, h=10):
        try:
            x, y, w, h = int(x), int(y), int(w), int(h)
        except ValueError as e:
            print(e, "(wrong crop var type)")
        # Cropping part
        try:
            imageObject = Image.open(input_file.filepath)
        except IOError:
            self.error("IOError: Can't open %s (%s)" %
                       (input_file.filepath, self.original_file_name))
            return 1
        if x + y + w + h:
            output = "cropped_%s" % (self.original_file_name)
            try:
                cropped = imageObject.crop((x, y, w, h))
            except OSError:
                truncated_file_name = ("truncated_%s" %
                                       (self.original_file_name))
                imageObject.save("/home/mfdata/plugins/image_treatment/"
                                 "files/truncated_files/%s" %
                                 truncated_file_name)
                imageObject.close()
                self.error("OSError truncated file %s"
                           "sent to truncated_files dir" % truncated_file_name)
                return 1
            cropped.save(output, format="jpeg")
            cropped.save("/home/mfdata/plugins/image_treatment/files/cropped/"
                         "%s" % self.original_file_name,
                         format="jpeg")
            cropped.close()

            # Xattr part
            output_attr = XattrFile(output)
            for key in input_file.tags:
                output_attr.tags[key] = input_file.tags[key]
            if all(key in input_file.tags
                   for key in (b"crop_x", b"crop_y", b"crop_width",
                               b"cropp_height")):
                del input_file.tags[b"crop_x"]
                del input_file.tags[b"crop_y"]
                del input_file.tags[b"crop_width"]
                del input_file.tags[b"crop_heigth"]
            output_attr.tags["actions"] = ",".join(
                (output_attr.tags["actions"].decode('utf-8')).split(",")[1:])
            output_attr.commit()
            output_attr.move_or_copy("/home/mfdata/var/in/incoming/%s" %
                                     (output))
        else:
            print("No crop options")
        imageObject.close()
Ejemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser("Inject a file into a plugin/step")
    parser.add_argument("filepath", type=str, help="filepath to inject")
    parser.add_argument("--plugin",
                        type=str,
                        help="plugin name (default :guess_file_type)",
                        default="guess_file_type")
    parser.add_argument("--step",
                        type=str,
                        help="step name (default: main)",
                        default="main")
    parser.add_argument("--move",
                        action="store_true",
                        help="move the file instead of copying it "
                        "(default: copy)")
    parser.add_argument("--random-basename",
                        action="store_true",
                        help="use a random basename for copying/moving "
                        "the file (default: keep the original basename)")
    parser.add_argument(
        "--incoming",
        action="store_true",
        help="ignore plugin and step parameter and inject "
        "the file into the first configured directory listened"
        " by the MFDATA_INTERNAL_PLUGINS_WATCHED_DIRECTORIES env var")

    args = parser.parse_args()
    try:
        x = XattrFile(args.filepath)
    except Exception:
        logger.warning("can't open %s" % args.filepath)
        sys.exit(1)
    if args.random_basename:
        basename = get_unique_hexa_identifier()
    else:
        basename = os.path.basename(args.filepath)
    if args.incoming:
        env_var = 'MFDATA_INTERNAL_PLUGINS_WATCHED_DIRECTORIES'
        first_directory = os.environ[env_var].split(',')[0]
        new_filepath = os.path.join(os.environ['MFDATA_DATA_IN_DIR'],
                                    first_directory, basename)
    else:
        new_filepath = \
            os.path.join(get_plugin_step_directory_path(args.plugin,
                                                        args.step), basename)
    if args.move:
        res, moved = x.move_or_copy(new_filepath)
        if not res:
            logger.warning("can't move %s to %s" %
                           (args.filepath, new_filepath))
            sys.exit(1)
    else:
        res = x.copy_or_nothing(new_filepath)
        if not res:
            logger.warning("can't copy %s to %s" %
                           (args.filepath, new_filepath))
            sys.exit(1)