def createJobFromImageFile(self, filename=None):
     """
     Create a job for the file specified
     @param: filename An image file
     @return: a Job instance containing the image file to convert
     """
     for plugin in self._plugins:
         if plugin.canConvert(filename):
             sourceMedia = plugin.probeImage(filename)
             mediaFile = MediaFile()
             mediaFile.setFileName(filename)
             mediaFile.setImageStreams(sourceMedia.get("image"))
             return plugin.createImageJob(sourceMediaFile=mediaFile)
         else:
             return Job()
    def createImageJob(self, sourceMediaFile=None):
        """
        Creates a job to convert image file to my own storage requirements
        @param sourceMediaFile Source MediaFile object
        @return Job instance to convert the image
        """
        sourceImageStreams = sourceMediaFile.getImageStreams()
        masterJob = None
        backupDestinationMediaFile = MediaFile()
        convertDestinationMediaFile = MediaFile()
        destinationBakupImageStreams = list()
        destinationConvertImageStreams = list()

        # Source video attributes
        sIWidth = None
        sIHeight = None
        sIDPIX = None
        sIDPIY = None
        sIQuality = None

        # Handbrake Destination video attributes
        dIWidth = None
        dIHeight = None
        dIDPIX = None
        dIDPIY = None
        dIQuality = None

        countSourceImageStreams = len(sourceImageStreams)
        if countSourceImageStreams == 1:
            imsKey = sourceImageStreams.keys()[0]
            ims = sourceImageStreams[imsKey]

            sIWidth = ims.getWidth()
            sIHeight = ims.getHeight()
            sIDPIX = ims.getDensityX()[0]
            sIDPIY = ims.getDensityY()[0]
            sIQuality = ims.getQuality()
            loggerCameraSourceType = "Not identified"
            skippedJobCreation = True
            skippedReason = ""

            sIQuotientHeightWidth = float(float(sIHeight)/float(sIWidth))

            # Select appropriate destination media file convertion settings
            # Unknown1
            if(sIDPIX == 300 and sIDPIY == 300 and
               sIWidth >= 3508 and sIHeight >= 2480):
                if sIQuotientHeightWidth >= 1.0:
                    sIHeight=3508
                else:
                    dIWidth=2480
                dIQuality=95
                loggerCameraSourceType = "Unknown1"
                skippedJobCreation = False
            # GoPro 3+ Silver - 10MP Wide Mode
            elif(sIDPIX == 72 and sIDPIY == 72 and
               sIWidth == 3680 and sIHeight == 2760):
                dIQuality=92
                loggerCameraSourceType = "GoPro 3+ Silver - 10MP Wide Mode"
                skippedJobCreation = False
            # Unknown2
            elif((sIWidth <= 2480 and sIHeight <= 3508) or
                (sIDPIX <=300 and sIDPIY <=300)):
                # No need to re-encode
                skippedJobCreation = True
                skippedReason = "No need to re-encode"
            else:
                skippedJobCreation = True
                skippedReason = "No suitable converter configuration found. Missing a convertion case ? New image file ?"

            if not skippedJobCreation:
                try:
                    masterJob = OnSuccessOnlyConverterJob()
                    # Backup file as Job #1
                    sourceBackupFileName = sourceMediaFile.getFileName()
                    destinationBackupFileName = str(sourceBackupFileName) + ".backup"
                    destinationBackupMediaFile = MediaFile()
                    destinationBackupMediaFile.setFileName(destinationBackupFileName)
                    copyFileJob = CopyFileJob(sourceFileName=sourceMediaFile.getFileName(), destinationFileName=destinationBackupMediaFile.getFileName())
                    masterJob.addJob(copyFileJob)
                    loggerJobCreationRuntime.info("Will backup file: " + str(sourceBackupFileName) + " to " + str(destinationBackupFileName))

                    # Convert with ImageMagick's mogrity tool as Job #2
                    convertSourceMediaFile = MediaFile()
                    convertSourceMediaFile.setFileName(util.escapePathForOSIndependentShell(destinationBackupFileName))
                    convertDestinationFileName = sourceMediaFile.getFileName()
                    convertDestinationMediaFile.setFileName(util.escapePathForOSIndependentShell(convertDestinationFileName))
                    destinationConvertImageStream = ImageStream(filename=convertDestinationFileName, width=dIWidth, height=sIHeight, quality=dIQuality, densityX=dIDPIX, densityY=dIDPIY)
                    destinationConvertImageStreams.append(destinationConvertImageStream)
                    convertDestinationMediaFile.setImageStreams(destinationConvertImageStreams)
                    convertCLIBuilder = ConvertCLGenerator.createResizeJobFrom(sourceMediaFile=convertSourceMediaFile, destinationMediaFile=convertDestinationMediaFile)
                    convertCLIRunner = CLRunner(shell=True)

                    masterJob.addJob(ConverterJob(clibuilder=convertCLIBuilder, clirunner=convertCLIRunner))
                    loggerJobCreationRuntime.info("convert cl:" + str(convertCLIBuilder.tocl()))

                    # Delete backup file as Job #3
                    masterJob.addJob(DeleteFileJob(filename=destinationBackupMediaFile.getFileName()))
                    loggerJobCreationRuntime.info("Will delete file:" + str(destinationBackupMediaFile.getFileName()))
                    loggerJobCreationSuccess.info("JOB_CREATION_SUCCESS:" + sourceMediaFile.getFileName() + ": Type:" + loggerCameraSourceType)
                except BaseException:
                    loggerJobCreationFailed.exception("JOB_CREATION_FAILED:" + sourceMediaFile.getFileName() + ": Type:" + loggerCameraSourceType + "Exception :")
            else:
                loggerJobCreationSkipped.info("JOB_CREATION_SKIPPED:" +
                                              sourceMediaFile.getFileName() +
                                              ": Type:" + loggerCameraSourceType
                                              + " Reason: " +skippedReason)			
        else:
            loggerJobCreationFailed.error("JOB_CREATION_FAILED:" + sourceMediaFile.getFileName() + ": Reason: 1 video stream expected. " + str(countSourceVideoStreams) + " found.")

        if not masterJob:
            masterJob = Job()  # Created only if proper convert job not created 
        return masterJob