o k` @sddlZddlZddlZddlZddlTddlmZddlmZm Z m Z ej dZ dZdZdZGd d d eZGd d d eZGd ddeZGdddeZGdddeZddZGdddeZdddZ  dddZdS)N)*)levenshtein_distance)_get_negotiated_locale has_babelLANGz%Y-%m-%dz%Y-%m-%d %H:%M:%Sz YYYY-MM-DDc@s eZdZdZddZddZdS)IAdminPanelProviderz_Extension point interface for adding panels to the web-based administration interface. cCdS)zReturn a list of available admin panels. The items returned by this function must be tuples of the form `(category, category_label, page, page_label)`. N)reqr r 0/usr/lib/python3/dist-packages/trac/admin/api.pyget_admin_panels$z$IAdminPanelProvider.get_admin_panelscCr )zProcess a request for an admin panel. This function should return a tuple of the form `(template, data)`, where `template` is the name of the template to use and `data` is the data to use when rendering the template. Nr )r categorypage path_infor r r render_admin_panel+rz&IAdminPanelProvider.render_admin_panelN)__name__ __module__ __qualname____doc__r rr r r r rs rc@seZdZdZdddZdS)AdminCommandErrorz:Exception raised when an admin command cannot be executed.FNcCst||||_||_dSN) TracError__init__ show_usagecmd)selfmsgrrr r r r6s  zAdminCommandError.__init__)FN)rrrrrr r r r r4src@eZdZdZddZdS)IAdminCommandProviderzlExtension point interface for adding commands to the console administration interface `trac-admin`. cCr )aReturn a list of available admin commands. The items returned by this function must be tuples of the form `(command, args, help, complete, execute)`, where `command` contains the space-separated command and sub-command names, `args` is a string describing the command arguments and `help` is the help text. The first paragraph of the help text is taken as a short help, shown in the list of commands. `complete` is called to auto-complete the command arguments, with the current list of arguments as its only argument. It should return a list of relevant values for the last argument in the list. `execute` is called to execute the command, with the command arguments passed as positional arguments. Nr r r r r get_admin_commandsArz(IAdminCommandProvider.get_admin_commandsN)rrrrr!r r r r r <s r c@s@eZdZdZeeZgfddZd ddZddZ dd d Z d S)AdminCommandManagerztrac-admin command manager.cCs`g}|jD]$}|p gD]}|d}|dt||kr(||ddq q||S)z.Return help information for a set of commands.rN) providersr!splitlenappendsort)rargscommandsproviderrpartsr r r get_command_helpYs  z$AdminCommandManager.get_command_helpFcCsg}|jD]]}|p gD]T}|d}tt|t|d}|d||d|kr-q t|t|krA||t|dq |sa|ddurOgS|d|t|dp\gSq q|S)z/Perform auto-completion on the given arguments.rNr#)r$r!r%minr&r')rr)cmd_onlycompr+rr,plenr r r complete_commandds     $ z$AdminCommandManager.complete_commandc Gst|}|jD]f}|pgD]]}|d}|dt||krl|d}|t|d}z ||WStyI}zd||_d}~wtykt t d}t|dkrjtt ddd|d wqqtt d dd ) z/Execute a command given by a list of arguments.rN r.zInvalid argumentsT)rrzCommand not found)r)listr$r!r%r&rjoinr TypeError traceback extract_tbsysexc_infor) rr)r+rr,ffargsetbr r r execute_commandus2     z#AdminCommandManager.execute_commandcs|sgSt}|jD]}|pgD] }||ddqq ddtfdd|D}dd|D}|d|S)NrcSs,||rdSt||tt|t|S)Nr) startswithrfloatr&)rargr r r scores z7AdminCommandManager.get_similar_commands..scorec3s|] }||fVqdSrr ).0rrFrGr r sz;AdminCommandManager.get_similar_commands..cSsg|] \}}|dkr|qS)g?r )rHvalrr r r sz.)setr$r!addr%sorted)rrFncmdsr+rsimilarsr rIr get_similar_commandss  z(AdminCommandManager.get_similar_commandsNF)rC) rrrrExtensionPointr r$r-r3rBrSr r r r r"Ts  r"c@r) PrefixListz8A list of prefixes for command argument auto-completion.cstfdd|DS)Ncsh|] }|r|qSr )rDrHatextr r z&PrefixList.complete..)r7)rrZr rYr completeszPrefixList.completeNrrrrr]r r r r rV rVcCstj|tj|Sr)ospathnormcaserD)raprefixr r r path_startswithsrdc@r)PathListz5A list of paths for command argument auto-completion.csFtfdd|D}t|dkr!tj|ds!|dd7<|S)z+Return the items in the list matching text.csh|] }t|r|qSr )rdrWrYr r r[r\z$PathList.complete..r.rr5)r7r&r`raisdir)rrZmatchesr rYr r]szPathList.completeNr^r r r r rer_reFc Cstj|}tjt|}t}zt|}Wn ty$|YSw|D]0}tjtj||}ztj |rF| tj|dn|sM| |Wq'tyWYq'w|S)zYReturn a list of paths to filesystem entries in the same directory as the given path.) r`radirnamer8getcwdrelistdirOSErrornormpathrfr')ra dirs_onlydnamedresultdlistentryr r r get_dir_lists(     rtLANGUAGELC_ALL LC_MESSAGESrcstr[ddlm}mfdd}|g}|D]}tj|}|s q|dkr/d|vr/|dd}||q|rA||j ddt t d t ||}zt |WS|yZYd Swd S) z\Return negotiated locale for console by locale environments and [trac] default_language.r)UnknownLocaleError parse_localecs,|sdSz dtd|WSYdS)Nr)r8filter)valuerzr r normalizes z%get_console_locale..normalizerv:tracdefault_languageN)r babel.coreryrzr`environgetr%r'configr7r{mapr)envlang categoriesryr~localesrr|r r}r get_console_locales*     rrT)NNru)r`os.pathr<r: trac.coretrac.util.textrtrac.util.translationrrrrrrconsole_date_formatconsole_datetime_formatconsole_date_format_hint Interfacerrrr Componentr"r7rVrdrertrr r r r s,   J