B Fë]éEã @s<ddlZddlmZmZddlZddlZddlZddlZddlZddl m Z ddl Z ddl m Z ddlZyddlmZmZdZWneefk rœdZYnXddlTddlTddlTddlTddlTdd lmZeƒZeejƒdd d „Zejfd d„Z ejfdd„Z!dd„Z"ddd„Z#ddd„Z$d dd„Z%d!dd„Z&dS)"éN)ÚKeyÚAttr)ÚMP3)Úsleep)ÚLEDÚButtonFT)Ú*)Ú Configurationú/tmpcCsXt d¡}tj |¡}|r8| d|¡|rTt|dn| d|¡tj|dddS)Nzcerebro_utils.setup_dirszthe dir exists: %s)Ú image_dirzthe dir doesn't exist: %siÿ)ÚmodeT)ÚloggingÚ getLoggerÚosÚpathÚexistsÚinfoÚdelete_local_filesÚmakedirs)Z dir_to_createZ clean_modeZsetup_dirs_loggerZdoes_dir_exist©rúZ/Users/sacholla/WorkDocs/My Projects/codecommit/project-cerebro/py_client/cerebro_utils.pyÚ setup_dirs6s   rcCsft d¡}| d¡| |¡t d|¡}| d¡| |¡x|D]}t |¡qFW| d¡dS)Nzcerebro_utils.delete_mediaz*Entered the delete local files handler ...z%s/*zFiles listing to be deleted ...zall files deleted now)r rrÚglobrÚremove)r Zdelete_media_loggerÚfilesÚfilerrrrGs       rcCs´t d¡}d}| d¡| |¡d}t d||f¡}| d¡| |¡t|ƒdkrb| d¡tj |d ¡  d ¡d }| d |¡|  |¡d}| d |¡| d ¡|S)Nz!cerebro_utils.get_current_profileÚz+Entered the get_current_profile handler ...Zprofile_z %s/%s*.jpgz Files listing to be analyzed ...éz+Warning, More than one profile image found!rz.jpgzProfile File: %szProfile Name determined is: %szProfile retrieved now) r rrrÚlenÚwarningrrÚbasenameÚsplit)r Zget_current_profile_loggerÚ profile_nameZ profile_stemrZprofile_name_filerrrÚget_current_profileUs         r#cCsPt d¡}| d¡| d¡d}dtj}tjd||fdd}| d ¡dS) Nzcerebro_utils.show_no_imagesz$Entered the switch_images method ...z,And now, starting up the slideshow again ...z ../scripts/stop-picture-frame.shz%s/picframe.stop.logz%s > %s 2>&1 &T)Úshellz#Stopping of images is now complete!)r rrÚconfigÚ__CEREBRO_LOGS_DIR__Ú subprocessÚcall)Zshow_no_images_loggerZslideshow_stop_utilZslideshow_stop_logÚstatusrrrÚshow_no_imagesks     r*rcCsÂt d¡}ts ttjƒ}| ¡d}t|dd}| d¡t |d| d¡dtj d f}| d ¡t |d | d ¡d }t|dd}| d¡t |d| d¡ts´|  ¡| d¡dS)Nz$cerebro_utils.process_accept_effectszLExcellent! Seems that you like this effect. Now, lets upload this selfie ...zlike_this_text.mp3)Ú speech_textÚfilenamez+Generated Audio now. Playing audio next ...)Ú file_pathzAudio played. Done!z %s/%s.jpgÚfiltered_image_effectszUploading the selfie now ...)Ú image_pathzSelfie was uploaded now!z'Selfie was uploaded with image effects!zuploaded_with_effects.mp3z7Completed the accept of the effects and uploaded. done!T) r rÚtest_environmentrr%Ú __GREEN_LED__ÚonÚgenerate_audiorÚ play_audioÚ__CEREBRO_MEDIA_DIR__Ú upload_imageÚoff)Ú selfie_moder/Ú device_idZprocess_accept_effects_loggerÚledÚ audio_promptÚspeech_file_pathÚprofile_promptrrrÚprocess_accept_effects}s,              r>cCsØt d¡}ts ttjƒ}| ¡d}t|dd}| d¡t |d| d¡dtj d f}| d ¡d }t|d d}| d¡t |d| d¡| d ¡t |d\}} | d|| f¡| d¡dtj df}| d¡ts”d| }|  dd¡} |   dd¡} t|| dd}| d¡t |d| d¡t ddd} dtj} tjd| | fdd } d!} d"tj} tjd#| tj | fdd } | d$¡ts¢| ¡i}d%|d&<tt|ƒƒ|d'<||d(<t|d)|d*dS)+Nz$cerebro_utils.process_accept_filterszTExcellent! Seems that You like this filter. Now, lets apply some effects to this ...zlets_apply_effects.mp3)r+r,z+Generated Audio now. Playing audio next ...)r-zAudio played. Done!z%s/%szfiltered_image.jpgz!Applying the image effect now ...z.Image effects now being applied to the selfie!Zeffects_now_being_appliedz2Now calling the image effects script inprocess ...)r/zTimage effects script inprocess completed. image effects file: %s , Chosen Effect: %sz&Finished with the image effect now ...z %s/%s.jpgr.zAAnd now, starting up the slideshow again if not in a test env ...z2You should now see the filters with %s effect ....ú Ú_Ú.rz.mp3F)Úenable_displayz!../scripts/stop-slideshow-only.shz%s/picframe.stop.logz%s > %s 2>&1 &T)r$z!../scripts/start-picture-frame.shz%s/picframe.start.logz%s "%s" > %s 2>&1 &z$Switching of images is now complete!Zeffects_appliedÚactionr8r/r)Úiot_msgÚdelayr9)r rr0rr%r1r2r3rr4r5Zapply_image_effectÚreplaceÚcontrol_displayr&r'r(r7ÚstrÚintÚsend_iot_message)r8r/r9Zprocess_accept_filters_loggerr:r;r<r=r.Zchosen_effect_textÚfnameÚslideshow_utilÚ slideshow_logr)Úsqs_msgrrrÚprocess_accept_filters sh                        rOcCsrt d¡}| d¡ts*ttjƒ}| ¡|r4d}nd}| d¡|sPd|}nd|}t|dd }| d ¡t |d | d ¡| d ¡| |¡|sö| d¡t |d| d¡d}t|dd }| d ¡t |d | d ¡tsò|  ¡nx| d¡d}t|dd }| d ¡t |d | d ¡| d¡t |d} | d| ¡d}t|dd }| d ¡t |d | d ¡| d¡| d¡ts&d}t|dd }| d ¡t |d | d ¡t ddd } d!tj} tjd"| | fd#d$} d%} d&tj} tjd'| tj| fd#d$} | d(¡ts4|  ¡i} d)| d*<tt|ƒƒ| d+<|| d,<|| d-<t| d.|d/d#S)0Nz$cerebro_utils.process_accept_picturezAEntered the process_accept_picture in the cerebroutils script ...ÚSelfiezProfile picturez %s 2>&1 &T)r$z!../scripts/start-picture-frame.shz%s/picframe.start.logz%s "%s" > %s 2>&1 &z$Switching of images is now complete!Zfilters_appliedrCr8r/r9r)rDrEr9)r rrr0rr%r1r2r3r4r6r7Zprocess_image_filterrGr&r'r(r5rHrIrJ)r8r/r9Zprocess_accept_picture_loggerr:Ú picture_textr;r<r=Zfiltered_imagerLrMr)rNrrrÚprocess_accept_pictureðs”                                         rRÚdefault_devicec Cs~t d¡}| d¡ts | ¡|r*d}nd}| d¡|rVd|}d| dd ¡} nd |}d | dd ¡} t|| d } | d ¡t| dd| d¡| d¡| |¡|s | d¡|sÐtƒ}|sÐd}tsÜ|  ¡| d¡t t j dt ƒtdƒt||d|d}| d|¡nZ| d¡ts8|  ¡| d¡t t j dt ƒtdƒt||d|d}| d|¡dS)Nz"cerebro_utils.process_choose_photoz?Entered the process_choose_photo in the cerebroutils script ...rPzProfile picturezrOrRrUrrrrÚs>       # P u