def resume_handler(self, signum, frame): """Removes the pause flag so the main loop continues to execute tasks.""" logger.info("Resuming daemon") self.download_image_time = 0 self.paused = False system_status.set_current_job(JobEnum.IDLE)
def pause_handler(self, signum, frame): """Sets pause flag so that task execution in the main loop is paused.""" logger.info("Pausing daemon") self.paused = True system_status.set_current_job(JobEnum.PAUSE)
def download_dropbox_images(facade, sorted_images): """Downloads new/updated images and deletes local images that was not found on dropbox.""" if not sorted_images["to_download"] and not sorted_images["to_delete"]: logger.info(" + Database is in sync with Dropbox account") logger.info(">> Sync dropbox images aborted") system_status.set_current_job(JobEnum.IDLE) return time.time() for image in sorted_images["to_download"]: facade.download_image(image) dropbox_images.save_image(image) system_status.set_latest_sync() lazy_files.delete_dict_files(sorted_images["to_delete"], "path") dropbox_images.delete_images(sorted_images["to_delete"])
def sync_dropbox_images(): """Compares images on dropbox and locally to sync.""" logger.info("<< Sync dropbox images") system_status.set_current_job(JobEnum.SYNC) facade = DropboxAPIFacade(True) if facade.is_authorized() is False: logger.warning(" + No dropbox account connected when syncing images") logger.info(">> Sync dropbox images aborted") system_status.set_current_job(JobEnum.IDLE) return time.time() external_images = facade.get_appfolder_imagedata() local_images = dropbox_images.get_all_images() logger.info(" + Images found in dropbox account %d" % len(external_images)) logger.info(" + Images found locally %d" % len(local_images)) sorted_images = compare_images_to_sync(external_images, local_images) download_dropbox_images(facade, sorted_images) system_status.set_current_job(JobEnum.IDLE) logger.info(">> Sync dropbox images complete") return time.time()