B °¤ï`™ã@sÊdZddlZddlmZddlZddlZddlZddlZe d¡Zejdœdd„Z e dœdd „Z d d „Z d d „Z dd„Zdd„ZedkrÆe ¡Ze edd…ddZeƒe ¡Ze dee›¡dS)zÐ SPECIAL THANKS to Heimo Stieg (https://github.com/coreGreenberet) for implementing the "aio_" examples as well as this script, which generates the contents of the "aio" directory for running asynchronously. éN)ÚdatetimeÚ)ÚreturncCstt t¡}|›dt ¡d›d}tj|tjddd|rpt ¡}| tj¡t  d¡}|  |¡t d¡  |¡|S) NZ_log__z%Y-%m-%d_%H-%M-%Sz.logz4%(asctime)s %(name)12s: %(levelname)8s > %(message)sz%Y-%m-%d %H:%M:%S)ÚfilenameÚlevelÚformatÚdatefmtz(%(name)12s: %(levelname)8s > %(message)sr) ÚloggingÚ getLoggerÚ__name__rÚnowÚ basicConfigÚDEBUGÚ StreamHandlerÚsetLevelÚ FormatterÚ setFormatterÚ addHandler)Úlog_file_prefixÚ print_consoleÚloggerZlog_fileÚconsoleÚ formatter©rús/private/var/folders/7j/8686xlfs15q3tgljmghtvg0r0000gn/T/pip-target-isidps9b/lib/python/meraki_v0/convert_to_aio.pyÚ create_loggers    rcCsltj tj ||¡¡s.ttj ||¡›dƒ‚d|krXtj |¡\}}tj |dd|¡Stj |d|¡SdS)zZhelper function to return the correct for a converted file based on the original file pathz is not a fileÚapiZaioN)ÚosÚpathÚisfileÚjoinÚ ValueErrorÚsplit)rrÚ_rrrÚ get_aio_path%s r$c Cs6t d|›¡d}t|dƒ}| ¡}WdQRX|S)z2reads the file into memory and returns it contentszReading NÚr)Ú_loggerÚinfoÚopenÚread)ÚfilepathÚcontentsÚfrrrÚ read_file2s  r-cCsâi}i}d|t d¡<d|t d¡<d|t d¡<d|t d¡<d |t d ¡<d |t d ¡<d |t d¡<d|t d¡<d|t d¡<d|t d¡<d|t d¡<d|t d¡<d|t d¡<d|t d¡<d|t d¡<||fS)z¶this function will compile all needed regex patterns for the conversion returns a tuple of dictionaries for the meraki/__init__.py file and all files under the api directory rzfrom \.legacy import \* zfrom ..config importzfrom \.config importzclass AsyncDashboardAPI:zclass DashboardAPI\(object\):z \1Async\2z(from \.api\..*import )(.*)z#\1, AIO_MAXIMUM_CONCURRENT_REQUESTSz(, SIMULATE_API_CALLS)zP\1, maximum_concurrent_requests=AIO_MAXIMUM_CONCURRENT_REQUESTSz(, simulate=SIMULATE_API_CALLS)zˆ\1 - maximum_concurrent_requests (integer): How many requests should be handled at the same time? Additional requests will be queuedz ( - simulate \(boolean\): .*)zF\1 maximum_concurrent_requests=maximum_concurrent_requestsz( {12}simulate=simulate,)z!self._session = AsyncRestSession(zself\._session = RestSession\(z \1 = Async\2z#(self\..*) = (.*\(self\._session\))z async def __aenter__(self): return self async def __aexit__(self, exc_type, exc, tb): await self._session.close() z $zsuper().__init__()z*super\([a-zA-Z0-9_]+, self\)\.__init__\(\)zclass Async\1:zclass ([a-zA-Z0-9]+)\(object\):z async def \1z def ([^_].*)zreturn await self._session.zreturn self\._session\.)ÚreÚcompile)ÚpatternInitFileÚpatternAPIFilerrrÚ compile_regex=s$ r2c Cs¦ttj ||¡ƒ}t d¡x>| ¡D]2\}}| ||¡\}}t d|j ›d|›d¡q&Wt d¡t ||ƒ}t |dƒ}|  |¡WdQRXt d|›d¡dS) NzStarting ConversionzApplied pattern ú z timeszFinished ConversionÚwzFile z saved) r-rrr r&r'ÚitemsÚsubnÚdebugÚpatternr$r(Úwrite) rrZ patternDictÚcontentÚpÚvÚcountZaioFiler,rrrÚ convert_filems    r>cCstj d¡st d¡tj d¡s,t d¡tƒ\}}tdd|ƒd}xDt d¡D]6}tj tj ||¡¡rR|dd…dkrRt|||ƒqRWdS)Nz meraki/aiozmeraki/aio/apiZmerakiz __init__.pyz meraki/apiéýÿÿÿz.py) rrÚexistsÚmakedirsr2r>Úlistdirrr )r0r1Z apifolderÚfilerrrÚmain~s      &rDÚ__main__r?T)rrz Script complete, total runtime )Ú__doc__Úcsvrrr r.ÚioÚLoggerr&rÚstrr$r-r2r>rDr r Ú start_timeÚ__file__Zend_timer'rrrrÚs&    0