def queue_handling_loop(self): any_download = False while True: if not is_alive(self.__host): time.sleep(WAIT_2) continue any_download = False if len(self.download_queue) > 0: self.rwl.acquire_read() logging.getLogger().debug( "QUEUE Lenght: " + str(len(self.download_queue))) elem = self.download_queue[0] img_name = get_image_name(elem) tick = timeit.default_timer() self.api.download_file(elem["Path"], os.path.join( self.__destination, img_name), skip_existing=True) tock = timeit.default_timer() logging.getLogger().info( "Image downloaded " + str(tock - tick)) self.rwl.promote() self.download_queue.remove(elem) self.cache[uniq_identifier(elem)] = elem self.rwl.demote() self.rwl.release() any_download = True if any_download: time.sleep(WAIT_3) else: time.sleep(WAIT_2)
logging.info("Download completed.") copy(temp_name, destination) os.remove(temp_name) except Exception as e: logging.getLogger().error(e) return {"Status": 0, "Result": e} return {"Status": 1, "Result": destination} @classmethod def get_root_directory(cls): return FLASH_AIR_ROOT if __name__ == "__main__": import sys logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) api = FACommandAPI() logging.getLogger().debug("api.host " + api.host) root_directories = api.get_directories() logging.getLogger().debug(root_directories) if root_directories["Status"]: for dir_obj in root_directories["Result"]: files = api.get_files(dir_obj["Path"]) if files["Status"] == 0: raise FACommandAPIException(files["Result"]) for file in files["Result"]: api.download_file(file["Path"], "/Users/mertsalik/Desktop/" + get_image_name(file)) break