o k`L@sddlZddlZddlmZmZddlmZddlm Z ddl Tddl m Z ddl mZmZddlmZdd lmZmZmZmZmZdd lmZmZmZdd lmZmZmZm Z m!Z!dd l"m#Z#m$Z$m%Z%Gd dde&Z'Gddde&Z(dS)N)IAdminCommandProviderIAdminPanelProvider)IEnvironmentSetupParticipant) ListOption)*)IPermissionRequestor)as_bool is_path_below)tag)breakable_pathnormalize_whitespace print_tableprinterrprintout)_ngettexttag_)DbRepositoryProviderInvalidRepositoryNoSuchChangesetRepositoryManager is_default)Chrome add_notice add_warningc@seZdZdZeeeeddZddZ ddZ dd Z d d Z d d Z ddZddZdddZdddZddZddZddZddZdS) VersionControlAdminz?trac-admin command provider for version control administration.ccshddd|j|jfVddd|j|jfVdddd|jfVd d d |j|jfVd d d |j|jfVdS)Nzchangeset addedz [rev] [...]zNotify trac about changesets added to a repository This command should be called from a post-commit hook. It will trigger a cache update and notify components about the addition. zchangeset modifiedamNotify trac about changesets modified in a repository This command should be called from a post-revprop hook after revision properties like the commit message, author or date have been changed. It will trigger a cache update for the given revisions and notify components about the change. zrepository listzList source repositorieszrepository resyncz [rev]aRe-synchronize trac with repositories When [rev] is specified, only that revision is synchronized. Otherwise, the complete revision history is synchronized. Note that this operation can take a long time to complete. If synchronization gets interrupted, it can be resumed later using the `sync` command. must be the repository name, not the repository path. Use `list` to see a list of repository names and associated paths. To synchronize all repositories, specify "*" for . The default repository can be specified using "(default)". zrepository synca,Resume synchronization of repositories It works like `resync`, except that it doesn't clear the already synchronized changesets, so it's a better way to resume an interrupted `resync`. See `resync` help for detailed usage. )_complete_repos_do_changeset_added_do_changeset_modified_do_list _do_resync_do_syncselfr%;/usr/lib/python3/dist-packages/trac/versioncontrol/admin.pyget_admin_commands(s*  z&VersionControlAdmin.get_admin_commandscCst|j}dd|DS)NcSsg|]}|pdqS) (default)r%).0reponamer%r%r& Ys z5VersionControlAdmin.get_reponames..)renvget_all_repositories)r$rmr%r%r& get_reponamesWs z!VersionControlAdmin.get_reponamescCst|dkr |SdS)N)lenr/)r$argsr%r%r&r\s z#VersionControlAdmin._complete_reposcGHt|rd}t|j}|d||f|}|D]}t|q|r"dSdS)Nrchangeset_addedrrrr,notifyrr$r* first_revrevsr.errorserrorr%r%r&r`   z'VersionControlAdmin._do_changeset_addedcGr3)Nrchangeset_modifiedr5rr6r8r%r%r&rir=z*VersionControlAdmin._do_changeset_modifiedc Cst|j}g}t|D]#\}}d}d|vr|dpd}||p$d|dd||ddfqt|tdtdtdtd gdS) Nraliasr(typedirNameTypeAlias Directory) rr,sortedr-itemsappendgetr r)r$r.valuesr*infor?r%r%r&r rs   &zVersionControlAdmin._do_listc Cst|j}|dkr|durttd|}nt|rd}||}|dur1ttd|p-dd|g}t|ddd D]E}|jpBd}|durV| |t td ||d qsz+VersionControlAdmin._sync..)keyz!%(rev)s resynced on %(reponame)s.)revr*z1Resyncing repository history for %(reponame)s... rOcleanz.SELECT count(rev) FROM revision WHERE repos=%sz%(num)s revision cached.z%(num)s revisions cached.)numzDone.)rr, TracErrorrget_real_repositoriesrget_repositoryrFr*sync_changesetrsync_sync_feedbackdb_queryidr) r$r*rSrUr. repositoriesrepos pretty_namecntr%r%r&_sync}sD          zVersionControlAdmin._synccCs4|dur tjd|ntjdtjdS)Nz [%s] z)sysstdoutwriteflush)r$rSr%r%r&r\s z"VersionControlAdmin._sync_feedbackNcC|j||dddS)NTrTrcr$r*rSr%r%r&r!zVersionControlAdmin._do_resynccCrh)NFrTrirjr%r%r&r"rkzVersionControlAdmin._do_syncc Csxt|jD]2}|jp d}ttd|dz||jWnty3t td||jp-ddYqw|dqdS)zIndex the repositories.r(z Indexing '%(name)s' repositorynamea --------------------------------------------------------------------- Warning: couldn't index '%(pretty_name)s' repository. This can happen for a variety of reasons: wrong repository type, no appropriate third party library for this repository type, no repository at the specified repository path... You can nevertheless start using your Trac environment, but you'll need to check your `%(name)s.type` and `%(name)s.dir` option values in the [repositories] section of your trac.ini file. r)rarmN) rr,rXr*rrr[r\rWr)r$r`rar%r%r&environment_createds    z'VersionControlAdmin.environment_createdcCdSrNr%r#r%r%r&environment_needs_upgradez-VersionControlAdmin.environment_needs_upgradecCrorNr%r#r%r%r&upgrade_environmentrqz'VersionControlAdmin.upgrade_environmentcCsdgdfgS)NVERSIONCONTROL_ADMIN) BROWSER_VIEWCHANGESET_VIEW FILE_VIEWLOG_VIEWr%r#r%r%r&get_permission_actionssz*VersionControlAdmin.get_permission_actionsrN)__name__ __module__ __qualname____doc__ implementsrrrr'r/rrrr rcr\r!r"rnrprrrxr%r%r%r&r s&/   "   rc@sHeZdZdZeeedddddZddZd d Z d d Z d dZ dS)RepositoryAdminPanelz.Web admin panel for repository administration.versioncontrolallowed_repository_dir_prefixesrzComma-separated list of allowed prefixes for repository directories when adding and editing repositories in the repository admin panel. If the list is empty, all repository directories are allowed. )docccsFt|j}|rd|ddvr!dtddtdfVdSdSdS)Nrsadminzversioncontrol/repositoryrzVersion Control repository Repositories)rr,get_supported_typespermr)r$reqtypesr%r%r&get_admin_panelss   z%RepositoryAdminPanel.get_admin_panelsc stj}|}jt}|rt|s|nd}||} | dur*ttd|d|jdkr|j dr@| |j ||n|r|j dri} d} |j D]} t|j | } | dusa| dvrl| | | krl| | | <qOd | vr{|| d s{d } | r| r||| t|td |j d }|pd }tdjj|f}d | vrtd|d}t||nd| vrtd|d}t|||r||krd| vrtdjj|f}td|d}t||| r| |j ||tj}||||d|d}n6|jdkr4|r|j dr|j d }|pd }||vr*ttd|d|j d}t|j d d}|dusF|dusF|sNt|tdn܈||r||||t|td|dtdjj|f}td|d}t||tdjj|f}tjtd|j dd d!}td"||d#}t||n|r|j d$r|j d }|pd }|j d}|dur|durz|||Wnjjjyttd%|dwt|td&|dn=t|td'n5|j d(rn-|r*|j d)r*|j d*}|r#|D]}|!|qt|td+nt|td,| |j ||d-d.i}i|durEt"|#fd/d0|$D}t%dg|&}|'||j(|t)d1d2|*Dd3d4|fS)5NrzRepository '%(repo)s' not foundrLPOSTcancelsaveT)hiddensync_per_requestrAFzYour changes have been saved.rmr(z&trac-admin "%s" repository resync "%s"zFYou should now run %(resync)s to synchronize Trac with the repository.)resyncr@zGYou may have to run %(resync)s to synchronize Trac with the repository.r?z)trac-admin "%s" changeset added "%s" $REVzbYou will need to update your post-commit hook to call %(cset_added)s with the new repository name.) cset_addeddetail)viewr* add_reposz)The repository "%(name)s" already exists.rlz&Missing arguments to add a repository.z)The repository "%(name)s" has been added. documentationTracRepositoryAdminz#Synchronization)hrefzYou should also set up a post-commit hook on the repository to call %(cset_added)s for each committed changeset. See the %(doc)s for more information.)rr add_aliasz$The alias "%(name)s" already exists.z$The alias "%(name)s" has been added.z"Missing arguments to add an alias.refreshremoveselz,The selected repositories have been removed.zNo repositories were selected.rlistc s(i|]\}}||||vqSr%) _extend_infocopy)r)r*rKdb_reposr$r%r& |s z;RepositoryAdminPanel.render_admin_panel..css|]}d|vVqdS)r?Nr%)r)rKr%r%r& sz:RepositoryAdminPanel.render_admin_panel..)r default_typer_ can_add_aliaszadmin_repositories.html)+rr,r-rrrIrWrmethodr2redirectrrrepository_attrsr _check_dirmodify_repositoryrr codepathrradd_wiki_toolbarsadd_auto_previewradd_repositoryawikirdb_excIntegrityErrorgetlistremove_repositorydictget_repositoriesrGrFrupdatedefault_repository_typeanyrJ)r$rcategorypage path_infor. all_repos db_providerr*rKchangesvalidfieldvaluermrarmsgrchromedatatype_rArr?rr_rr%rr&render_admin_panels                                  z'RepositoryAdminPanel.render_admin_panelc Cs||d<t|d|d<t|d|d<||d<d|vrw|ddur/t|dp,d|d <z t|j|}Wn tyP}z ||d <WYd}~|Sd}~wtyYY|Sw|}||d <z | ||d <W|St yvY|Sw|S) z%Extend repository info for rendering.rmrreditabler?rANr prettydirr<rS display_rev) rrIr rr,rYrrWget_youngest_revrr)r$r*rKrr`e youngest_revr%r%r&rs6   z!RepositoryAdminPanel._extend_infocsltjst|tddSfddjD}|r4tfdd|Ds4t|tdd|d dSd S) z^Check that a repository directory is valid, and add a warning message if not. z2The repository directory must be an absolute path.Fcsg|] }tjjj|qSr%)osrjoinr,r)prefixr#r%r&r+sz3RepositoryAdminPanel._check_dir..c3s|]}t|VqdSrN)r r)rAr%r&rsz2RepositoryAdminPanel._check_dir..zYThe repository directory must be located below one of the following directories: %(dirs)sz, )dirsT)rrisabsrrrrr)r$rrAprefixesr%)rAr$r&rs  zRepositoryAdminPanel._check_dirN) ryrzr{r|r}rrrrrrrr%r%r%r&r~s ! r~))os.pathrrd trac.adminrrtrac.apir trac.configr trac.core trac.permr trac.utilrr trac.util.htmlr trac.util.textr r r rrtrac.util.translationrrrtrac.versioncontrolrrrrrtrac.web.chromerrr Componentrr~r%r%r%r&s      4