o k`(@sddlmZddlZddlZddlZddlmZmZmZmZddl Z ddl m Z ddl m Z mZmZmZmZddlmZmZdgZdd Zd d Zd d ZdedeffddZdddZddZdS))globN) working_setDistributionNotFoundVersionConflict UnknownExtra) ComponentMeta)get_docget_module_metadataget_module_path get_pkginfo get_sources)exception_to_unicode to_unicodeload_componentscCs ||dur||dSdS)z@Enable the given plugin module if it wasn't disabled explicitly.N)is_component_enabledenable_component)envmoduler-/usr/lib/python3/dist-packages/trac/loader.py_enable_plugin!srcsdfdd }|S)z=Loader that loads any eggs on the search path and `sys.path`.Nc s(tt|\}}|D]}|tvr jd||jt|q fdd}|D] \}}|||q+dd}|rAt j |}t t dddD]E} jd | j| jjz| jd d Wnty|}z|| ||| WYd}~qLd}~wwt j t j | jj|krt| jqLdS) NzAdding plugin "%s" from "%s"csft|}t|trjd||dSt|tttfr%jd||dSjd|t|dddS)NSkipping "%s": %sT traceback) r isinstancerlogdebug ImportErrorrrerror)itemeuerrr _log_error4s   z1load_eggs.._load_eggs.._log_errorcSs<|jD]}tjD]}|j|jkr|j|krt|qqdS)z6Remove components for `entry_point` from the registry.N)attrsr _components __module__ module_name__name__ deregister) entry_pointnamecrrrderegister_componentsAs     z._load_eggs..deregister_componentscSs|jSN)r+)entryrrrLsz/load_eggs.._load_eggs..keyzLoading plugin "%s" from "%s"T)require)r find_plugins pkg_resources Environmentrrlocationadditemsospathnormcasesortediter_entry_pointsr+distload Exceptiondirnamerr') r search_path auto_enable distributionserrorsr?r#r r-r/entry_point_namer"r _load_eggs)sF         zload_eggs.._load_eggsr.r)rHrIrrGr load_eggs's/rJcCsddd}|S)zLoader that look for Python source files in the plugins directories, which simply get imported, thereby registering them with the component manager if they define any components. Nc Ss|D]v}ttj|d}|D]h}tj|dd}|jd||z |tjvr/t ||Wn=t t fyN}z|j d|t|WYd}~qd}~wttfym}z|j d|t|ddWYd}~qd}~ww||krwt||qqdS)Nz*.pyzLoading file plugin %s from %srz!Failed to load plugin from %s: %sTr)rr:r;joinbasenamerrsysmodulesimp load_sourcerrrr rA SystemExitr)rrCrDr; plugin_files plugin_file plugin_namer rrr_load_py_files`s8     z%load_py_files.._load_py_filesr.r)rVrrr load_py_files[s rWz trac.pluginscCs8|j}|g}|r|t|7}|D] }||||dqdS)z:Load all plugin components found on the given search path.)rDN) plugins_dirlist)r extra_pathloadersrXrCloadfuncrrrrxs Fc sifdd}|j}i}tjD]}tj|j}||}d}tjtj tj |j |kr6tj |j }|j |vrd} |rLt|j tjtjrLd} t|} |j} | rn| D]} | | dkrdd| | <qWt| | | | <qWnt|} | d} |j | |j || | id ||j <||j d } |j| vrt|\}}||id ||j d |j<|jd |j}t|\}}|}||vrt||js||}|||||t|d dd| |jd|j<q|st|D] }|dkr||qtt| dddS)zAReturn package information about Trac core and installed plugins.cs|j}t|}|}|durt|}|<||ddd}|dur2||ddd}|dur?tj|d|jd}|S)N./.pyz /__init__.py) project_nameversionr7)r(r getr replacer5 Distribution__file__)rr+r;sourcesr? path_sourcesrrfind_distributions z*get_plugin_info..find_distributionNTFUNKNOWNr`rb)r+rbr;plugin_filenamereadonlyinforOrO)summary description componentsr]required) full_namerorpenabledrrrqtraccSs|ddk|dfS)Nr+ru)lower)prrrr0s z!get_plugin_info..r1)!rXrr%rNrOr&r:r;r<realpathrBr7rMraaccessF_OKW_OKr rbrr r(r issubclass __class__rgetattrrYrvpopr=itervalues)r include_corerjrXplugins componentrr?rlrmrnrbkrOrorprsr,r+rrhrget_plugin_infosp                 rcsddt|Dfdd}|D]1}tj|ddd\}}|dkr,r,||qt|D]\}}|d |rA||d <nq0qd S) zAdd a `frame_idx` element to plugin information as returned by `get_plugin_info()`, containing the index of the highest frame in the list that was located in the plugin. cSs&g|]\}}|ddr||fqS)filenamezbuild/) startswith).0ifrrr s z+match_plugins_to_frames..c stj|dddD]<}z1|d}|D]%}|dr:|dd}D]\}}|d|r9||d <WdSq$qWq tyEYq wdS) Nr;T)onlyz SOURCES.txtr_\r^r frame_idx)r5find_distributions get_metadata splitlinesendswithrdKeyError)pluginr?rgsrcnsrcrr egg_framesrrfind_egg_frame_indexs&         z5match_plugins_to_frames..find_egg_frame_indexr;rr^z.eggrrN) enumerater:r;splitextrdr)rframesrrbaseextrrrrrmatch_plugins_to_framess   r)F)rrPos.pathr:r5rrrrrN trac.corer trac.utilrr r r r trac.util.textr r__all__rrJrWrrrrrrrs$  4 V