Ejemplo n.º 1
0
    def __call__(self):
        import magicColorspaceModAspctLoadFaster2 as magickProc2
        import convert_img_srgb
        convert_img_srgb.main(image_file=self.img)
        print self.img, ' <-- self.img ', self.rgbmean
        try:
            if self.mozu_sending_dir:
                _mozu_send_subdir = path.join(self.mozu_sending_dir, self.img.split('/')[-1][:4])
                try:
                    makedirs(_mozu_send_subdir)
                except Exception, e:
                    pass
                self.mozu_out = magickProc2.subproc_magick_png(self.img, rgbmean=self.rgbmean, destdir=_mozu_send_subdir)
                with open(path.join(self.mozu_log_dir, todaysdate + '_index.txt'), mode='a+') as fwrite:
                    logged_line = '{0}\t{1}\t{2}'.format('{:%Y%m%d%H%M%S}'.format(datetime.datetime.now()), 'PROCESSED', self.mozu_out)
                    fwrite.write(logged_line)
            self.pngout = magickProc2.subproc_magick_png(self.img, rgbmean=self.rgbmean, destdir=self.destdir)
            ## TODO: Possible insertion of Mozu and/or GoogleDrive upload and key exchange
            ## COPY TO MOZU DAILY DIR DEFINED AS GLOBAL ABOVE
            #shutil.copy2(self.pngout, imgdest_jpg_mozu)
            if self.mozu_out:
                magickProc2.subproc_magick_large_jpg(self.mozu_out, destdir=self.destdir)
                ret = magickProc2.subproc_magick_medium_jpg(self.mozu_out, destdir=self.destdir)
            else:
                magickProc2.subproc_magick_large_jpg(self.png_out, destdir=self.destdir)
                ret = magickProc2.subproc_magick_medium_jpg(self.png_out, destdir=self.destdir)

            return '-ret- %s \n-path- %s \n-dest- %s \n' % (ret, self.img, self.destdir)
Ejemplo n.º 2
0
 def worker():
     count = 0
     destdir =  '/mnt/Post_Complete/ImageDrop/'
     while True:
         img, rgbmean = q.get()
         convert_img_srgb.main(image_file=img)
         ## Add to Mongo DB
         try:
             jbmodules.mongo_image_prep.update_gridfs_extract_metadata(image_file, db_name='gridfs_mrktplce')
         except:
             jbmodules.mongo_image_prep.insert_gridfs_extract_metadata(image_file, db_name='gridfs_mrktplce')
         ## Generate png from source then jpgs from png
         pngout = magickProc2.subproc_magick_png(img, rgbmean=dict(rgbmean), destdir=destdir)
         magickProc2.subproc_magick_large_jpg(pngout, destdir=destdir)
         magickProc2.subproc_magick_medium_jpg(pngout, destdir=destdir)
         count += 1
         print count
         q.task_done()
Ejemplo n.º 3
0
def main(root_img_dir=None):
    import sys,glob,shutil,os,re
    import convert_img_srgb
    regex_coded = re.compile(r'^.+?/[1-9][0-9]{8}_[1-6]\.[JjPpNnGg]{3}$')
    regex_alt = re.compile(r'^.+?/[1-9][0-9]{8}_\w+?0[1-6]\.[JjPpNnGg]{3}$')
    regex_valid_style = re.compile(r'^.+?/[1-9][0-9]{8}_?.*?\.[JjPpNnGg]{3}$')

    if not root_img_dir:
        try:
            root_img_dir = sys.argv[1]
            if root_img_dir == 'jblocal':
                root_img_dir = os.path.abspath('/mnt/Post_Ready/Retouchers/JohnBragato/MARKETPLACE_LOCAL')
            else:
                root_img_dir = os.path.abspath('/mnt/Post_Complete/Complete_Archive/MARKETPLACE')
        except IndexError:
            root_img_dir = os.path.abspath('/mnt/Post_Complete/Complete_Archive/MARKETPLACE')
            pass
    else:
        pass

    try:
        destdir = os.path.abspath(sys.argv[2])

        if not os.path.isdir(destdir):
            os.makedirs(destdir, 16877)
    except IndexError:
        destdir =  '/mnt/Post_Complete/ImageDrop/' ##os.path.join(root_img_dir, 'output')
        # try:
        #     os.makedirs(destdir, 16877)
        # except OSError:
        #     pass

    if not type(root_img_dir) == list and os.path.isdir(root_img_dir):
        #import md5_unique_dup_files
        #duplicates = md5_unique_dup_files.find_duplicate_imgs(root_img_dir)[1]
        #[ os.remove(f) for f in duplicates if f ]
        imgs_renamed = [rename_retouched_file(f) for f in (glob.glob(os.path.join(root_img_dir,'*.??[gG]')))]
        img_dict = sort_files_by_values(glob.glob(os.path.join(root_img_dir,'*.??[gG]')))

        for k,v in img_dict.items():
            try:
                img = k
                ## Convert profile of source img if CMYK ignores if RGB
                convert_img_srgb.main(image_file=img)
                ## Get color pixel values from source img
                rgbmean     = v.items()
                ## Generate png from source then jpgs from png
                pngout = subproc_magick_png(img, rgbmean=dict(rgbmean), destdir=destdir)
                subproc_magick_large_jpg(pngout, destdir=destdir)
                subproc_magick_medium_jpg(pngout, destdir=destdir)
            except AttributeError:
                print 'SOMETHING IS WRONG WITH THE IMAGE Error {}'.format(img)
                pass

    else:
        'Image is ', root_img_dir
        img = root_img_dir
        if regex_coded.findall(img):
            img = rename_retouched_file(img)
        pngout = subproc_magick_png(img, destdir=destdir)
        subproc_magick_large_jpg(pngout, destdir=destdir)
        subproc_magick_medium_jpg(pngout, destdir=destdir)
def main(root_img_dir=None, destdir=None):
    import sys,glob,shutil,os,re
    import convert_img_srgb
    regex_coded = re.compile(r'^.+?/[1-9][0-9]{8}_[1-6]\.[JjPpNnGg]{3}$')
    regex_alt = re.compile(r'^.+?/[1-9][0-9]{8}_\w+?0[1-6]\.[JjPpNnGg]{3}$')
    regex_valid_style = re.compile(r'^.+?/[1-9][0-9]{8}_?.*?\.[JjPpNnGg]{3}$')

    if not root_img_dir:
        try:
            root_img_dir = sys.argv[1]
        except IndexError:
            root_img_dir = os.path.abspath('/mnt/Post_Complete/Complete_Archive/MARKETPLACE')
            pass
    else:
        pass

    if not destdir:
        try:
            destdir = os.path.abspath(sys.argv[2])
            if destdir.isdigit():
                destdir = os.path.join(root_img_dir, 'output')
        except IndexError:
            destdir = os.path.join(root_img_dir, 'output')
            try:
                os.makedirs(destdir, 16877)
            except OSError:
                pass

    if not os.path.isdir(destdir):
        os.makedirs(destdir, 16877)

    if os.path.isdir(root_img_dir):
        imgs_renamed = [rename_retouched_file(f) for f in (glob.glob(os.path.join(root_img_dir,'*.??[gG]')))]
        img_dict = sort_files_by_values(glob.glob(os.path.join(root_img_dir,'*.??[gG]')))

        for k,v in img_dict.items():
            try:
                img = k
                ## Convert profile of source img if CMYK ignores if RGB
                convert_img_srgb.main(image_file=img)
                ## Get color pixel values from source img
                rgbmean     = v.items()
                ## Generate png from source then jpgs from png
                pngout = subproc_magick_png(img, rgbmean=dict(rgbmean), destdir=destdir)
                subproc_magick_large_jpg(pngout, destdir=destdir)
                subproc_magick_medium_jpg(pngout, destdir=destdir)
            except AttributeError:
                print 'SOMETHING IS WRONG WITH THE IMAGE Error {}'.format(img)
                pass

    else:
        img = root_img_dir
        if regex_coded.findall(img):
            img = rename_retouched_file(img)
        pngout = subproc_magick_png(img, destdir=destdir)
        subproc_magick_large_jpg(pngout, destdir=destdir)
        subproc_magick_medium_jpg(pngout, destdir=destdir)


    upload_imagedrop(destdir)
    failed_dir = os.path.join(destdir,'failed_upload','*.??[gG]')
def main(**kwargs):
    import sys,glob,shutil,os,re
    from os import chdir, path
    sys.path.append('/usr/local/batchRunScripts/python/jbmodules/image_processing/marketplace_dev')

    import convert_img_srgb
    regex_coded = re.compile(r'^.+?/[1-9][0-9]{8}_[1-6]\.[JjPpNnGg]{3}$')
    regex_alt = re.compile(r'^.+?/[1-9][0-9]{8}_\w+?0[1-6]\.[JjPpNnGg]{3}$')
    regex_valid_style = re.compile(r'^.+?/[1-9][0-9]{8}_?.*?\.[JjPpNnGg]{3}$')

    if not kwargs.get('root_img_dir', os.environ.get('ROOT_IMG_DIR', '')):
        try:
            root_img_dir = sys.argv[1]
            if root_img_dir == 'jblocal':
                root_img_dir = path.abspath('/mnt/Post_Ready/Retouchers/JohnBragato/MARKETPLACE_LOCAL')
            else:
                root_img_dir = path.abspath('/mnt/Post_Complete/Complete_Archive/MARKETPLACE')
        except IndexError:
            root_img_dir = path.abspath('/mnt/Post_Complete/Complete_Archive/MARKETPLACE')
            pass
    else:
        root_img_dir = kwargs.get('root_img_dir', os.environ.get('ROOT_IMG_DIR'))

    try:
        destdir = path.abspath(sys.argv[2])
        if not path.isdir(destdir):
            os.makedirs(destdir)
    except IndexError:
        destdir =  '/mnt/Post_Complete/ImageDrop/' ##path.join(root_img_dir, 'output')
        # try:
        #     os.makedirs(destdir, 16877)
        # except OSError:
        #     pass

    if not type(root_img_dir) == list and path.isdir(root_img_dir):
        #import md5_unique_dup_files
        #duplicates = md5_unique_dup_files.find_duplicate_imgs(root_img_dir)[1]
        #[ os.remove(f) for f in duplicates if f ]
        imgs_renamed = [rename_retouched_file(f) for f in (glob.glob(path.join(root_img_dir,'*.??[gG]')))]
        img_dict = sort_files_by_values(glob.glob(path.join(root_img_dir,'*.??[gG]')))
        mz_converted_jpgs = []
        for k,v in img_dict.items():
            try:
                img = k
                ## Convert profile of source img if CMYK ignores if RGB
                convert_img_srgb.main(image_file=img)
                ## Get color pixel values from source img
                rgbmean     = v.items()
                ## Generate png from source then jpgs from png
                pngout = subproc_magick_png(img, rgbmean=dict(rgbmean), destdir=destdir)

                ## TODO: pngout will be the image to POST to mozu returned from mozu
                #  ie. response = send_to_mozu(pngout)  then save response in postgres --> and push the id to mozu again

                ##############################################
                ## Make Jpegs and collect Finals in mozu loading dir
                #######
                from os import path # chdir , curdir
                import datetime #, glob, shutil

                todaysdatefullsecs = '{:%Y%m%d%H%M%S}'.format(datetime.datetime.now())
                todaysdatefull = todaysdatefullsecs[:12]
                todaysdate = todaysdatefull[:8]  # '{:%Y,%m,%d}'.format(datetime.datetime.now())

                # Define for Creating Archive dirs
                archive = '/mnt/Post_Complete/Complete_Archive/Uploaded'
                # archive_uploaded = path.join(archive, "dateloaded_" + str(todaysdate).replace(",", ""), "uploaded_" + str(todaysdatefullsecs).replace(",", ""))
                archive_uploaded_day = path.join(archive, "dateloaded_" + str(todaysdate).replace(",", ""))
                imgdest_jpg_mozu = path.join(archive_uploaded_day, 'JPG_MOZU_LOAD')

                #chdir('/usr/local/batchRunScripts/mozu')
                import mozu_exec, mozu_image_util_functions
                ## Compress and convert to jpg and store in separate dir for concurrent xfers
                #if path.isfile(pngout):
                try:
                    print ' Is file PNGOUT', pngout, img
                    jpgout = mozu_image_util_functions.magick_convert_to_jpeg(pngout,destdir=imgdest_jpg_mozu)
                except IOError:
                    jpgout = mozu_image_util_functions.magick_convert_to_jpeg(img,destdir=imgdest_jpg_mozu)
                    pass

                # Try and make a list without needing globbing below
                mz_converted_jpgs.append(jpgout)
                ###########################################
                # from mozu import mozu_exec
                # mz_res = mozu_exec.main(pngout)
                # print mz_res, ' <-- MOZU-Done'
                subproc_magick_large_jpg(pngout, destdir=destdir)
                subproc_magick_medium_jpg(pngout, destdir=destdir)
            except AttributeError:
                print 'SOMETHING IS WRONG WITH THE IMAGE Error {}'.format(img)
                pass
            finally:
                return mz_converted_jpgs
    else:
        'Image is ', root_img_dir
        img = root_img_dir
        if regex_coded.findall(img):
            img = rename_retouched_file(img)
        pngout = subproc_magick_png(img, destdir=destdir)
        #from mozu import mozu_exec as mozu_exec
        #mz_res = mozu_exec.main(pngout)
        #print mz_res, ' <-- MOZU-Done'
        subproc_magick_large_jpg(pngout, destdir=destdir)
        subproc_magick_medium_jpg(pngout, destdir=destdir)
        return pngout