o k`*@sddlZddlZddlZddlTddlmZddlTddlmZddl m Z ddl m Z m Z ddlmZmZddlmZmZmZmZmZmZdd lmZGd d d eZdS) N)*)IEnvironmentSetupParticipant)model) WikiSystem)lazy read_file)format_datetimefrom_utimestamp)path_to_unicode print_tableprintout to_unicode unicode_quoteunicode_unquote)_c@seZdZdZeeeddZeddZ d4ddZ d d Z gd fd d Z ggd fddZ ddZddZddZddZddZddZddZd4ddZd4d d!Zd"d#Zd$d%Zd&d'Zd(d)Zd5d*d+Zd,d-Zd.d/Zd0d1Zd2d3ZdS)6 WikiAdminz4trac-admin command provider for wiki administration.ccsdddd|jfVddd|j|jfVddd |j|jfVd d d |j|jfVd d d|j|jfVddd|j|jfVddd|j |j fVddd|j |j fVdddd|j fVdS)Nz wiki listzList wiki pagesz wiki renamez zRename wiki pagez wiki removezzRemove wiki pagez wiki exportz [file]z"Export wiki page to file or stdoutz wiki importz#Import wiki page from file or stdinz wiki dumpz [page] [...]a8Export wiki pages to files named by title Individual wiki page names can be specified after the directory. A name ending with a * means that all wiki pages starting with that prefix should be dumped. If no name is specified, all wiki pages are dumped.z wiki loadz [...]zImport wiki pages from files If a given path is a file, it is imported as a page with the name of the file. If a path is a directory, all files in that directory are imported.z wiki replaceaReplace content of wiki pages from files (DANGEROUS!) This command replaces the content of the last version of one or more wiki pages with new content. The previous content is lost, and no new entry is created in the page history. The metadata of the page (time, author) is not changed either. If a given path is a file, it is imported as a page with the name of the file. If a path is a directory, all files in that directory are imported. WARNING: This operation results in the loss of the previous content and cannot be undone. It may be advisable to backup the current content using "wiki dump" beforehand.z wiki upgradez-Upgrade default wiki pages to current version) _do_list_complete_page _do_rename _do_remove_complete_import_export _do_export _do_import_complete_dump_do_dump_complete_load_replace_do_load _do_replace _do_upgradeselfr"1/usr/lib/python3/dist-packages/trac/wiki/admin.pyget_admin_commands%sJ zWikiAdmin.get_admin_commandscCs tddS)Nz trac.wikiz default-pages) pkg_resourcesresource_filenamer r"r"r#default_pages_dirXs zWikiAdmin.default_pages_dirNcCstt|j|SN)sortedrenv get_pages)r!prefixr"r"r# get_wiki_list\szWikiAdmin.get_wiki_listcCst|j|}|jrC|st|jdStj|r#t t dt |dt |ddd}| |jWddS1stitle create_onlyrDdatar/r4er"r"r# import_pagems4      zWikiAdmin.import_pagecCsg}|jj9tt|D](}||vrqtj||}tj|r6t| d}| ||||r6| |qWd|S1sBwY|S)Nr1) r*db_transactionr)r8listdirr9joinr:rrHrQappend)r!dirignorerNrDloadedr4r>r"r"r# load_pagess       zWikiAdmin.load_pagescCst|dkr |SdS)N)lenr-r!argsr"r"r#rs zWikiAdmin._complete_pagecCs0t|dkr |St|dkrt|dSdS)NrZ)r[r- get_dir_listr\r"r"r#rs   z!WikiAdmin._complete_import_exportcCs4t|dkrt|dddSt|dkr|SdS)NrZr_T) dirs_onlyr^)r[r`r-r\r"r"r#rs  zWikiAdmin._complete_dumpcCst|dkr t|dSdS)NrZr_)r[r`r\r"r"r#rs  z WikiAdmin._complete_load_replacecCs2tdd|jdDtdtdtdgdS)NcSs*g|]\}}}|t|tt|tfqSr")intrr console_datetime_format).0rMeditsmodifiedr"r"r# s  z&WikiAdmin._do_list..zs SELECT name, max(version), max(time) FROM wiki GROUP BY name ORDER BY nameTitleEditsModified)r r*db_queryrr r"r"r#rs  zWikiAdmin._do_listc CsVt|j|}z||Wnty}zt||d}~wwttd||ddS)Nz# '%(name1)s' renamed to '%(name2)s')name1name2)rr5r*renamerLr;r r)r!r/new_namer4rPr"r"r#rs  zWikiAdmin._do_renamecCs|jjQ|dr2||dpd}|D] }t|j|}|qtdd|Dt dgnt|j|}|t t d|dWddSWddS1sXwYdS)Nrcss|]}|fVqdSr(r")rdpr"r"r# sz'WikiAdmin._do_remove..z Deleted pagesz '%(page)s' deletedr3) r*rRendswithr-rstriprr5deleter rr )r!r/pagesrpr4r"r"r#rs   "zWikiAdmin._do_removecCs(||||rtd||fdSdS)N '%s' => '%s')rAr r!r4r>r"r"r#rs zWikiAdmin._do_exportcCs|||dSr()_importrwr"r"r#rszWikiAdmin._do_importcs|sdg}|}tj|s%tj|st|n ttdt|d|D]%t fdd|DrLtj |t d}t d|f| |q'dS)Nrz'%(name)s' is not a directoryr.c3s4|]}|kp|do|ddVqdS)rNr_)rr startswith)rdr/rpr"r#rqs  z%WikiAdmin._do_dump..rrv)r-r8r9isdirr6mkdirr;rr anyrTrr rA)r! directorynamesrudstr"rzr#rs$     zWikiAdmin._do_dumpcG|j|dddS)NFrC_load_or_replacer!pathsr"r"r#rzWikiAdmin._do_loadcGr)NTrCrrr"r"r#rrzWikiAdmin._do_replacecCs0|j|jddgdgd}ttdt|ddS)N WikiStartSandBox InterMapTxt)rWrNz'Upgrade done: %(count)s pages upgraded.)count)rYr'r rr[)r!rr"r"r#rs zWikiAdmin._do_upgradecCs<|j|||drtdt||fdSttd|ddS)NrCrvz" '%(title)s' is already up to date)rM)rQr r r)r!r>rMrDr"r"r#rxszWikiAdmin._importcCs|jj@|D]4}tj|r.tt|D]}tj||}tj|r,| |||qqtj |}| |||qWddS1sGwYdSr() r*rRr8r9r{r)rSrTr:rxbasename)r!rrDr9r4r>r"r"r#rs    "zWikiAdmin._load_or_replacecCst|jd|jj&||jD]}|dvr't|j|}d|_| ddqWddS1s3wYdS)z3Add default wiki pages when environment is created.zInstalling default wiki pages)rrrrZN) rIrJr*rRrYr'rr5readonlyrK)r!r/r4r"r"r#environment_createds   "zWikiAdmin.environment_createdcCdSr(r"r r"r"r#environment_needs_upgradez#WikiAdmin.environment_needs_upgradecCrr(r"r r"r"r#upgrade_environmentrzWikiAdmin.upgrade_environmentr()F) __name__ __module__ __qualname____doc__ implementsIAdminCommandProviderrr$rr'r-rArQrYrrrrrrrrrrrrrrxrrrrr"r"r"r#rs8 3       r)r8r%rE trac.admintrac.apir trac.core trac.wikir trac.wiki.apir trac.utilrrtrac.util.datefmtrr trac.util.textr r r r rrtrac.util.translationr Componentrr"r"r"r#s