##// END OF EJS Templates
i18n: updated translation for Polish...
i18n: updated translation for Polish Currently translated at 56.5% (614 of 1087 strings)

File last commit:

r8078:08eec03c default
r8092:7fef5132 default
Show More
summary.py
214 lines | 8.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.summary
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bradley M. Kuhn
General renaming to Kallithea
r4212 Summary 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 18, 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 calendar
Mads Kiilerich
compat: drop unnecessary wrappers for old Python versions...
r6171 import itertools
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 import logging
import traceback
from datetime import date, timedelta
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 from time import mktime
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 request
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 webob.exc import HTTPBadRequest
Mads Kiilerich
summary: handle repo like changelog does...
r7854 import kallithea.lib.helpers as h
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 from kallithea.config.conf import ALL_EXTS, ALL_READMES, LANGUAGES_EXTENSIONS_MAP
Mads Kiilerich
lib: clean up ext_json and how it is used - avoid monkey patching...
r7987 from kallithea.lib import ext_json
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
from kallithea.lib.base import BaseRepoController, jsonify, render
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 from kallithea.lib.celerylib.tasks import get_commits_stats
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 from kallithea.lib.markup_renderer import MarkupRenderer
Mads Kiilerich
page: replace RepoPage with Page given the reverse collection...
r7855 from kallithea.lib.page import Page
Mads Kiilerich
py3: rename all existing safe_unicode to safe_str
r8078 from kallithea.lib.utils2 import safe_int, safe_str
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718 from kallithea.lib.vcs.backends.base import EmptyChangeset
from kallithea.lib.vcs.exceptions import ChangesetError, EmptyRepositoryError, NodeDoesNotExistError
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 from kallithea.lib.vcs.nodes import FileNode
Mads Kiilerich
caching: invalidate Repository cache of README and RSS based on latest revision hash in its .changeset_cache...
r7831 from kallithea.model.db import Statistics
Mads Kiilerich
scripts: initial run of import cleanup using isort
r7718
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
log = logging.getLogger(__name__)
README_FILES = [''.join([x[0][0], x[1][0]]) for x in
Mads Kiilerich
compat: drop unnecessary wrappers for old Python versions...
r6171 sorted(list(itertools.product(ALL_READMES, ALL_EXTS)),
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 key=lambda y:y[0][1] + y[1][1])]
class SummaryController(BaseRepoController):
def __get_readme_data(self, db_repo):
repo_name = db_repo.repo_name
log.debug('Looking for README file')
Mads Kiilerich
db: name the scm_instance_cached cache entries - reduce the risk of collisions...
r5737 @cache_region('long_term', '_get_readme_from_cache')
Mads Kiilerich
caching: clarify that arguments to internal @cache_region functions only are used as caching key
r7830 def _get_readme_from_cache(*_cache_keys): # parameters are not really used - only as caching key
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 readme_data = None
readme_file = None
try:
# gets the landing revision! or tip if fails
cs = db_repo.get_landing_changeset()
if isinstance(cs, EmptyChangeset):
raise EmptyRepositoryError()
renderer = MarkupRenderer()
for f in README_FILES:
try:
readme = cs.get_node(f)
if not isinstance(readme, FileNode):
continue
readme_file = f
Mads Kiilerich
cleanup: pass log strings unformatted - avoid unnecessary % formatting when not logging
r5375 log.debug('Found README file `%s` rendering...',
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 readme_file)
Mads Kiilerich
py3: rename all existing safe_unicode to safe_str
r8078 readme_data = renderer.render(safe_str(readme.content),
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 filename=f)
break
except NodeDoesNotExistError:
continue
except ChangesetError:
log.error(traceback.format_exc())
pass
except EmptyRepositoryError:
pass
return readme_data, readme_file
kind = 'README'
Mads Kiilerich
caching: invalidate Repository cache of README and RSS based on latest revision hash in its .changeset_cache...
r7831 return _get_readme_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
auth: restore anonymous repository access...
r7038 @LoginRequired(allow_default_user=True)
Søren Løvborg
auth: simplify repository permission checks...
r6471 @HasRepoPermissionLevelDecorator('read')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 def index(self, repo_name):
Mads Kiilerich
summary: inline _load_changelog_summary...
r6773 p = safe_int(request.GET.get('page'), 1)
size = safe_int(request.GET.get('size'), 10)
Mads Kiilerich
summary: handle repo like changelog does...
r7854 try:
Mads Kiilerich
page: replace RepoPage with Page given the reverse collection...
r7855 collection = c.db_repo_scm_instance.get_changesets(reverse=True)
Mads Kiilerich
summary: handle repo like changelog does...
r7854 except EmptyRepositoryError as e:
Mads Kiilerich
lib: handle both HTML, unsafe strings, and exceptions passed to helpers.flash()...
r7949 h.flash(e, category='warning')
Mads Kiilerich
summary: handle repo like changelog does...
r7854 collection = []
Mads Kiilerich
page: replace RepoPage with Page given the reverse collection...
r7855 c.cs_pagination = Page(collection, page=p, items_per_page=size)
Mads Kiilerich
summary: inline _load_changelog_summary...
r6773 page_revisions = [x.raw_id for x in list(c.cs_pagination)]
c.cs_comments = c.db_repo.get_comments(page_revisions)
c.cs_statuses = c.db_repo.statuses(page_revisions)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Mads Kiilerich
summary: only show SSH clone URL if SSH is enabled and the user is authenticated
r7737 c.ssh_repo_url = None
Mads Kiilerich
controllers: avoid setting request state in controller instances - set it in the thread global request variable...
r6412 if request.authuser.is_default_user:
Mads Kiilerich
clone_url: drop **override - we only pass username
r7669 username = None
Søren Løvborg
auth: introduce AuthUser.is_default_user attribute...
r5545 else:
Mads Kiilerich
clone_url: drop **override - we only pass username
r7669 username = request.authuser.username
Mads Kiilerich
summary: only show SSH clone URL if SSH is enabled and the user is authenticated
r7737 if c.ssh_enabled:
c.ssh_repo_url = c.db_repo.clone_url(clone_uri_tmpl=c.clone_ssh_tmpl)
Mads Kiilerich
clone_url: simplify the logic - move summary handling of different URLs with/without id to db...
r7668 c.clone_repo_url = c.db_repo.clone_url(clone_uri_tmpl=c.clone_uri_tmpl, with_id=False, username=username)
c.clone_repo_url_id = c.db_repo.clone_url(clone_uri_tmpl=c.clone_uri_tmpl, with_id=True, username=username)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Bradley M. Kuhn
Rename rhodecode_db_repo to db_repo - it stores db repo abstractions
r4195 if c.db_repo.enable_statistics:
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 c.show_stats = True
else:
c.show_stats = False
Søren Løvborg
model: remove BaseModel class...
r6483 stats = Statistics.query() \
Mads Kiilerich
cleanup: consistent space before line continuation backslash
r5585 .filter(Statistics.repository == c.db_repo) \
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 .scalar()
c.stats_percentage = 0
if stats and stats.languages:
Mads Kiilerich
lib: clean up ext_json and how it is used - avoid monkey patching...
r7987 lang_stats_d = ext_json.loads(stats.languages)
Mads Kiilerich
summary: simplify sorting of language stats - avoid comparing dicts...
r7705 lang_stats = [(x, {"count": y,
"desc": LANGUAGES_EXTENSIONS_MAP.get(x, '?')})
for x, y in lang_stats_d.items()]
lang_stats.sort(key=lambda k: (-k[1]['count'], k[0]))
c.trending_languages = lang_stats[:10]
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 else:
Søren Løvborg
templates: properly escape inline JavaScript values...
r6492 c.trending_languages = []
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Bradley M. Kuhn
Rename rhodecode_db_repo to db_repo - it stores db repo abstractions
r4195 c.enable_downloads = c.db_repo.enable_downloads
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 c.readme_data, c.readme_file = \
Bradley M. Kuhn
Rename rhodecode_db_repo to db_repo - it stores db repo abstractions
r4195 self.__get_readme_data(c.db_repo)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 return render('summary/summary.html')
@LoginRequired()
Søren Løvborg
auth: simplify repository permission checks...
r6471 @HasRepoPermissionLevelDecorator('read')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 @jsonify
def repo_size(self, repo_name):
if request.is_xhr:
Bradley M. Kuhn
Rename rhodecode_db_repo to db_repo - it stores db repo abstractions
r4195 return c.db_repo._repo_size()
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 else:
raise HTTPBadRequest()
Mads Kiilerich
auth: restore anonymous repository access...
r7038 @LoginRequired(allow_default_user=True)
Søren Løvborg
auth: simplify repository permission checks...
r6471 @HasRepoPermissionLevelDecorator('read')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 def statistics(self, repo_name):
Bradley M. Kuhn
Rename rhodecode_db_repo to db_repo - it stores db repo abstractions
r4195 if c.db_repo.enable_statistics:
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 c.show_stats = True
Andrew Shadura
stats: fix display when no data ready yet...
r4932 c.no_data_msg = _('No data ready yet')
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 else:
c.show_stats = False
c.no_data_msg = _('Statistics are disabled for this repository')
td = date.today() + timedelta(days=1)
Mads Kiilerich
summary: use calendar.monthrange instead of internal calendar.mday...
r8048 td_1m = td - timedelta(days=calendar.monthrange(td.year, td.month)[1])
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 td_1y = td - timedelta(days=365)
ts_min_m = mktime(td_1m.timetuple())
ts_min_y = mktime(td_1y.timetuple())
ts_max_y = mktime(td.timetuple())
c.ts_min = ts_min_m
c.ts_max = ts_max_y
Søren Løvborg
model: remove BaseModel class...
r6483 stats = Statistics.query() \
Mads Kiilerich
cleanup: consistent space before line continuation backslash
r5585 .filter(Statistics.repository == c.db_repo) \
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 .scalar()
Mads Kiilerich
summary: add missing c.stats_percentage initialization that caused crash on empty repos
r5521 c.stats_percentage = 0
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 if stats and stats.languages:
Mads Kiilerich
lib: clean up ext_json and how it is used - avoid monkey patching...
r7987 c.commit_data = ext_json.loads(stats.commit_activity)
c.overview_data = ext_json.loads(stats.commit_activity_combined)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
Mads Kiilerich
summary: compute lang_stats consistently...
r7990 lang_stats_d = ext_json.loads(stats.languages)
lang_stats = [(x, {"count": y,
"desc": LANGUAGES_EXTENSIONS_MAP.get(x, '?')})
for x, y in lang_stats_d.items()]
lang_stats.sort(key=lambda k: (-k[1]['count'], k[0]))
c.trending_languages = lang_stats[:10]
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
last_rev = stats.stat_on_revision + 1
Mads Kiilerich
cleanup: consistent space before line continuation backslash
r5585 c.repo_last_rev = c.db_repo_scm_instance.count() \
Bradley M. Kuhn
Rename rhodecode_repo to db_repo_scm_instance
r4196 if c.db_repo_scm_instance.revisions else 0
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 if last_rev == 0 or c.repo_last_rev == 0:
pass
else:
c.stats_percentage = '%.2f' % ((float((last_rev)) /
c.repo_last_rev) * 100)
else:
Søren Løvborg
templates: properly escape inline JavaScript values...
r6492 c.commit_data = {}
c.overview_data = ([[ts_min_y, 0], [ts_max_y, 10]])
Mads Kiilerich
summary: drop no_data in all possible ways...
r7989 c.trending_languages = []
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187
recurse_limit = 500 # don't recurse more than 500 times when parsing
Mads Kiilerich
celeryd: annotate tasks so they can be run directly without run_task...
r6133 get_commits_stats(c.db_repo.repo_name, ts_min_y, ts_max_y, recurse_limit)
Bradley M. Kuhn
Second step in two-part process to rename directories....
r4187 return render('summary/statistics.html')