def main(styles_list): from os import environ ##### Temp #### environ['IMGDIR'] = '/mnt/images' ## ************* ## imgnum = int(environ.get('IMGNUM', 0)) root_dir = environ.get('IMGDIR', '/mnt/Post_Complete/MozuRoot') ext = environ.get('IMGEXT','.png') ## Do for only 1 img number or load any that are found if imgnum > 0: flist = create_list_files_to_send(styles_list, imgnum=imgnum, ext=ext, root_dir=root_dir) else: flist = [] for x in range(1,7,1): li1 = create_list_files_to_send(styles_list, imgnum=x, ext=ext, root_dir=root_dir) [ flist.append(f) for f in li1 if f is not None ] #### ## Compile Actual Styles and Filename found and Ready to Send loaded_filenames = [f.split('/')[-1].split('.')[0] for f in flist if f is not None] loaded_styles = list(set(sorted([fn[:9] for fn in loaded_filenames if fn is not None]))) print 'loaded styles', loaded_styles ### Send Collected to Mozu import mozu_exec print('Starting.\nReloading {0} Images for {1} Styles from {2} to Mozu'.format(ext.lstrip('.').upper(), len(styles_list), root_dir)) mozu_exec.main(flist) print('Finished.\nReloaded {0} Images for {1} Styles\n{2} Total Files from {3} to Mozu'.format(ext.lstrip('.').upper(), len(loaded_styles), len(loaded_filenames),root_dir)) ## Set Media Version for Loaded Styles import media_version_ctrl media_version_ctrl.batch_process_by_style_list(loaded_styles) print('Finished.\nMedia Incr for {1} Styles from {2} to Mozu'.format(ext.lstrip('.').upper(), len(loaded_styles), root_dir)) ## Return File Path of Loaded Styles for further ops if needed return loaded_filenames
def batch_load_dated_mozu_jpg_cnvrt_png(**kwargs): ########## MOZU - Five ########## from os import path, renames # , curdir, chdir import datetime, glob # , shutil ## Define for Creating Archive dirs rootdir = kwargs.get('rootdir', '/mnt/Post_Complete/Complete_Archive/Uploaded') delta = kwargs.get('delta', '') if delta: days_ago = datetime.timedelta(days=int(delta)) todaysdatefullsecs = '{:%Y%m%d%H%M%S}'.format(datetime.datetime.now()-days_ago) print todaysdatefullsecs, ' <-- Deltaed' todaysdatefull = todaysdatefullsecs[:12] search_date = todaysdatefull[:8] # '{:%Y,%m,%d}'.format(datetime.datetime.now()) todaysdate_real = '{:%Y%m%d%H%M%S}'.format(datetime.datetime.now())[:8] else: todaysdatefullsecs = '{:%Y%m%d%H%M%S}'.format(datetime.datetime.now()) todaysdatefull = todaysdatefullsecs[:12] search_date = todaysdatefull[:8] # '{:%Y,%m,%d}'.format(datetime.datetime.now()) todaysdate_real = search_date search_dir = path.join(rootdir, "dateloaded_" + str(search_date)) currentdate_dir = path.join(rootdir, "dateloaded_" + str(todaysdate_real)) imgdest_jpg_mozu = path.join(currentdate_dir, 'JPG_MOZU_LOAD') imgdest_jpg_mozu_loaded = path.join(imgdest_jpg_mozu, 'LOADED') # For later pulling production pngs into the batch as well imgdest_png_stored = path.join(imgdest_jpg_mozu, 'LOADED') import mozu_exec #, mozu_image_util_functions ## Compress and convert to jpg and store in separate dir for concurrent xfers load_collect_batch_mozu_list = glob.glob(path.join(search_dir, '*/JPG_MOZU_LOAD/*.[Jjp][Ppn][gG]')) try: if load_collect_batch_mozu_list: for f in load_collect_batch_mozu_list: print '31-->', f, imgdest_jpg_mozu # rename(f, imgdest_jpg_mozu) renames(f, path.join(imgdest_jpg_mozu, path.basename(f))) except IndexError: print ' Index Error' load_batch_mozu_list = glob.glob(path.join(imgdest_jpg_mozu, '*.[Jjp][Ppn][gG]')) print imgdest_jpg_mozu, ' <-- DEST Mozu begin mozu exec' if len(load_batch_mozu_list) > 0: mozu_exec.main(load_batch_mozu_list) for f in load_batch_mozu_list: print '37-->', f, imgdest_jpg_mozu_loaded try: renames(f, path.join(imgdest_jpg_mozu_loaded, path.basename(f))) except OSError: print 'OS ERROR 45 ', f, imgdest_jpg_mozu_loaded, imgdest_jpg_mozu load_batch_mozu_done = glob.glob(path.join(imgdest_jpg_mozu_loaded, '*.[Jj][Pp][gG]')) # Store the pngs store_png_list = [ renames(f, path.join(imgdest_png_stored, path.basename(f))) for f in glob.glob(path.join(imgdest_jpg_mozu, '*.[Pp][Nn][gG]')) if f is not None] return load_batch_mozu_done else: print imgdest_jpg_mozu, ' <-- DEST Mozu \n<---- ZERO FILES to Process'