本文整理汇总了Python中trac.versioncontrol.api.RepositoryManager类的典型用法代码示例。如果您正苦于以下问题:Python RepositoryManager类的具体用法?Python RepositoryManager怎么用?Python RepositoryManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RepositoryManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pre_process_request
def pre_process_request(self, req, handler):
"""
Pre-process the request by adding 'Zip Archive' link into alternative format links
The link is constructed from first and latest revision number, taken from the default
repository.
:param Request req: Trac request
:param object handler: existing handler
:returns: Handler, modified or not
"""
# Add link only in /browser or /browser/?rev= pages
if (self.browser_regx.match(req.path_info)
and 'BROWSER_VIEW' in req.perm and 'FILE_VIEW' in req.perm):
# Get default repository and its type
rm = RepositoryManager(self.env)
repo = rm.get_repository('')
repo_type = rm.repository_type
# Construct the export urls for each format and based on revision info
latest_rev = plaintext(str(req.args.get('rev', repo.get_youngest_rev())))
# Use Trac's internal implementation
if repo_type == 'svn':
return handler
# For other types, iterate supported formats
for format, info in self.formats.items():
add_link(req, 'alternate', req.href('export/archive', rev=latest_rev, format=format), _(info['desc']),
info['mime'], info['ext'])
return handler
示例2: process_request
def process_request(self, req):
if req.method != 'POST':
msg = u'Method not allowed (%s)\n' % req.method
req.send(msg.encode('utf-8'), 'text/plain', 405)
if req.args.get('token') != self.token:
msg = u'Invalid token (%s)\n' % req.args.get('token')
req.send(msg.encode('utf-8'), 'text/plain', 403)
path = req.args.get('path', '/')
rm = RepositoryManager(self.env)
reponame, repos, path = rm.get_repository_by_path(path)
output = u'Running hook on %s\n' % (reponame or '(default)')
if self.autofetch:
git = repos.git.repo
output += u'* Running git fetch\n'
output += git.fetch()
output += u'* Updating references\n'
remote_refs = git.for_each_ref(
"--format=%(refname)", "refs/remotes/origin").split()
for remote_ref in remote_refs:
local_ref = remote_ref.replace('remotes/origin', 'heads', 1)
output += git.update_ref(local_ref, remote_ref)
data = req.args.get('payload')
if data:
revs = [commit['id'] for commit in json.loads(data)['commits']]
if revs:
output += u'* Adding changesets %s\n' % u', '.join(revs)
rm.notify('changeset_added', reponame, revs)
req.send(output.encode('utf-8'), 'text/plain', 200 if output else 204)
示例3: _get_authz_info
def _get_authz_info(self):
try:
mtime = os.path.getmtime(self.authz_file)
except OSError as e:
if self._authz is not None:
self.log.error('Error accessing authz file: %s',
exception_to_unicode(e))
self._mtime = mtime = 0
self._authz = None
self._users = set()
if mtime != self._mtime:
self._mtime = mtime
rm = RepositoryManager(self.env)
modules = set(repos.reponame
for repos in rm.get_real_repositories())
if '' in modules and self.authz_module_name:
modules.add(self.authz_module_name)
modules.add('')
self.log.info('Parsing authz file: %s', self.authz_file)
try:
self._authz = parse(read_file(self.authz_file), modules)
self._users = set(user for paths in self._authz.itervalues()
for path in paths.itervalues()
for user, result in path.iteritems()
if result)
except Exception as e:
self._authz = None
self._users = set()
self.log.error('Error parsing authz file: %s',
exception_to_unicode(e))
return self._authz, self._users
示例4: post_process_request
def post_process_request(self, req, template, data, content_type):
#add_script(req, 'multiproject/js/browser.js')
repository_name = None
data_repositories = None
latest_revisions = []
if len(req.path_info.split("/")) > 2:
#Get repository name from path_info
repository_name = req.path_info.split("/")[2]
if template == 'browser.html':
username = urllib.quote(req.authname)
project = Project.get(self.env)
schemes = None
if repository_name:
scm_type = repository_name + ".type"
scm_dir = repository_name + ".dir"
scm = self.env.config.get('repositories', scm_type)
repository_name = self.env.config.get('repositories', scm_dir).split("/")[-1]
schemes = self.protocols(project.id, scm)
rm = RepositoryManager(self.env)
list_repos = rm.get_real_repositories()
for r in list_repos:
if r.get_base().split("/")[-1] == repository_name:
l_rev = r.get_youngest_rev()
if l_rev:
export_url = '../export/archive/'+repository_name+"?rev="+str(l_rev)+"&format=zip"
latest_revisions.append(export_url)
else:
scm = self.env.config.get('trac', 'repository_type')
schemes = self.protocols(project.id, scm)
data_repo_names = self.get_repositories()
if len(data_repo_names) > 0:
data_repositories = []
for repo in data_repo_names:
type_scheme = []
for data_scheme in self.protocols(project.id, repo[1]):
type_scheme.append(self.create_co_command(repo[1], username, data_scheme, repo[0]))
data_repositories.append(type_scheme)
names = {'git':'GIT', 'svn':'Subversion', 'hg':'Mercurial'}
cmd_kinds = {'git':'Clone', 'hg':'Clone', 'svn':'Check out'}
type = names[scm]
data['kinds'] = cmd_kinds
data['schemes'] = schemes
data['name'] = names[scm]
data['type'] = scm
data['data_repositories'] = data_repositories
data['export_urls'] = latest_revisions
co_commands = {}
for scheme in schemes:
co_commands[scheme] = self.create_co_command(scm, username, scheme, repository_name)
data['co_commands'] = co_commands
return template, data, content_type
示例5: _get_vcs_folders
def _get_vcs_folders(self, req, q, dirname, prefix):
rm = RepositoryManager(self.env)
reponame, repos, path = rm.get_repository_by_path(dirname)
repo_entries = {'text': _('Suggestions'),
'children': [],
}
if repos:
try:
entries = ({'id': '/' + pathjoin(repos.reponame, e.path),
'text': '/' + pathjoin(repos.reponame, e.path),
'is_favorite': False
}
for e in repos.get_node(path).get_entries()
if e.can_view(req.perm)
and e.name.lower().startswith(prefix)
and e.isdir
)
repo_entries['children'].extend(entries)
if q.endswith('/'):
repo_entries['children'].append({'id': q,
'text': q,
'is_favorite': False
}
)
except NoSuchNode:
pass
return repo_entries
示例6: _format_link
def _format_link(self, formatter, ns, match, label, fullmatch=None):
if ns == 'log1':
groups = fullmatch.groupdict()
it_log = groups.get('it_log')
revs = groups.get('log_revs')
path = groups.get('log_path') or '/'
target = '%s%[email protected]%s' % (it_log, path, revs)
# prepending it_log is needed, as the helper expects it there
intertrac = formatter.shorthand_intertrac_helper(
'log', target, label, fullmatch)
if intertrac:
return intertrac
path, query, fragment = formatter.split_link(path)
else:
assert ns in ('log', 'log2')
if ns == 'log':
match, query, fragment = formatter.split_link(match)
else:
query = fragment = ''
match = ''.join(reversed(match.split('/', 1)))
path = match
revs = ''
if self.LOG_LINK_RE.match(match):
indexes = [sep in match and match.index(sep) for sep in ':@']
idx = min([i for i in indexes if i is not False])
path, revs = match[:idx], match[idx+1:]
rm = RepositoryManager(self.env)
try:
reponame, repos, path = rm.get_repository_by_path(path)
if not reponame:
reponame = rm.get_default_repository(formatter.context)
if reponame is not None:
repos = rm.get_repository(reponame)
if repos:
if 'LOG_VIEW' in formatter.perm:
reponame = repos.reponame or None
path = path or '/'
revranges = RevRanges(repos, revs)
if revranges.has_ranges():
href = formatter.href.log(reponame, path,
revs=unicode(revranges))
else:
# try to resolve if single rev
repos.normalize_rev(revs)
href = formatter.href.log(reponame, path,
rev=revs or None)
if query and '?' in href:
query = '&' + query[1:]
return tag.a(label, class_='source',
href=href + query + fragment)
errmsg = _("No permission to view change log")
elif reponame:
errmsg = _("Repository '%(repo)s' not found", repo=reponame)
else:
errmsg = _("No default repository defined")
except TracError, e:
errmsg = to_unicode(e)
示例7: _get_repository
def _get_repository(env, req):
'''From env and req identify and return (reponame, repository, path),
removing reponame from path in the process.
'''
path = req.args.get('path')
repo_mgr = RepositoryManager(env)
reponame, repos, path = repo_mgr.get_repository_by_path(path)
return reponame, repos, path
示例8: ChangesetIndexerEventsTestCase
class ChangesetIndexerEventsTestCase(BaseBloodhoundSearchTest):
def setUp(self):
super(ChangesetIndexerEventsTestCase, self).setUp()
self.whoosh_backend = WhooshBackend(self.env)
self.whoosh_backend.recreate_index()
self.search_api = BloodhoundSearchApi(self.env)
self.repository_manager = RepositoryManager(self.env)
self.inject_dummy_repository()
def test_can_index_added_changeset(self):
rev = self.insert_changeset("Changed document 1.")
results = self.search_api.query("*:*")
self.assertEqual(1, results.hits)
doc = results.docs[0]
self.assertEqual('%s/dummy' % rev, doc["id"])
self.assertEqual('dummy', doc["repository"])
self.assertEqual('1', doc["revision"])
self.assertEqual("Changed document 1.", doc["message"])
def test_can_index_modified_changeset(self):
rev = self.insert_changeset("Changed document 1.")
self.modify_changeset(rev, "Added document 1.")
results = self.search_api.query("*:*")
self.assertEqual(1, results.hits)
doc = results.docs[0]
self.assertEqual('%s/dummy' % rev, doc["id"])
self.assertEqual('dummy', doc["repository"])
self.assertEqual('1', doc["revision"])
self.assertEqual("Added document 1.", doc["message"])
def insert_changeset(self, message, author=None, date=None, revision=None):
rev = self.repository.add_changeset(revision, message, author, date)
self.repository_manager.notify("changeset_added", 'dummy', [rev])
return rev
def modify_changeset(self, rev, message=None, author=None, date=None):
changeset = self.repository.get_changeset(rev)
if message is not None:
changeset.message = message
if author is not None:
changeset.author = author
if date is not None:
changeset.date = date
self.repository_manager.notify("changeset_modified", "dummy", [rev])
def inject_dummy_repository(self):
# pylint: disable=protected-access,attribute-defined-outside-init
self.repository = DummyRepositry()
self.repository_connector = DummyRepositoryConnector(self.env)
self.repository_connector.repository = self.repository
self.repository_manager._all_repositories = {
'dummy': dict(dir='dirname', type='dummy')}
self.repository_manager._connectors = {
'dummy': (self.repository_connector, 100)}
示例9: _render_repository_index
def _render_repository_index(self, context, all_repositories, order, desc):
# Color scale for the age column
timerange = custom_colorizer = None
if self.color_scale:
custom_colorizer = self.get_custom_colorizer()
rm = RepositoryManager(self.env)
repositories = []
for reponame, repoinfo in all_repositories.iteritems():
if not reponame or as_bool(repoinfo.get("hidden")):
continue
try:
repos = rm.get_repository(reponame)
except TracError as err:
entry = (reponame, repoinfo, None, None, exception_to_unicode(err), None)
else:
if repos:
if not repos.is_viewable(context.perm):
continue
try:
youngest = repos.get_changeset(repos.youngest_rev)
except NoSuchChangeset:
youngest = None
if self.color_scale and youngest:
if not timerange:
timerange = TimeRange(youngest.date)
else:
timerange.insert(youngest.date)
raw_href = self._get_download_href(context.href, repos, None, None)
entry = (reponame, repoinfo, repos, youngest, None, raw_href)
else:
entry = (reponame, repoinfo, None, None, u"\u2013", None)
if entry[4] is not None: # Check permission in case of error
root = Resource("repository", reponame).child(self.realm, "/")
if "BROWSER_VIEW" not in context.perm(root):
continue
repositories.append(entry)
# Ordering of repositories
if order == "date":
def repo_order((reponame, repoinfo, repos, youngest, err, href)):
return (youngest.date if youngest else to_datetime(0), embedded_numbers(reponame.lower()))
elif order == "author":
def repo_order((reponame, repoinfo, repos, youngest, err, href)):
return (youngest.author.lower() if youngest else "", embedded_numbers(reponame.lower()))
else:
def repo_order((reponame, repoinfo, repos, youngest, err, href)):
return embedded_numbers(reponame.lower())
repositories = sorted(repositories, key=repo_order, reverse=desc)
return {"repositories": repositories, "timerange": timerange, "colorize_age": custom_colorizer}
示例10: _format_link
def _format_link(self, formatter, ns, match, label, fullmatch=None):
if ns == "log1":
groups = fullmatch.groupdict()
it_log = groups.get("it_log")
revs = groups.get("log_revs")
path = groups.get("log_path") or "/"
target = "%s%[email protected]%s" % (it_log, path, revs)
# prepending it_log is needed, as the helper expects it there
intertrac = formatter.shorthand_intertrac_helper("log", target, label, fullmatch)
if intertrac:
return intertrac
path, query, fragment = formatter.split_link(path)
else:
assert ns in ("log", "log2")
if ns == "log":
match, query, fragment = formatter.split_link(match)
else:
query = fragment = ""
match = "".join(reversed(match.split("/", 1)))
path = match
revs = ""
if self.LOG_LINK_RE.match(match):
indexes = [sep in match and match.index(sep) for sep in ":@"]
idx = min([i for i in indexes if i is not False])
path, revs = match[:idx], match[idx + 1 :]
rm = RepositoryManager(self.env)
try:
reponame, repos, path = rm.get_repository_by_path(path)
if not reponame:
reponame = rm.get_default_repository(formatter.context)
if reponame is not None:
repos = rm.get_repository(reponame)
if repos:
if "LOG_VIEW" in formatter.perm:
reponame = repos.reponame or None
path = path or "/"
revranges = RevRanges(repos, revs)
if revranges.has_ranges():
href = formatter.href.log(reponame, path, revs=unicode(revranges))
else:
# try to resolve if single rev
repos.normalize_rev(revs)
href = formatter.href.log(reponame, path, rev=revs or None)
if query and "?" in href:
query = "&" + query[1:]
return tag.a(label, class_="source", href=href + query + fragment)
errmsg = _("No permission to view change log")
elif reponame:
errmsg = _("Repository '%(repo)s' not found", repo=reponame)
else:
errmsg = _("No default repository defined")
except TracError as e:
errmsg = to_unicode(e)
return tag.a(label, class_="missing source", title=errmsg)
示例11: check_permission
def check_permission(self, action, username, resource, perm):
realm = resource.realm if resource else None
if (realm, action) in self._handled_perms:
authz, users = self._get_authz_info()
if authz is None:
return False
if username == 'anonymous':
usernames = ('$anonymous', '*')
else:
usernames = (username, '$authenticated', '*')
if resource is None:
return True if users & set(usernames) else None
rm = RepositoryManager(self.env)
try:
repos = rm.get_repository(resource.parent.id)
except TracError:
return True # Allow error to be displayed in the repo index
if repos is None:
return True
modules = [resource.parent.id or self.authz_module_name]
if modules[0]:
modules.append('')
def check_path(path):
path = '/' + join(repos.scope, path)
if path != '/':
path += '/'
# Allow access to parent directories of allowed resources
if any(section.get(user) is True
for module in modules
for spath, section in authz.get(module, {}).iteritems()
if spath.startswith(path)
for user in usernames):
return True
# Walk from resource up parent directories
for spath in parent_iter(path):
for module in modules:
section = authz.get(module, {}).get(spath)
if section:
for user in usernames:
result = section.get(user)
if result is not None:
return result
if realm == 'source':
return check_path(resource.id)
elif realm == 'changeset':
changes = list(repos.get_changeset(resource.id).get_changes())
if not changes or any(check_path(change[0])
for change in changes):
return True
示例12: process_request
def process_request(self, req):
req.perm.require('BROWSER_VIEW')
presel = req.args.get('preselected')
if presel and (presel + '/').startswith(req.href.browser() + '/'):
req.redirect(presel)
path = req.args.get('path', '/')
rev = req.args.get('rev', '')
if rev in ('', 'HEAD'):
rev = None
order = req.args.get('order', 'name').lower()
desc = req.args.has_key('desc')
xhr = req.get_header('X-Requested-With') == 'XMLHttpRequest'
rm = RepositoryManager(self.env)
all_repositories = rm.get_all_repositories()
reponame, repos, path = rm.get_repository_by_path(path)
# Repository index
show_index = not reponame and path == '/'
if show_index:
if repos and (as_bool(all_repositories[''].get('hidden'))
or not repos.can_view(req.perm)):
repos = None
if not repos and reponame:
raise ResourceNotFound(_("Repository '%(repo)s' not found",
repo=reponame))
if reponame and reponame != repos.reponame: # Redirect alias
qs = req.query_string
req.redirect(req.href.browser(repos.reponame or None, path)
+ (qs and '?' + qs or ''))
reponame = repos and repos.reponame or None
# Find node for the requested path/rev
context = Context.from_request(req)
node = None
display_rev = lambda rev: rev
if repos:
try:
if rev:
rev = repos.normalize_rev(rev)
# If `rev` is `None`, we'll try to reuse `None` consistently,
# as a special shortcut to the latest revision.
rev_or_latest = rev or repos.youngest_rev
node = get_existing_node(req, repos, path, rev_or_latest)
except NoSuchChangeset, e:
raise ResourceNotFound(e.message,
_('Invalid changeset number'))
context = context(repos.resource.child('source', path,
version=rev_or_latest))
display_rev = repos.display_rev
示例13: expand_macro
def expand_macro(self, formatter, name, content):
args, kwargs = parse_args(content)
format = kwargs.get('format', 'compact')
glob = kwargs.get('glob', '*')
order = kwargs.get('order')
desc = as_bool(kwargs.get('desc', 0))
rm = RepositoryManager(self.env)
all_repos = dict(rdata for rdata in rm.get_all_repositories().items()
if fnmatchcase(rdata[0], glob))
if format == 'table':
repo = self._render_repository_index(formatter.context, all_repos,
order, desc)
add_stylesheet(formatter.req, 'common/css/browser.css')
wiki_format_messages = self.config['changeset'] \
.getbool('wiki_format_messages')
data = {'repo': repo, 'order': order, 'desc': desc and 1 or None,
'reponame': None, 'path': '/', 'stickyrev': None,
'wiki_format_messages': wiki_format_messages}
from trac.web.chrome import Chrome
return Chrome(self.env).render_template(
formatter.req, 'repository_index.html', data, None,
fragment=True)
def get_repository(reponame):
try:
return rm.get_repository(reponame)
except TracError:
return
all_repos = [(reponame, get_repository(reponame))
for reponame in all_repos]
all_repos = sorted(((reponame, repos) for reponame, repos in all_repos
if repos
and not as_bool(repos.params.get('hidden'))
and repos.can_view(formatter.perm)),
reverse=desc)
def repolink(reponame, repos):
label = reponame or _('(default)')
return Markup(tag.a(label,
title=_('View repository %(repo)s', repo=label),
href=formatter.href.browser(repos.reponame or None)))
if format == 'list':
return tag.dl([
tag(tag.dt(repolink(reponame, repos)),
tag.dd(repos.params.get('description')))
for reponame, repos in all_repos])
else: # compact
return Markup(', ').join([repolink(reponame, repos)
for reponame, repos in all_repos])
示例14: get_entries_for_index
def get_entries_for_index(self):
repository_manager = RepositoryManager(self.env)
for repository in repository_manager.get_real_repositories():
rev = repository.oldest_rev
stop = repository.youngest_rev
while True:
changeset = repository.get_changeset(rev)
yield ChangesetIndexer(self.env).build_doc(changeset)
if rev == stop:
break
rev = repository.next_rev(rev)
示例15: process_request
def process_request(self, req):
rev = req.args.get("rev")
path = req.args.get("path")
rm = RepositoryManager(self.env)
reponame, repos, path = rm.get_repository_by_path(path)
gh_repo = self.get_gh_repo(reponame)
try:
rev = repos.normalize_rev(rev)
except NoSuchChangeset, e:
raise ResourceNotFound(e.message, _("Invalid Changeset Number"))