def _sync(self, reponame, rev, clean): rm = RepositoryManager(self.env) if reponame == '*': if rev is not None: raise TracError(_('Cannot synchronize a single revision ' 'on multiple repositories')) repositories = rm.get_real_repositories() else: if is_default(reponame): reponame = '' repos = rm.get_repository(reponame) if repos is None: raise TracError(_("Repository '%(repo)s' not found", repo=reponame or '(default)')) if rev is not None: repos.sync_changeset(rev) printout(_('%(rev)s resynced on %(reponame)s.', rev=rev, reponame=repos.reponame or '(default)')) return repositories = [repos] db = self.env.get_db_cnx() for repos in sorted(repositories, key=lambda r: r.reponame): printout(_('Resyncing repository history for %(reponame)s... ', reponame=repos.reponame or '(default)')) repos.sync(self._sync_feedback, clean=clean) cursor = db.cursor() cursor.execute("SELECT count(rev) FROM revision WHERE repos=%s", (repos.id,)) for cnt, in cursor: printout(ngettext('%(num)s revision cached.', '%(num)s revisions cached.', num=cnt)) printout(_('Done.'))
def _do_changeset_modified(self, reponame, *revs): if is_default(reponame): reponame = '' rm = RepositoryManager(self.env) errors = rm.notify('changeset_modified', reponame, revs) for error in errors: printout(error)
def _sync(self, reponame, rev, clean): rm = RepositoryManager(self.env) if reponame == '*': if rev is not None: raise TracError(_('Cannot synchronize a single revision ' 'on multiple repositories')) repositories = rm.get_real_repositories() else: if is_default(reponame): reponame = '' repos = rm.get_repository(reponame) if repos is None: raise TracError(_("Repository '%(repo)s' not found", repo=reponame or '(default)')) if rev is not None: repos.sync_changeset(rev) printout(_('%(rev)s resynced on %(reponame)s.', rev=rev, reponame=repos.reponame or '(default)')) return repositories = [repos] for repos in sorted(repositories, key=lambda r: r.reponame): printout(_('Resyncing repository history for %(reponame)s... ', reponame=repos.reponame or '(default)')) repos.sync(self._sync_feedback, clean=clean) for cnt, in self.env.db_query( "SELECT count(rev) FROM revision WHERE repos=%s", (repos.id,)): printout(ngettext('%(num)s revision cached.', '%(num)s revisions cached.', num=cnt)) printout(_('Done.'))
def _do_changeset_added(self, reponame, first_rev, *revs): if is_default(reponame): reponame = '' rm = RepositoryManager(self.env) errors = rm.notify('changeset_added', reponame, (first_rev, ) + revs) for error in errors: printout(error)
def _do_changeset_added(self, reponame, *revs): if is_default(reponame): reponame = "" rm = RepositoryManager(self.env) errors = rm.notify("changeset_added", reponame, revs) for error in errors: printout(error)
def _do_changeset_modified(self, reponame, first_rev, *revs): if is_default(reponame): reponame = '' rm = RepositoryManager(self.env) errors = rm.notify('changeset_modified', reponame, (first_rev,) + revs) for error in errors: printerr(error) return 2 if errors else 0
def render_admin_panel(self, req, cat, page, path_info): req.perm.require('SVNVERIFY_REPORT') rm = RepositoryManager(self.env) all_repos = rm.get_all_repositories() db = self.env.get_read_db() cursor = db.cursor() if path_info: # detailed reponame = not is_default(path_info) and path_info or '' info = all_repos.get(reponame) if info is None: raise TracError(_("Repository '%(repo)s' not found", repo=path_info)) cursor.execute("SELECT type, time, result, log " "FROM svnverify_log WHERE repository_id = %s " "ORDER BY time DESC LIMIT 1", (info['id'],)) row = cursor.fetchone() if row: info['check_type'] = row[0] info['time_checked'] = format_datetime(from_utimestamp(row[1])) info['pretty_status'] = int(row[2]) == 0 and "OK" or "Warning" info['status'] = row[2] info['log'] = row[3] info['prettydir'] = breakable_path(info['dir']) if info['name'] == '': info['name'] = "(default)" return 'svnverify.html', {"info": info} else: repositories = {} for reponame, info in all_repos.iteritems(): if info.get('type',rm.repository_type) == "svn" or (rm.repository_type == 'svn' and info.get('type') == ''): info['prettydir'] = breakable_path(info['dir']) try: r = RepositoryManager(self.env).get_repository(reponame) info['rev'] = r.get_youngest_rev() info['display_rev'] = r.display_rev(info['rev']) except: pass cursor.execute("SELECT type, time, result " "FROM svnverify_log " "WHERE repository_id = %s " "ORDER BY time DESC LIMIT 1", (info['id'],)) row = cursor.fetchone() if row: info['check_type'] = row[0] info['time_checked'] = format_datetime(from_utimestamp(row[1])) info['pretty_status'] = int(row[2]) == 0 and "OK" or "Warning" info['status'] = row[2] repositories[reponame] = info add_stylesheet(req, 'svnverify/css/svnverify.css') return 'svnverifylist.html', {"repositories": repositories}
def _sync(self, reponame, rev, clean): rm = RepositoryManager(self.env) if reponame == "*": if rev is not None: raise TracError(_("Cannot synchronize a single revision " "on multiple repositories")) repositories = rm.get_real_repositories() else: if is_default(reponame): reponame = "" repos = rm.get_repository(reponame) if repos is None: raise TracError(_("Repository '%(repo)s' not found", repo=reponame or "(default)")) if rev is not None: repos.sync_changeset(rev) printout(_("%(rev)s resynced on %(reponame)s.", rev=rev, reponame=repos.reponame or "(default)")) return repositories = [repos] for repos in sorted(repositories, key=lambda r: r.reponame): printout(_("Resyncing repository history for %(reponame)s... ", reponame=repos.reponame or "(default)")) repos.sync(self._sync_feedback, clean=clean) for (cnt,) in self.env.db_query("SELECT count(rev) FROM revision WHERE repos=%s", (repos.id,)): printout(ngettext("%(num)s revision cached.", "%(num)s revisions cached.", num=cnt)) printout(_("Done."))
def render_admin_panel(self, req, category, page, path_info): # Retrieve info for all repositories rm = RepositoryManager(self.env) all_repos = rm.get_all_repositories() db_provider = self.env[DbRepositoryProvider] if path_info: # Detail view reponame = path_info if not is_default(path_info) else '' info = all_repos.get(reponame) if info is None: raise TracError( _("Repository '%(repo)s' not found", repo=path_info)) if req.method == 'POST': if req.args.get('cancel'): req.redirect(req.href.admin(category, page)) elif db_provider and req.args.get('save'): # Modify repository changes = {} valid = True for field in db_provider.repository_attrs: value = normalize_whitespace(req.args.get(field)) if (value is not None or field in ('hidden', 'sync_per_request')) \ and value != info.get(field): changes[field] = value if 'dir' in changes and not \ self._check_dir(req, changes['dir']): valid = False if valid and changes: db_provider.modify_repository(reponame, changes) add_notice(req, _('Your changes have been saved.')) name = req.args.get('name') pretty_name = name or '(default)' resync = tag.code('trac-admin "%s" repository resync ' '"%s"' % (self.env.path, pretty_name)) if 'dir' in changes: msg = tag_( 'You should now run %(resync)s to ' 'synchronize Trac with the repository.', resync=resync) add_notice(req, msg) elif 'type' in changes: msg = tag_( 'You may have to run %(resync)s to ' 'synchronize Trac with the repository.', resync=resync) add_notice(req, msg) if name and name != path_info and 'alias' not in info: cset_added = tag.code('trac-admin "%s" changeset ' 'added "%s" $REV' % (self.env.path, pretty_name)) msg = tag_( 'You will need to update your ' 'post-commit hook to call ' '%(cset_added)s with the new ' 'repository name.', cset_added=cset_added) add_notice(req, msg) if valid: req.redirect(req.href.admin(category, page)) chrome = Chrome(self.env) chrome.add_wiki_toolbars(req) chrome.add_auto_preview(req) data = {'view': 'detail', 'reponame': reponame} else: # List view if req.method == 'POST': # Add a repository if db_provider and req.args.get('add_repos'): name = req.args.get('name') pretty_name = name or '(default)' if name in all_repos: raise TracError( _('The repository "%(name)s" already ' 'exists.', name=pretty_name)) type_ = req.args.get('type') # Avoid errors when copy/pasting paths dir = normalize_whitespace(req.args.get('dir', '')) if name is None or type_ is None or not dir: add_warning( req, _('Missing arguments to add a ' 'repository.')) elif self._check_dir(req, dir): db_provider.add_repository(name, dir, type_) add_notice( req, _('The repository "%(name)s" has been ' 'added.', name=pretty_name)) resync = tag.code('trac-admin "%s" repository resync ' '"%s"' % (self.env.path, pretty_name)) msg = tag_( 'You should now run %(resync)s to ' 'synchronize Trac with the repository.', resync=resync) add_notice(req, msg) cset_added = tag.code('trac-admin "%s" changeset ' 'added "%s" $REV' % (self.env.path, pretty_name)) doc = tag.a(_("documentation"), href=req.href.wiki('TracRepositoryAdmin') + '#Synchronization') msg = tag_( 'You 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.', cset_added=cset_added, doc=doc) add_notice(req, msg) # Add a repository alias elif db_provider and req.args.get('add_alias'): name = req.args.get('name') pretty_name = name or '(default)' alias = req.args.get('alias') if name is not None and alias is not None: try: db_provider.add_alias(name, alias) except self.env.db_exc.IntegrityError: raise TracError( _('The alias "%(name)s" already ' 'exists.', name=pretty_name)) add_notice( req, _('The alias "%(name)s" has been ' 'added.', name=pretty_name)) else: add_warning(req, _('Missing arguments to add an ' 'alias.')) # Refresh the list of repositories elif req.args.get('refresh'): pass # Remove repositories elif db_provider and req.args.get('remove'): sel = req.args.getlist('sel') if sel: for name in sel: db_provider.remove_repository(name) add_notice( req, _('The selected repositories have ' 'been removed.')) else: add_warning(req, _('No repositories were selected.')) req.redirect(req.href.admin(category, page)) data = {'view': 'list'} # Find repositories that are editable db_repos = {} if db_provider is not None: db_repos = dict(db_provider.get_repositories()) # Prepare common rendering data repositories = { reponame: self._extend_info(reponame, info.copy(), reponame in db_repos) for (reponame, info) in all_repos.iteritems() } types = sorted([''] + rm.get_supported_types()) data.update({ 'types': types, 'default_type': rm.default_repository_type, 'repositories': repositories, 'can_add_alias': any('alias' not in info for info in repositories.itervalues()) }) return 'admin_repositories.html', data
def _do_changeset_modified(self, reponame, *revs): if is_default(reponame): reponame = '' rm = RepositoryManager(self.env) rm.notify('changeset_modified', reponame, revs)
def render_admin_panel(self, req, category, page, path_info): req.perm.require('VERSIONCONTROL_ADMIN') # Retrieve info for all repositories rm = RepositoryManager(self.env) all_repos = rm.get_all_repositories() db_provider = self.env[DbRepositoryProvider] if path_info: # Detail view reponame = not is_default(path_info) and path_info or '' info = all_repos.get(reponame) if info is None: raise TracError(_("Repository '%(repo)s' not found", repo=path_info)) if req.method == 'POST': if req.args.get('cancel'): req.redirect(req.href.admin(category, page)) elif db_provider and req.args.get('save'): # Modify repository changes = {} for field in db_provider.repository_attrs: value = normalize_whitespace(req.args.get(field)) if (value is not None or field == 'hidden') \ and value != info.get(field): changes[field] = value if 'dir' in changes \ and not self._check_dir(req, changes['dir']): changes = {} if changes: db_provider.modify_repository(reponame, changes) add_notice(req, _('Your changes have been saved.')) name = req.args.get('name') resync = tag.tt('trac-admin $ENV repository resync "%s"' % (name or '(default)')) if 'dir' in changes: msg = tag_('You should now run %(resync)s to ' 'synchronize Trac with the repository.', resync=resync) add_notice(req, msg) elif 'type' in changes: msg = tag_('You may have to run %(resync)s to ' 'synchronize Trac with the repository.', resync=resync) add_notice(req, msg) if name and name != path_info and not 'alias' in info: cset_added = tag.tt('trac-admin $ENV changeset ' 'added "%s" $REV' % (name or '(default)')) msg = tag_('You will need to update your post-commit ' 'hook to call %(cset_added)s with the new ' 'repository name.', cset_added=cset_added) add_notice(req, msg) if changes: req.redirect(req.href.admin(category, page)) Chrome(self.env).add_wiki_toolbars(req) data = {'view': 'detail', 'reponame': reponame} else: # List view if req.method == 'POST': # Add a repository if db_provider and req.args.get('add_repos'): name = req.args.get('name') type_ = req.args.get('type') # Avoid errors when copy/pasting paths dir = normalize_whitespace(req.args.get('dir', '')) if name is None or type_ is None or not dir: add_warning(req, _('Missing arguments to add a ' 'repository.')) elif self._check_dir(req, dir): db_provider.add_repository(name, dir, type_) name = name or '(default)' add_notice(req, _('The repository "%(name)s" has been ' 'added.', name=name)) resync = tag.tt('trac-admin $ENV repository resync ' '"%s"' % name) msg = tag_('You should now run %(resync)s to ' 'synchronize Trac with the repository.', resync=resync) add_notice(req, msg) cset_added = tag.tt('trac-admin $ENV changeset ' 'added "%s" $REV' % name) msg = tag_('You should also set up a post-commit hook ' 'on the repository to call %(cset_added)s ' 'for each committed changeset.', cset_added=cset_added) add_notice(req, msg) req.redirect(req.href.admin(category, page)) # Add a repository alias elif db_provider and req.args.get('add_alias'): name = req.args.get('name') alias = req.args.get('alias') if name is not None and alias is not None: db_provider.add_alias(name, alias) add_notice(req, _('The alias "%(name)s" has been ' 'added.', name=name or '(default)')) req.redirect(req.href.admin(category, page)) add_warning(req, _('Missing arguments to add an ' 'alias.')) # Refresh the list of repositories elif req.args.get('refresh'): req.redirect(req.href.admin(category, page)) # Remove repositories elif db_provider and req.args.get('remove'): sel = req.args.getlist('sel') if sel: for name in sel: db_provider.remove_repository(name) add_notice(req, _('The selected repositories have ' 'been removed.')) req.redirect(req.href.admin(category, page)) add_warning(req, _('No repositories were selected.')) data = {'view': 'list'} # Find repositories that are editable db_repos = {} if db_provider is not None: db_repos = dict(db_provider.get_repositories()) # Prepare common rendering data repositories = dict((reponame, self._extend_info(reponame, info.copy(), reponame in db_repos)) for (reponame, info) in all_repos.iteritems()) types = sorted([''] + rm.get_supported_types()) data.update({'types': types, 'default_type': rm.repository_type, 'repositories': repositories}) return 'admin_repositories.html', data
def render_admin_panel(self, req, category, page, path_info): req.perm.require('VERSIONCONTROL_ADMIN') # Retrieve info for all repositories rm = RepositoryManager(self.env) all_repos = rm.get_all_repositories() db_provider = self.env[DbRepositoryProvider] if path_info: # Detail view reponame = path_info if not is_default(path_info) else '' info = all_repos.get(reponame) if info is None: raise TracError( _("Repository '%(repo)s' not found", repo=path_info)) if req.method == 'POST': if req.args.get('cancel'): req.redirect(req.href.admin(category, page)) elif db_provider and req.args.get('save'): # Modify repository changes = {} for field in db_provider.repository_attrs: value = normalize_whitespace(req.args.get(field)) if (value is not None or field == 'hidden') \ and value != info.get(field): changes[field] = value if 'dir' in changes \ and not self._check_dir(req, changes['dir']): changes = {} if changes: db_provider.modify_repository(reponame, changes) add_notice(req, _('Your changes have been saved.')) name = req.args.get('name') resync = tag.tt('trac-admin $ENV repository resync "%s"' % (name or '(default)')) if 'dir' in changes: msg = tag_( 'You should now run %(resync)s to ' 'synchronize Trac with the repository.', resync=resync) add_notice(req, msg) elif 'type' in changes: msg = tag_( 'You may have to run %(resync)s to ' 'synchronize Trac with the repository.', resync=resync) add_notice(req, msg) if name and name != path_info and not 'alias' in info: cset_added = tag.tt('trac-admin $ENV changeset ' 'added "%s" $REV' % (name or '(default)')) msg = tag_( 'You will need to update your post-commit ' 'hook to call %(cset_added)s with the new ' 'repository name.', cset_added=cset_added) add_notice(req, msg) if changes: req.redirect(req.href.admin(category, page)) Chrome(self.env).add_wiki_toolbars(req) data = {'view': 'detail', 'reponame': reponame} else: # List view if req.method == 'POST': # Add a repository if db_provider and req.args.get('add_repos'): name = req.args.get('name') type_ = req.args.get('type') # Avoid errors when copy/pasting paths dir = normalize_whitespace(req.args.get('dir', '')) if name is None or type_ is None or not dir: add_warning( req, _('Missing arguments to add a ' 'repository.')) elif self._check_dir(req, dir): db_provider.add_repository(name, dir, type_) name = name or '(default)' add_notice( req, _('The repository "%(name)s" has been ' 'added.', name=name)) resync = tag.tt('trac-admin $ENV repository resync ' '"%s"' % name) msg = tag_( 'You should now run %(resync)s to ' 'synchronize Trac with the repository.', resync=resync) add_notice(req, msg) cset_added = tag.tt('trac-admin $ENV changeset ' 'added "%s" $REV' % name) msg = tag_( 'You should also set up a post-commit hook ' 'on the repository to call %(cset_added)s ' 'for each committed changeset.', cset_added=cset_added) add_notice(req, msg) req.redirect(req.href.admin(category, page)) # Add a repository alias elif db_provider and req.args.get('add_alias'): name = req.args.get('name') alias = req.args.get('alias') if name is not None and alias is not None: db_provider.add_alias(name, alias) add_notice( req, _('The alias "%(name)s" has been ' 'added.', name=name or '(default)')) req.redirect(req.href.admin(category, page)) add_warning(req, _('Missing arguments to add an ' 'alias.')) # Refresh the list of repositories elif req.args.get('refresh'): req.redirect(req.href.admin(category, page)) # Remove repositories elif db_provider and req.args.get('remove'): sel = req.args.getlist('sel') if sel: for name in sel: db_provider.remove_repository(name) add_notice( req, _('The selected repositories have ' 'been removed.')) req.redirect(req.href.admin(category, page)) add_warning(req, _('No repositories were selected.')) data = {'view': 'list'} # Find repositories that are editable db_repos = {} if db_provider is not None: db_repos = dict(db_provider.get_repositories()) # Prepare common rendering data repositories = dict( (reponame, self._extend_info(reponame, info.copy(), reponame in db_repos)) for (reponame, info) in all_repos.iteritems()) types = sorted([''] + rm.get_supported_types()) data.update({ 'types': types, 'default_type': rm.repository_type, 'repositories': repositories }) return 'admin_repositories.html', data
def render_admin_panel(self, req, category, page, path_info): req.perm.require("VERSIONCONTROL_ADMIN") # Retrieve info for all repositories rm = RepositoryManager(self.env) all_repos = rm.get_all_repositories() db_provider = self.env[DbRepositoryProvider] if path_info: # Detail view reponame = path_info if not is_default(path_info) else "" info = all_repos.get(reponame) if info is None: raise TracError(_("Repository '%(repo)s' not found", repo=path_info)) if req.method == "POST": if req.args.get("cancel"): req.redirect(req.href.admin(category, page)) elif db_provider and req.args.get("save"): # Modify repository changes = {} for field in db_provider.repository_attrs: value = normalize_whitespace(req.args.get(field)) if (value is not None or field == "hidden") and value != info.get(field): changes[field] = value if "dir" in changes and not self._check_dir(req, changes["dir"]): changes = {} if changes: db_provider.modify_repository(reponame, changes) add_notice(req, _("Your changes have been saved.")) name = req.args.get("name") resync = tag.tt('trac-admin $ENV repository resync "%s"' % (name or "(default)")) if "dir" in changes: msg = tag_( "You should now run %(resync)s to " "synchronize Trac with the repository.", resync=resync ) add_notice(req, msg) elif "type" in changes: msg = tag_( "You may have to run %(resync)s to " "synchronize Trac with the repository.", resync=resync ) add_notice(req, msg) if name and name != path_info and not "alias" in info: cset_added = tag.tt("trac-admin $ENV changeset " 'added "%s" $REV' % (name or "(default)")) msg = tag_( "You will need to update your post-commit " "hook to call %(cset_added)s with the new " "repository name.", cset_added=cset_added, ) add_notice(req, msg) if changes: req.redirect(req.href.admin(category, page)) Chrome(self.env).add_wiki_toolbars(req) data = {"view": "detail", "reponame": reponame} else: # List view if req.method == "POST": # Add a repository if db_provider and req.args.get("add_repos"): name = req.args.get("name") type_ = req.args.get("type") # Avoid errors when copy/pasting paths dir = normalize_whitespace(req.args.get("dir", "")) if name is None or type_ is None or not dir: add_warning(req, _("Missing arguments to add a " "repository.")) elif self._check_dir(req, dir): db_provider.add_repository(name, dir, type_) name = name or "(default)" add_notice(req, _('The repository "%(name)s" has been ' "added.", name=name)) resync = tag.tt("trac-admin $ENV repository resync " '"%s"' % name) msg = tag_( "You should now run %(resync)s to " "synchronize Trac with the repository.", resync=resync ) add_notice(req, msg) cset_added = tag.tt("trac-admin $ENV changeset " 'added "%s" $REV' % name) msg = tag_( "You should also set up a post-commit hook " "on the repository to call %(cset_added)s " "for each committed changeset.", cset_added=cset_added, ) add_notice(req, msg) req.redirect(req.href.admin(category, page)) # Add a repository alias elif db_provider and req.args.get("add_alias"): name = req.args.get("name") alias = req.args.get("alias") if name is not None and alias is not None: db_provider.add_alias(name, alias) add_notice(req, _('The alias "%(name)s" has been ' "added.", name=name or "(default)")) req.redirect(req.href.admin(category, page)) add_warning(req, _("Missing arguments to add an " "alias.")) # Refresh the list of repositories elif req.args.get("refresh"): req.redirect(req.href.admin(category, page)) # Remove repositories elif db_provider and req.args.get("remove"): sel = req.args.getlist("sel") if sel: for name in sel: db_provider.remove_repository(name) add_notice(req, _("The selected repositories have " "been removed.")) req.redirect(req.href.admin(category, page)) add_warning(req, _("No repositories were selected.")) data = {"view": "list"} # Find repositories that are editable db_repos = {} if db_provider is not None: db_repos = dict(db_provider.get_repositories()) # Prepare common rendering data repositories = dict( (reponame, self._extend_info(reponame, info.copy(), reponame in db_repos)) for (reponame, info) in all_repos.iteritems() ) types = sorted([""] + rm.get_supported_types()) data.update({"types": types, "default_type": rm.repository_type, "repositories": repositories}) return "admin_repositories.html", data
def _do_changeset_added(self, reponame, *revs): if is_default(reponame): reponame = "" rm = RepositoryManager(self.env) rm.notify("changeset_added", reponame, revs)