o k`I@sddlZddlZddlZddlZddlZddlZddlZddlZddlmZzddl Z Wn e y7dZ Ynwddl m Z ddlmZmZmZddlmZddlmZddlmZddlmZdd lmZdd lmZmZmZm Z m!Z!m"Z"m#Z#dd l$m%Z%m&Z&m'Z'm(Z(dd l)m*Z*dd l+m,Z,Gdddej-Z.Gddde,Z/ddZ0ddZ1dddZ2e3dkre4de e5e2dSdS)N)shlex) __version__)AdminCommandErrorAdminCommandManagerget_console_locale) Configuration) TracError) Environment) translation)html) console_printexception_to_unicodegetpreferredencodingprinterrprintout raw_input to_unicode)_ cleandoc_ has_babelngettext) MacroError) WikiMacroBasec@s2eZdZdZddeiZdZdZdZdZ dZ d:ddZ dd Z d d Z d d Zd:ddZddZeddZddZeddZddZddZeddZed;dd Zd NcCs\tj|trt}dD]}||d}qt|d|_|r,|t j |dSdS)Nz-/:()\rF) cmdCmd__init__readlineget_completer_delimsreplaceset_completer_delims interactiveenv_setospathabspath)selfenvdirdelimscr,4/usr/lib/python3/dist-packages/trac/admin/console.pyr8s  zTracAdmin.__init__cCsdSNr,r(r,r,r- emptylineCszTracAdmin.emptylinec CsXt|tr|jr tjj}nt}t||}|jr|dd}z t j ||p'd}Wn{t y1t ya}z%ttdt|d|jrUt||j pS||dd}WYd}~nHd}~wtyz}ztt|d}WYd}~n/d}~wty}ztt|d}|r|jjd|t|d d WYd}~nd}~ww|js|SdS) z)`line` may be a `bytes` or a `str` object\z\\rzError: %(msg)smsgNz%Exception in trac-admin command: %r%sT traceback) isinstancebytesr#sysstdinencodingrrr!rronecmd SystemExitrrr show_usageprintdo_help arg_tokenizerr Exception env_checkenvlogerror)r(liner;rver,r,r-r<FsF         zTracAdmin.onecmdcCs$d|_ttdtdd|dS)NTzWelcome to trac-admin %(version)s Interactive Trac administration console. Copyright (C) %(year)s Edgewall Software Type: '?' or 'help' for help on commands. z 2003-2021)ryear)r#rr TRAC_VERSIONcmdloopr/r,r,r-rungs  z TracAdmin.runcCs(||_d|j|_|dur||_dSdS)Nz Trac [%s]> )envnameprompt_TracAdmin__env)r(rNrDr,r,r-r$ss   zTracAdmin.env_setcCs.|jsz|WdStyYdSwdS)NFT)rP _init_envrBr/r,r,r-rCys  zTracAdmin.env_checkc Csh|js1z|W|jSty0}zttdt|dddtdWYd}~|jSd}~ww|jS)Nz#Failed to open environment: %(err)sTr5err)rPrQrBrrr r9exit)r(rIr,r,r-rDs  z TracAdmin.envcCs6t|j|_}trt|}|rt|dSdSdSr.)r rNrPrrr activate)r(rD negotiatedr,r,r-rQszTracAdmin._init_envcCs t|jSr.)rrDr/r,r,r-cmd_mgrs zTracAdmin.cmd_mgrcCs6t|dd}d|_d|_tjdkrd|_t|pdgS)NT)posixrnt)rwhitespace_split commentersr%nameescapelist)r(argstrlexr,r,r-rAs  zTracAdmin.arg_tokenizecs6tfdd|D}t|dkr|dd7<|S)Ncsh|] }|r|qSr, startswith).0atextr,r- sz*TracAdmin.word_complete..rTr )r_len)r(rgwordsr,rfr- word_completes zTracAdmin.word_completecCstd|}dd|DS)Nz(?m)(?:^[ \t]*\n)+cSsg|] }tdd|qS)z(?m)\s+ri)resubstrip)rdeachr,r,r- sz-TracAdmin.split_help_text..)rmsplit)rg paragraphsr,r,r-split_help_texts zTracAdmin.split_help_textFc Cs|durtj}dd|D}|sdS|r:tdd|D}|D]\}}}||} t|d||| dfqdS|D]A\}}}||} t|d||ft|d| d|s`t|d kr}t| d kr}| d dD]} t|tj| d d d d d qlq.css|] }t|dVqdS)rN)rjrur,r,r- sz&TracAdmin.print_doc..z%s %srz%s %s z %s rTO )initial_indentsubsequent_indent ) r9stdoutmaxrtr ljustrjtextwrapfill) clsdocsstreamshortlongmax_lenrargsrvrs paragraphr,r,r- print_docs:   zTracAdmin.print_docc Cs||}|r|ddkr|dg}|rMz |j||}Wn+tyL}ztttdt|d|j j dt|ddWYd}~nd}~wwt |d kr_| d d |Dz||WStyt|||YSw) NrirzCompletion error: %(err)srRztrac-admin completion error: %sTr5rTcss&|]}|dr|ddVqdS)do_Nrb)rdr]r,r,r-rwsz*TracAdmin.complete_line..)rAappendrCrXcomplete_commandrBrrr rDrErFrjextend get_namescompleteAttributeErrorrl)r(rgrGcmd_onlyrcomprIr,r,r- complete_lines0       zTracAdmin.complete_linecCs|||dS)NTrr(rgrGbegidxendidxr,r,r- completenameszTracAdmin.completenamescCs |||Sr.rrr,r,r-completedefaults zTracAdmin.completedefaultc Csz|js||jdur|j|_Wn%ty'}ztt||d}~wty9}ztt||d}~ww||}|ddkrId|_n |jrUtt d|j d|j j |S)NrupgradezPThe Trac Environment needs to be upgraded. Run: trac-admin "%(path)s" upgrader&) rPrQ needs_upgraderrrrBr rArrNrXexecute_command)r(rGrIrr,r,r-defaults*     zTracAdmin.default)helprzShow documentationcCs*|j|j}|dur|t||Sr.) _help_help _help_initenvrrget_command_help)rrDrr,r,r-all_docss zTracAdmin.all_docscCs|||dddS)NTrrr,r,r- complete_helpszTracAdmin.complete_helpcCs$||}|drcd}t|d|dd}|dur%|r%|j}||}|r.||dSttdd|dd}|rD| |d}|r_t dt t ddt ||D] }t d |qVdSdSt td t d |js}tt td t td |r|jnd}|j||dddS)Nr_help_zMNo documentation found for '%(cmd)s'. Use 'help' to see the list of commands.ri)rrzDid you mean this?zDid you mean one of these?ryz8trac-admin - The Trac Administration Console %(version)s)rzIUsage: trac-admin [command [subcommand] [option ...]] z=Invoking trac-admin without command starts interactive mode. T)r)rAgetattrrCrXrrrrjoinget_similar_commandsrrrjrKr#r?rDr)r(rGargrXrvcmdsrrDr,r,r-r@sD    zTracAdmin.do_help)quitrzExit the programcCsttdSr.)r?r9rUr(rGr,r,r-do_quit0s zTracAdmin.do_quit)initenvz[ ]aCreate and initialize a new environment If no arguments are given, then the required parameters are requested interactively unless the optional argument `--config` is specified. One or more optional arguments --inherit=PATH can be used to specify the "[inherit] file" option at environment creation time, so that only the options not already specified in one of the global configuration files are written to the conf/trac.ini file of the newly created environment. Relative paths are resolved relative to the "conf" directory of the new environment. The optional argument --config=PATH can be used to specify a configuration file that is used to populate the environment configuration. The arguments , and any other arguments passed in the invocation are optional, but if specified will override values in the configuration file. cCs||dSr.) do_initenvrr,r,r- do_initdbMrzTracAdmin.do_initdbcCsng}ttdd}|ttd|dp|ttdd}td|d}|t|p0|t|S)Nz Trac will first ask a few questions about your environment in order to initialize and prepare the project database. Please enter the name of your project. This name will be used in page titles and descriptions. z My ProjectzProject Name [%(default)s]> )ra Please specify the connection string for the database. By default, a local SQLite database is created in the environment directory. It is also possible to use an existing MySQL or PostgreSQL database (check the Trac documentation for the connection string syntax). zsqlite:db/trac.dbz*Database connection string [%(default)s]> )rrrrror?)r( returnvalsdpddbrOr,r,r-get_initenv_argsPs     zTracAdmin.get_initenv_argsc sfdd}r|tddSttdjd|}g}d}d}d}|t|kri||}|d rD|||d dn|d rS||d d}n|d kr_||d}n|d7}|t|ks.d} |rt j |s}|td|ddSzt |} Wnt y} z || WYd} ~ dSd} ~ ww|pdg}t|dkr|ds| s\} } n*t|dkr| rd} } |dr|d} nt|dkr|\} } n |dt|dSg} | r| jddD]| fdd| Dq| dur| dd| f| dur| dd| f|r!| ddd|fz tjd| |d_Wn=t yE} z || WYd} ~ dSd} ~ wtyj} z|tdt| ttdWYd} ~ nd} ~ wwttd | jt j jjjd!dS)"Ncsttdjdd|dS)NzInitenv for '%(env)s' failed.)rDz %s)rrrNr2r/r,r- initenv_errorisz+TracAdmin.do_initenv..initenv_errorz"Does an environment already exist?r4z.Creating a new Trac environment at %(envname)s)rNTrz --inherit= z --config= z--no-default-dataFrTzEThe file specified in the --config argument does not exist: %(path)s.rrzWrong number of arguments: %d)defaultsc3s|] \}}||fVqdSr.r,)rdoptionvalue)sectionr,r-rwsz'TracAdmin.do_initenv..projectr]tracdatabaseinheritfilez, )createoptions default_datazFailed to create environment.a Project environment for '%(project_name)s' created. You may configure the environment by editing the file: %(config_path)s You can run the Trac standalone web server `tracd` and point your browser to http://localhost:8000/%(project_dir)s. tracd --port 8000 %(project_path)s Navigate to "Help/Guide" to browse the documentation for Trac, including information on further setup (such as deploying Trac to a real web server). The latest documentation can also be found on the project website: https://trac.edgewall.org/ ) project_name project_path project_dir config_path)rCrrrNrArjrcrpopr%r&existsrrrsectionsrrrr rPrBrr6 print_excr9rUbasenameconfig_file_path)r(rGrr inherit_pathsrriitemconfigrIrdb_strrr,)rr(r-rhs                     zTracAdmin.do_initenvr.)NFF)F)-__name__ __module__ __qualname__introrK doc_headerrulerrOrNrPrrr0r<rMr$rCpropertyrDrQrXrArl staticmethodrt classmethodrrrrrrrrr@ _help_quit _help_exit _help_EOFrdo_exitdo_EOFrrrrr,r,r,r-r-s^  !         % rc@s"eZdZdZedZdddZdS)TracAdminHelpMacromessagesa3 Display help for trac-admin commands. Examples: {{{ [[TracAdminHelp]] # all commands [[TracAdminHelp(wiki)]] # all wiki commands [[TracAdminHelp(wiki export)]] # the "wiki export" command [[TracAdminHelp(upgrade)]] # the upgrade command }}} Nc Cs|r+|}ttd|dd}|dur t|j}||}|s*ttd|dnt |j}t }tj ||ddt j|ddS) Nrrz(Unknown trac-admin command "%(command)s")commandT)rwiki)class_)rorrrrrrDrrrrioStringIOrr pregetvalue) r( formatterr]contentrrrvrXbufr,r,r- expand_macros    zTracAdminHelpMacro.expand_macror.)rrr_domainr _descriptionrr,r,r,r-rs rcsddfdd|DS)NcSs&|r|Sddd|dDS)Nz"'"css|]}d|VqdS)z'%s'Nr,)rdvr,r,r-rwsz-_quote_args..quote..')isalnumrrr)rr,r,r-quotesz_quote_args..quotecsg|]}|qSr,r,)rdrrr,r-rqsz_quote_args..r,rr,rr- _quote_argssrc Cs|dur tjdd}t}|rq|ddvr'|dtdg|ddS|ddvr;ttj tjdt dS| tj |dt |dkrZ|dt|ddS z|Wntyo|dYnwq[|dS) NrTr)z-hz--helprrir)z-vz --versionTr)r9argvrr<rrrr%r&rrKr$r'rjrMKeyboardInterruptr)radminr,r,r-_runs& "     rcCs*ttz t|WtStw)zMain entry point.)r rVrr deactivaterr,r,r-rMs rM__main__zTrac==%sr.)6rrr% pkg_resourcesrmr9rr6rr ImportErrorrrrKtrac.admin.apirrr trac.configr trac.corertrac.envr trac.utilr trac.util.htmlr trac.util.textr r rrrrrtrac.util.translationrrrrtrac.wiki.formatterrtrac.wiki.macrosrrrrrrrMrrequirerUr,r,r,r-sJ         $  &