##// END OF EJS Templates
py3: prepare for types.NotImplementedType going away...
py3: prepare for types.NotImplementedType going away From 2to3 types.

File last commit:

r7860:19e046dd default
r7891:4fcf6351 default
Show More
feed.py
139 lines | 5.3 KiB | text/x-python | PythonLexer
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 # -*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
kallithea.controllers.feed
~~~~~~~~~~~~~~~~~~~~~~~~~~
Bradley M. Kuhn
General renaming to Kallithea
r4212 Feed controller for Kallithea
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Bradley M. Kuhn
RhodeCode GmbH is not the sole author of this work
r4211 This file was forked by the Kallithea project in July 2014.
Original author and date, and relevant copyright and licensing information is below:
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 :created_on: Apr 23, 2010
:author: marcink
Bradley M. Kuhn
RhodeCode GmbH is not the sole author of this work
r4211 :copyright: (c) 2013 RhodeCode GmbH, and others.
Bradley M. Kuhn
Correct licensing information in individual files....
r4208 :license: GPLv3, see LICENSE.md for more details.
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 """
import logging
Mads Kiilerich
caching: invalidate Repository cache of README and RSS based on latest revision hash in its .changeset_cache...
r7831 from beaker.cache import cache_region
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 from tg import response
from tg import tmpl_context as c
Mads Kiilerich
tg: minimize future diff by some mocking and replacing some pylons imports with tg...
r6508 from tg.i18n import ugettext as _
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
Mads Kiilerich
controllers: avoid setting constants as controller instance variables in __before__...
r6411 from kallithea import CONFIG
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 from kallithea.lib import helpers as h
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 from kallithea.lib.base import BaseRepoController
Mads Kiilerich
diffs: drop the DiffLimitExceeded container - just make it a flag available as property...
r6839 from kallithea.lib.diffs import DiffProcessor
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 from kallithea.lib.utils2 import safe_int, safe_unicode, str2bool
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
log = logging.getLogger(__name__)
Mads Kiilerich
controllers: avoid setting constants as controller instance variables in __before__...
r6411 language = 'en-us'
ttl = "5"
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 class FeedController(BaseRepoController):
Mads Kiilerich
auth: drop api_access_controllers_whitelist and give API key auth same access as other kinds of auth...
r7598 @LoginRequired(allow_default_user=True)
Søren Løvborg
auth: simplify repository permission checks...
r6471 @HasRepoPermissionLevelDecorator('read')
Thomas De Schampheleire
controllers: rename __before__ to _before in preparation of TurboGears2...
r6513 def _before(self, *args, **kwargs):
super(FeedController, self)._before(*args, **kwargs)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
def _get_title(self, cs):
Mads Kiilerich
cleanup: remove unnecessary '%s'%s formatting
r5305 return h.shorter(cs.message, 160)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Mads Kiilerich
diffs: drop the noop as_raw method - just use the raw diff directly and with proper variable naming
r6834 def __get_desc(self, cs):
desc_msg = [(_('%s committed on %s')
% (h.person(cs.author), h.fmt_date(cs.date))) + '<br/>']
# branches, tags, bookmarks
Mads Kiilerich
vcs: introduce 'branches' attribute on changesets, making it possible for Git to show multiple branches for a changeset...
r7067 for branch in cs.branches:
desc_msg.append('branch: %s<br/>' % branch)
Mads Kiilerich
diffs: drop the noop as_raw method - just use the raw diff directly and with proper variable naming
r6834 for book in cs.bookmarks:
desc_msg.append('bookmark: %s<br/>' % book)
for tag in cs.tags:
desc_msg.append('tag: %s<br/>' % tag)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 changes = []
Mads Kiilerich
diffs: cleanup of variable naming around cut_off_limit...
r6831 diff_limit = safe_int(CONFIG.get('rss_cut_off_limit', 32 * 1024))
Mads Kiilerich
diffs: drop the noop as_raw method - just use the raw diff directly and with proper variable naming
r6834 raw_diff = cs.diff()
diff_processor = DiffProcessor(raw_diff,
Mads Kiilerich
diffs: inline prepare() into __init__ and make the result available as .parsed...
r6838 diff_limit=diff_limit,
inline_diff=False)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Mads Kiilerich
diffs: inline prepare() into __init__ and make the result available as .parsed...
r6838 for st in diff_processor.parsed:
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 st.update({'added': st['stats']['added'],
'removed': st['stats']['deleted']})
changes.append('\n %(operation)s %(filename)s '
'(%(added)s lines added, %(removed)s lines removed)'
% st)
Mads Kiilerich
diffs: drop the DiffLimitExceeded container - just make it a flag available as property...
r6839 if diff_processor.limited_diff:
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 changes = changes + ['\n ' +
_('Changeset was too big and was cut off...')]
# rev link
Mads Kiilerich
urls: introduce canonical_url config setting...
r4445 _url = h.canonical_url('changeset_home', repo_name=c.db_repo.repo_name,
revision=cs.raw_id)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 desc_msg.append('changeset: <a href="%s">%s</a>' % (_url, cs.raw_id[:8]))
desc_msg.append('<pre>')
Andrew Shadura
feed: urlify and escape the commit description...
r4827 desc_msg.append(h.urlify_text(cs.message))
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 desc_msg.append('\n')
desc_msg.extend(changes)
Mads Kiilerich
controllers: avoid setting constants as controller instance variables in __before__...
r6411 if str2bool(CONFIG.get('rss_include_diff', False)):
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 desc_msg.append('\n\n')
Mads Kiilerich
diffs: drop the noop as_raw method - just use the raw diff directly and with proper variable naming
r6834 desc_msg.append(raw_diff)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 desc_msg.append('</pre>')
return map(safe_unicode, desc_msg)
Mads Kiilerich
feed: refactor to reduce code duplication
r7860 def _feed(self, repo_name, kind, feed_factory):
"""Produce a simple feed"""
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Mads Kiilerich
db: name the scm_instance_cached cache entries - reduce the risk of collisions...
r5737 @cache_region('long_term', '_get_feed_from_cache')
Mads Kiilerich
caching: clarify that arguments to internal @cache_region functions only are used as caching key
r7830 def _get_feed_from_cache(*_cache_keys): # parameters are not really used - only as caching key
Mads Kiilerich
feed: refactor to reduce code duplication
r7860 feed = feed_factory(
Mads Kiilerich
controllers: avoid setting constants as controller instance variables in __before__...
r6411 title=_('%s %s feed') % (c.site_name, repo_name),
link=h.canonical_url('summary_home', repo_name=repo_name),
description=_('Changes on %s repository') % repo_name,
language=language,
Mads Kiilerich
feed: refactor to reduce code duplication
r7860 ttl=ttl, # rss only
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 )
Mads Kiilerich
controllers: avoid setting constants as controller instance variables in __before__...
r6411 rss_items_per_page = safe_int(CONFIG.get('rss_items_per_page', 20))
for cs in reversed(list(c.db_repo_scm_instance[-rss_items_per_page:])):
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 feed.add_item(title=self._get_title(cs),
Mads Kiilerich
urls: introduce canonical_url config setting...
r4445 link=h.canonical_url('changeset_home', repo_name=repo_name,
revision=cs.raw_id),
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 author_name=cs.author,
description=''.join(self.__get_desc(cs)),
pubdate=cs.date,
)
response.content_type = feed.mime_type
return feed.writeString('utf-8')
Mads Kiilerich
caching: invalidate Repository cache of README and RSS based on latest revision hash in its .changeset_cache...
r7831 return _get_feed_from_cache(repo_name, kind, c.db_repo.changeset_cache.get('raw_id'))
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Mads Kiilerich
feed: refactor to reduce code duplication
r7860 def atom(self, repo_name):
"""Produce a simple atom-1.0 feed"""
return self._feed(repo_name, 'ATOM', Atom1Feed)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 def rss(self, repo_name):
"""Produce an rss2 feed via feedgenerator module"""
Mads Kiilerich
feed: refactor to reduce code duplication
r7860 return self._feed(repo_name, 'RSS', Rss201rev2Feed)