# HG changeset patch # User Marcin Kuzminski # Date 2011-04-05 11:12:38 # Node ID 50e41777675dd62e4f93ba60268beca4f27e9d62 # Parent a7e7c0fab9db0c92a71134f8d43879597f01a4b1 pep8ify diff --git a/rhodecode/controllers/branches.py b/rhodecode/controllers/branches.py --- a/rhodecode/controllers/branches.py +++ b/rhodecode/controllers/branches.py @@ -33,6 +33,7 @@ from rhodecode.lib.utils import OrderedD log = logging.getLogger(__name__) + class BranchesController(BaseRepoController): @LoginRequired() diff --git a/rhodecode/controllers/changelog.py b/rhodecode/controllers/changelog.py --- a/rhodecode/controllers/changelog.py +++ b/rhodecode/controllers/changelog.py @@ -40,6 +40,7 @@ from rhodecode.lib.helpers import RepoPa log = logging.getLogger(__name__) + class ChangelogController(BaseRepoController): @LoginRequired() @@ -67,14 +68,14 @@ class ChangelogController(BaseRepoContro p = int(request.params.get('page', 1)) branch_name = request.params.get('branch', None) c.total_cs = len(c.rhodecode_repo) - c.pagination = RepoPage(c.rhodecode_repo, page=p, item_count=c.total_cs, - items_per_page=c.size, branch_name=branch_name) + c.pagination = RepoPage(c.rhodecode_repo, page=p, + item_count=c.total_cs, items_per_page=c.size, + branch_name=branch_name) self._graph(c.rhodecode_repo, c.total_cs, c.size, p) return render('changelog/changelog.html') - def _graph(self, repo, repo_size, size, p): """ Generates a DAG graph for mercurial diff --git a/rhodecode/controllers/changeset.py b/rhodecode/controllers/changeset.py --- a/rhodecode/controllers/changeset.py +++ b/rhodecode/controllers/changeset.py @@ -43,6 +43,7 @@ from vcs.utils.ordered_dict import Order log = logging.getLogger(__name__) + class ChangesetController(BaseRepoController): @LoginRequired() @@ -94,7 +95,6 @@ class ChangesetController(BaseRepoContro except IndexError: changeset_parent = None - #================================================================== # ADDED FILES #================================================================== @@ -106,17 +106,20 @@ class ChangesetController(BaseRepoContro c.sum_added += node.size if c.sum_added < self.cut_off_limit: f_gitdiff = differ.get_gitdiff(filenode_old, node) - diff = differ.DiffProcessor(f_gitdiff, format='gitdiff').as_html() + diff = differ.DiffProcessor(f_gitdiff, + format='gitdiff').as_html() else: - diff = wrap_to_table(_('Changeset is to big and was cut' - ' off, see raw changeset instead')) + diff = wrap_to_table(_('Changeset is to big and ' + 'was cut off, see raw ' + 'changeset instead')) c.cut_off = True break cs1 = None cs2 = node.last_changeset.raw_id - c.changes[changeset.raw_id].append(('added', node, diff, cs1, cs2)) + c.changes[changeset.raw_id].append(('added', node, + diff, cs1, cs2)) #================================================================== # CHANGED FILES @@ -126,7 +129,8 @@ class ChangesetController(BaseRepoContro try: filenode_old = changeset_parent.get_node(node.path) except ChangesetError: - filenode_old = FileNode(node.path, '', EmptyChangeset()) + filenode_old = FileNode(node.path, '', + EmptyChangeset()) if filenode_old.is_binary or node.is_binary: diff = wrap_to_table(_('binary file')) @@ -134,25 +138,30 @@ class ChangesetController(BaseRepoContro if c.sum_removed < self.cut_off_limit: f_gitdiff = differ.get_gitdiff(filenode_old, node) - diff = differ.DiffProcessor(f_gitdiff, format='gitdiff').as_html() + diff = differ.DiffProcessor(f_gitdiff, + format='gitdiff')\ + .as_html() if diff: c.sum_removed += len(diff) else: - diff = wrap_to_table(_('Changeset is to big and was cut' - ' off, see raw changeset instead')) + diff = wrap_to_table(_('Changeset is to big and ' + 'was cut off, see raw ' + 'changeset instead')) c.cut_off = True break cs1 = filenode_old.last_changeset.raw_id cs2 = node.last_changeset.raw_id - c.changes[changeset.raw_id].append(('changed', node, diff, cs1, cs2)) + c.changes[changeset.raw_id].append(('changed', node, + diff, cs1, cs2)) #================================================================== # REMOVED FILES #================================================================== if not c.cut_off: for node in changeset.removed: - c.changes[changeset.raw_id].append(('removed', node, None, None, None)) + c.changes[changeset.raw_id].append(('removed', node, None, + None, None)) if len(c.cs_ranges) == 1: c.changeset = c.cs_ranges[0] @@ -184,7 +193,8 @@ class ChangesetController(BaseRepoContro diff = _('binary file') + '\n' else: f_gitdiff = differ.get_gitdiff(filenode_old, node) - diff = differ.DiffProcessor(f_gitdiff, format='gitdiff').raw_diff() + diff = differ.DiffProcessor(f_gitdiff, + format='gitdiff').raw_diff() cs1 = None cs2 = node.last_changeset.raw_id @@ -196,7 +206,8 @@ class ChangesetController(BaseRepoContro diff = _('binary file') else: f_gitdiff = differ.get_gitdiff(filenode_old, node) - diff = differ.DiffProcessor(f_gitdiff, format='gitdiff').raw_diff() + diff = differ.DiffProcessor(f_gitdiff, + format='gitdiff').raw_diff() cs1 = filenode_old.last_changeset.raw_id cs2 = node.last_changeset.raw_id @@ -205,10 +216,12 @@ class ChangesetController(BaseRepoContro response.content_type = 'text/plain' if method == 'download': - response.content_disposition = 'attachment; filename=%s.patch' % revision + response.content_disposition = 'attachment; filename=%s.patch' \ + % revision parent = True if len(c.changeset.parents) > 0 else False - c.parent_tmpl = 'Parent %s' % c.changeset.parents[0].raw_id if parent else '' + c.parent_tmpl = 'Parent %s' \ + % c.changeset.parents[0].raw_id if parent else '' c.diffs = '' for x in c.changes: diff --git a/rhodecode/controllers/error.py b/rhodecode/controllers/error.py --- a/rhodecode/controllers/error.py +++ b/rhodecode/controllers/error.py @@ -27,7 +27,7 @@ import cgi import logging import paste.fileapp -from pylons import tmpl_context as c, request, config +from pylons import tmpl_context as c, request, config, url from pylons.i18n.translation import _ from pylons.middleware import media_path @@ -35,6 +35,7 @@ from rhodecode.lib.base import BaseContr log = logging.getLogger(__name__) + class ErrorController(BaseController): """Generates error documents as and when they are required. @@ -46,7 +47,8 @@ class ErrorController(BaseController): """ def __before__(self): - pass#disable all base actions since we don't need them here + #disable all base actions since we don't need them here + pass def document(self): resp = request.environ.get('pylons.original_response') @@ -55,23 +57,20 @@ class ErrorController(BaseController): log.debug('### %s ###', resp.status) e = request.environ - c.serv_p = r'%(protocol)s://%(host)s/' % { - 'protocol': e.get('wsgi.url_scheme'), - 'host':e.get('HTTP_HOST'), - } - + c.serv_p = r'%(protocol)s://%(host)s/' \ + % {'protocol': e.get('wsgi.url_scheme'), + 'host': e.get('HTTP_HOST'), } c.error_message = cgi.escape(request.GET.get('code', str(resp.status))) c.error_explanation = self.get_error_explanation(resp.status_int) - #redirect to when error with given seconds + # redirect to when error with given seconds c.redirect_time = 0 - c.redirect_module = _('Home page')# name to what your going to be redirected + c.redirect_module = _('Home page') c.url_redirect = "/" return render('/errors/error_document.html') - def img(self, id): """Serve Pylons' stock images""" return self._serve_file(os.path.join(media_path, 'img', id)) @@ -96,7 +95,8 @@ class ErrorController(BaseController): code = 500 if code == 400: - return _('The request could not be understood by the server due to malformed syntax.') + return _('The request could not be understood by the server' + ' due to malformed syntax.') if code == 401: return _('Unauthorized access to resource') if code == 403: @@ -104,4 +104,5 @@ class ErrorController(BaseController): if code == 404: return _('The resource could not be found') if code == 500: - return _('The server encountered an unexpected condition which prevented it from fulfilling the request.') + return _('The server encountered an unexpected condition' + ' which prevented it from fulfilling the request.') diff --git a/rhodecode/controllers/feed.py b/rhodecode/controllers/feed.py --- a/rhodecode/controllers/feed.py +++ b/rhodecode/controllers/feed.py @@ -35,6 +35,7 @@ from webhelpers.feedgenerator import Ato log = logging.getLogger(__name__) + class FeedController(BaseRepoController): @LoginRequired(api_access=True) @@ -71,7 +72,8 @@ class FeedController(BaseRepoController) def atom(self, repo_name): """Produce an atom-1.0 feed via feedgenerator module""" feed = Atom1Feed(title=self.title % repo_name, - link=url('summary_home', repo_name=repo_name, qualified=True), + link=url('summary_home', repo_name=repo_name, + qualified=True), description=self.description % repo_name, language=self.language, ttl=self.ttl) @@ -89,11 +91,11 @@ class FeedController(BaseRepoController) response.content_type = feed.mime_type return feed.writeString('utf-8') - def rss(self, repo_name): """Produce an rss2 feed via feedgenerator module""" feed = Rss201rev2Feed(title=self.title % repo_name, - link=url('summary_home', repo_name=repo_name, qualified=True), + link=url('summary_home', repo_name=repo_name, + qualified=True), description=self.description % repo_name, language=self.language, ttl=self.ttl) diff --git a/rhodecode/controllers/files.py b/rhodecode/controllers/files.py --- a/rhodecode/controllers/files.py +++ b/rhodecode/controllers/files.py @@ -73,7 +73,6 @@ class FilesController(BaseRepoController h.flash(str(e), category='warning') redirect(h.url('files_home', repo_name=repo_name, revision='tip')) - def __get_filenode_or_redirect(self, repo_name, cs, path): """ Returns file_node, if error occurs or given path is directory, @@ -84,7 +83,6 @@ class FilesController(BaseRepoController :param path: path to lookup """ - try: file_node = cs.get_node(path) if file_node.is_dir(): @@ -104,7 +102,6 @@ class FilesController(BaseRepoController redirect(url('files_home', repo_name=c.repo_name, revision=cs.raw_id, f_path=f_path)) - c.changeset = self.__get_cs_or_redirect(revision, repo_name) c.branch = request.GET.get('branch', None) c.f_path = f_path @@ -144,7 +141,6 @@ class FilesController(BaseRepoController redirect(h.url('files_home', repo_name=repo_name, revision=revision)) - return render('files/files.html') def rawfile(self, repo_name, revision, f_path): @@ -205,7 +201,6 @@ class FilesController(BaseRepoController return cs.get_chunked_archive(stream=None, kind=fileformat) - def diff(self, repo_name, f_path): diff1 = request.GET.get('diff1') diff2 = request.GET.get('diff2') @@ -231,7 +226,6 @@ class FilesController(BaseRepoController return redirect(url('files_home', repo_name=c.repo_name, f_path=f_path)) - if c.action == 'download': diff = differ.DiffProcessor(differ.get_gitdiff(node1, node2), format='gitdiff') @@ -252,7 +246,8 @@ class FilesController(BaseRepoController if node1.is_binary or node2.is_binary: c.cur_diff = _('Binary file') - elif node1.size > self.cut_off_limit or node2.size > self.cut_off_limit: + elif node1.size > self.cut_off_limit or \ + node2.size > self.cut_off_limit: c.cur_diff = _('Diff is too big to display') else: diff = differ.DiffProcessor(differ.get_gitdiff(node1, node2), @@ -263,7 +258,8 @@ class FilesController(BaseRepoController #default option if node1.is_binary or node2.is_binary: c.cur_diff = _('Binary file') - elif node1.size > self.cut_off_limit or node2.size > self.cut_off_limit: + elif node1.size > self.cut_off_limit or \ + node2.size > self.cut_off_limit: c.cur_diff = _('Diff is too big to display') else: diff = differ.DiffProcessor(differ.get_gitdiff(node1, node2), diff --git a/rhodecode/controllers/home.py b/rhodecode/controllers/home.py --- a/rhodecode/controllers/home.py +++ b/rhodecode/controllers/home.py @@ -35,6 +35,7 @@ from rhodecode.lib.base import BaseContr log = logging.getLogger(__name__) + class HomeController(BaseController): @LoginRequired() diff --git a/rhodecode/controllers/journal.py b/rhodecode/controllers/journal.py --- a/rhodecode/controllers/journal.py +++ b/rhodecode/controllers/journal.py @@ -41,10 +41,9 @@ from rhodecode.model.db import UserLog, log = logging.getLogger(__name__) + class JournalController(BaseController): - - def __before__(self): super(JournalController, self).__before__() self.rhodecode_user = self.rhodecode_user @@ -75,12 +74,11 @@ class JournalController(BaseController): return c.journal_data return render('journal/journal.html') - def _get_daily_aggregate(self, journal): groups = [] - for k, g in groupby(journal, lambda x:x.action_as_day): + for k, g in groupby(journal, lambda x: x.action_as_day): user_group = [] - for k2, g2 in groupby(list(g), lambda x:x.user.email): + for k2, g2 in groupby(list(g), lambda x: x.user.email): l = list(g2) user_group.append((l[0].user, l)) @@ -88,7 +86,6 @@ class JournalController(BaseController): return groups - def _get_journal_data(self, following_repos): repo_ids = [x.follows_repository.repo_id for x in following_repos if x.follows_repository is not None] @@ -113,7 +110,6 @@ class JournalController(BaseController): else: journal = [] - return journal @LoginRequired() @@ -127,7 +123,7 @@ class JournalController(BaseController): if user_id: try: self.scm_model.toggle_following_user(user_id, - self.rhodecode_user.user_id) + self.rhodecode_user.user_id) return 'ok' except: raise HTTPBadRequest() @@ -136,17 +132,14 @@ class JournalController(BaseController): if repo_id: try: self.scm_model.toggle_following_repo(repo_id, - self.rhodecode_user.user_id) + self.rhodecode_user.user_id) return 'ok' except: raise HTTPBadRequest() - log.debug('token mismatch %s vs %s', cur_token, token) raise HTTPBadRequest() - - @LoginRequired() def public_journal(self): # Return a rendered template @@ -168,7 +161,6 @@ class JournalController(BaseController): return c.journal_data return render('journal/public_journal.html') - @LoginRequired(api_access=True) def public_journal_atom(self): """ diff --git a/rhodecode/controllers/login.py b/rhodecode/controllers/login.py --- a/rhodecode/controllers/login.py +++ b/rhodecode/controllers/login.py @@ -41,6 +41,7 @@ from rhodecode.model.user import UserMod log = logging.getLogger(__name__) + class LoginController(BaseController): def __before__(self): @@ -93,7 +94,8 @@ class LoginController(BaseController): def register(self): user_model = UserModel() c.auto_active = False - for perm in user_model.get_by_username('default', cache=False).user_perms: + for perm in user_model.get_by_username('default', + cache=False).user_perms: if perm.permission.permission_name == 'hg.register.auto_activate': c.auto_active = True break diff --git a/rhodecode/controllers/search.py b/rhodecode/controllers/search.py --- a/rhodecode/controllers/search.py +++ b/rhodecode/controllers/search.py @@ -41,6 +41,7 @@ from whoosh.query import Phrase log = logging.getLogger(__name__) + class SearchController(BaseController): @LoginRequired() @@ -53,13 +54,12 @@ class SearchController(BaseController): c.runtime = '' c.cur_query = request.GET.get('q', None) c.cur_type = request.GET.get('type', 'source') - c.cur_search = search_type = {'content':'content', - 'commit':'content', - 'path':'path', - 'repository':'repository'}\ + c.cur_search = search_type = {'content': 'content', + 'commit': 'content', + 'path': 'path', + 'repository': 'repository'}\ .get(c.cur_type, 'content') - if c.cur_query: cur_query = c.cur_query.lower() @@ -67,8 +67,8 @@ class SearchController(BaseController): p = int(request.params.get('page', 1)) highlight_items = set() try: - idx = open_dir(config['app_conf']['index_dir'] - , indexname=IDX_NAME) + idx = open_dir(config['app_conf']['index_dir'], + indexname=IDX_NAME) searcher = idx.searcher() qp = QueryParser(search_type, schema=SCHEMA) @@ -103,7 +103,6 @@ class SearchController(BaseController): page=p, item_count=res_ln, items_per_page=10, url=url_generator) - except QueryParserError: c.runtime = _('Invalid search query. Try quoting it.') searcher.close() diff --git a/rhodecode/controllers/settings.py b/rhodecode/controllers/settings.py --- a/rhodecode/controllers/settings.py +++ b/rhodecode/controllers/settings.py @@ -46,6 +46,7 @@ from rhodecode.model.db import User log = logging.getLogger(__name__) + class SettingsController(BaseRepoController): @LoginRequired() @@ -72,11 +73,11 @@ class SettingsController(BaseRepoControl #fill owner if c.repo_info.user: - defaults.update({'user':c.repo_info.user.username}) + defaults.update({'user': c.repo_info.user.username}) else: replacement_user = self.sa.query(User)\ .filter(User.admin == True).first().username - defaults.update({'user':replacement_user}) + defaults.update({'user': replacement_user}) #fill repository users for p in c.repo_info.repo_to_perm: @@ -99,7 +100,8 @@ class SettingsController(BaseRepoControl def update(self, repo_name): repo_model = RepoModel() changed_name = repo_name - _form = RepoSettingsForm(edit=True, old_data={'repo_name':repo_name})() + _form = RepoSettingsForm(edit=True, + old_data={'repo_name': repo_name})() try: form_result = _form.to_python(dict(request.POST)) repo_model.update(repo_name, form_result) @@ -112,7 +114,7 @@ class SettingsController(BaseRepoControl except formencode.Invalid, errors: c.repo_info = repo_model.get_by_repo_name(repo_name) c.users_array = repo_model.get_users_js() - errors.value.update({'user':c.repo_info.user.username}) + errors.value.update({'user': c.repo_info.user.username}) return htmlfill.render( render('settings/repo_settings.html'), defaults=errors.value, @@ -126,7 +128,6 @@ class SettingsController(BaseRepoControl return redirect(url('repo_settings_home', repo_name=changed_name)) - @HasRepoPermissionAllDecorator('repository.admin') def delete(self, repo_name): """DELETE /repos/repo_name: Delete an existing item""" @@ -182,11 +183,11 @@ class SettingsController(BaseRepoControl def fork_create(self, repo_name): repo_model = RepoModel() c.repo_info = repo_model.get_by_repo_name(repo_name) - _form = RepoForkForm(old_data={'repo_type':c.repo_info.repo_type})() + _form = RepoForkForm(old_data={'repo_type': c.repo_info.repo_type})() form_result = {} try: form_result = _form.to_python(dict(request.POST)) - form_result.update({'repo_name':repo_name}) + form_result.update({'repo_name': repo_name}) repo_model.create_fork(form_result, self.rhodecode_user) h.flash(_('forked %s repository as %s') \ % (repo_name, form_result['fork_name']), diff --git a/rhodecode/controllers/shortlog.py b/rhodecode/controllers/shortlog.py --- a/rhodecode/controllers/shortlog.py +++ b/rhodecode/controllers/shortlog.py @@ -34,8 +34,6 @@ from rhodecode.lib.helpers import RepoPa log = logging.getLogger(__name__) - - class ShortlogController(BaseRepoController): @LoginRequired() @@ -46,7 +44,8 @@ class ShortlogController(BaseRepoControl def index(self): p = int(request.params.get('page', 1)) - c.repo_changesets = RepoPage(c.rhodecode_repo, page=p, items_per_page=20) + c.repo_changesets = RepoPage(c.rhodecode_repo, page=p, + items_per_page=20) c.shortlog_data = render('shortlog/shortlog_data.html') if request.params.get('partial'): return c.shortlog_data diff --git a/rhodecode/controllers/summary.py b/rhodecode/controllers/summary.py --- a/rhodecode/controllers/summary.py +++ b/rhodecode/controllers/summary.py @@ -51,6 +51,7 @@ except ImportError: import simplejson as json log = logging.getLogger(__name__) + class SummaryController(BaseRepoController): @LoginRequired() @@ -65,14 +66,13 @@ class SummaryController(BaseRepoControll c.dbrepo = dbrepo = Repository.by_repo_name(repo_name) c.following = self.scm_model.is_following_repo(repo_name, - self.rhodecode_user.user_id) + self.rhodecode_user.user_id) + def url_generator(**kw): return url('shortlog_home', repo_name=repo_name, **kw) - c.repo_changesets = RepoPage(c.rhodecode_repo, page=1, items_per_page=10, - url=url_generator) - - + c.repo_changesets = RepoPage(c.rhodecode_repo, page=1, + items_per_page=10, url=url_generator) if self.rhodecode_user.username == 'default': #for default(anonymous) user we don't need to pass credentials @@ -82,13 +82,13 @@ class SummaryController(BaseRepoControll username = str(self.rhodecode_user.username) password = '@' - uri = u'%(protocol)s://%(user)s%(password)s%(host)s%(prefix)s/%(repo_name)s' % { - 'protocol': e.get('wsgi.url_scheme'), - 'user':username, - 'password':password, - 'host':e.get('HTTP_HOST'), - 'prefix':e.get('SCRIPT_NAME'), - 'repo_name':repo_name, } + uri = u'%(proto)s://%(user)s%(pass)s%(host)s%(prefix)s/%(repo_name)s' \ + % {'proto': e.get('wsgi.url_scheme'), + 'user': username, + 'pass': password, + 'host': e.get('HTTP_HOST'), + 'prefix': e.get('SCRIPT_NAME'), + 'repo_name': repo_name, } c.clone_repo_url = uri c.repo_tags = OrderedDict() for name, hash in c.rhodecode_repo.tags.items()[:10]: @@ -146,7 +146,7 @@ class SummaryController(BaseRepoControll c.repo_last_rev) * 100) else: c.commit_data = json.dumps({}) - c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 10] ]) + c.overview_data = json.dumps([[ts_min_y, 0], [ts_max_y, 10]]) c.trending_languages = json.dumps({}) c.no_data = True @@ -156,8 +156,6 @@ class SummaryController(BaseRepoControll return render('summary/summary.html') - - def _get_download_links(self, repo): download_l = [] diff --git a/rhodecode/controllers/tags.py b/rhodecode/controllers/tags.py --- a/rhodecode/controllers/tags.py +++ b/rhodecode/controllers/tags.py @@ -32,6 +32,7 @@ from rhodecode.lib.utils import OrderedD log = logging.getLogger(__name__) + class TagsController(BaseRepoController): @LoginRequired() @@ -45,7 +46,7 @@ class TagsController(BaseRepoController) tags = [(name, c.rhodecode_repo.get_changeset(hash_)) for \ name, hash_ in c.rhodecode_repo.tags.items()] - ordered_tags = sorted(tags, key=lambda x:x[1].date, reverse=True) + ordered_tags = sorted(tags, key=lambda x: x[1].date, reverse=True) for name, cs_tag in ordered_tags: c.repo_tags[name] = cs_tag