def main(root_img_dir=None): import sys,glob,shutil,os,re from image_processing.magick_tweaks 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) ## 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') import sys from os import chdir, path import sys,glob,shutil,os,re,datetime sys.path.append('/usr/local/batchRunScripts/python/jbmodules/image_processing/magick_tweaks') sys.path.append('/usr/local/batchRunScripts/mozu') sys.path.append('/usr/local/batchRunScripts/python') sys.path.append('/usr/local/batchRunScripts/python/jbmodules') sys.path.append('/usr/local/batchRunScripts/python/jbmodules/mongo_tools') sys.path.append('/usr/local/batchRunScripts/python/jbmodules/image_processing') sys.path.append('/usr/local/batchRunScripts/python/jbmodules/image_processing/marketplace') #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 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)
def main(root_img_dir=None): import sys,glob,shutil,os,re from image_processing.magick_tweaks 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') 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 = os.path.join(root_img_dir, 'output') try: os.makedirs(destdir, 16877) except OSError: pass if 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: 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(root_img_dir=None, destdir=None): import sys, glob, shutil, os, re from image_processing.magick_tweaks 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]")