# HG changeset patch # User Mads Kiilerich # Date 1581035910 -3600 # Node ID b6b6955981a55dc3737a5d5160316b0168426745 # Parent d122a95326306fd5ef85aae9442af392650db19f cleanup: drop some dead code spotted by "vulture" diff -r d122a9532630 -r b6b6955981a5 docs/api/models.rst --- a/docs/api/models.rst Thu Feb 06 02:38:25 2020 +0100 +++ b/docs/api/models.rst Fri Feb 07 01:38:30 2020 +0100 @@ -13,9 +13,6 @@ .. automodule:: kallithea.model.permission :members: -.. automodule:: kallithea.model.repo_permission - :members: - .. automodule:: kallithea.model.repo :members: diff -r d122a9532630 -r b6b6955981a5 kallithea/controllers/admin/repo_groups.py --- a/kallithea/controllers/admin/repo_groups.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/controllers/admin/repo_groups.py Fri Feb 07 01:38:30 2020 +0100 @@ -101,7 +101,6 @@ _list = RepoGroup.query(sorted=True).all() group_iter = RepoGroupList(_list, perm_level='admin') repo_groups_data = [] - total_records = len(group_iter) _tmpl_lookup = app_globals.mako_lookup template = _tmpl_lookup.get_template('data_table/_dt_elements.html') diff -r d122a9532630 -r b6b6955981a5 kallithea/controllers/admin/user_groups.py --- a/kallithea/controllers/admin/user_groups.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/controllers/admin/user_groups.py Fri Feb 07 01:38:30 2020 +0100 @@ -86,7 +86,6 @@ .all() group_iter = UserGroupList(_list, perm_level='admin') user_groups_data = [] - total_records = len(group_iter) _tmpl_lookup = app_globals.mako_lookup template = _tmpl_lookup.get_template('data_table/_dt_elements.html') diff -r d122a9532630 -r b6b6955981a5 kallithea/controllers/admin/users.py --- a/kallithea/controllers/admin/users.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/controllers/admin/users.py Fri Feb 07 01:38:30 2020 +0100 @@ -70,7 +70,6 @@ .all() users_data = [] - total_records = len(c.users_list) _tmpl_lookup = app_globals.mako_lookup template = _tmpl_lookup.get_template('data_table/_dt_elements.html') diff -r d122a9532630 -r b6b6955981a5 kallithea/controllers/changeset.py --- a/kallithea/controllers/changeset.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/controllers/changeset.py Fri Feb 07 01:38:30 2020 +0100 @@ -215,7 +215,6 @@ return { 'location': h.url('my_pullrequests'), # or repo pr list? } - raise HTTPFound(location=h.url('my_pullrequests')) # or repo pr list? raise HTTPForbidden() text = request.POST.get('text', '').strip() diff -r d122a9532630 -r b6b6955981a5 kallithea/lib/db_manage.py --- a/kallithea/lib/db_manage.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/lib/db_manage.py Fri Feb 07 01:38:30 2020 +0100 @@ -54,7 +54,6 @@ self.tests = tests self.root = root self.dburi = dbconf - self.db_exists = False self.cli_args = cli_args or {} self.init_db(SESSION=SESSION) diff -r d122a9532630 -r b6b6955981a5 kallithea/lib/exceptions.py --- a/kallithea/lib/exceptions.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/lib/exceptions.py Fri Feb 07 01:38:30 2020 +0100 @@ -74,9 +74,5 @@ pass -class RepositoryCreationError(Exception): - pass - - class HgsubversionImportError(Exception): pass diff -r d122a9532630 -r b6b6955981a5 kallithea/lib/middleware/sessionmiddleware.py --- a/kallithea/lib/middleware/sessionmiddleware.py Thu Feb 06 02:38:25 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -# -*- 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 . -""" -kallithea.lib.middleware.sessionmiddleware -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -session management middleware - -This file overrides Beaker's built-in SessionMiddleware -class to automagically use secure cookies over HTTPS. - -Original Beaker SessionMiddleware class written by Ben Bangert -""" - -from beaker.middleware import SessionMiddleware -from beaker.session import SessionObject - - -class SecureSessionMiddleware(SessionMiddleware): - def __call__(self, environ, start_response): - """ - This function's implementation is taken directly from Beaker, - with HTTPS detection added. When accessed over HTTPS, force - setting cookie's secure flag. - - The only difference from that original code is that we switch - the secure option on and off depending on the URL scheme (first - two lines). To avoid concurrency issues, we use a local options - variable. - """ - options = dict(self.options) - options["secure"] = environ['wsgi.url_scheme'] == 'https' - - session = SessionObject(environ, **options) - if environ.get('paste.registry'): - if environ['paste.registry'].reglist: - environ['paste.registry'].register(self.session, session) - environ[self.environ_key] = session - environ['beaker.get_session'] = self._get_session - - if 'paste.testing_variables' in environ and 'webtest_varname' in options: - environ['paste.testing_variables'][options['webtest_varname']] = session - - def session_start_response(status, headers, exc_info=None): - if session.accessed(): - session.persist() - if session.__dict__['_headers']['set_cookie']: - cookie = session.__dict__['_headers']['cookie_out'] - if cookie: - headers.append(('Set-cookie', cookie)) - return start_response(status, headers, exc_info) - return self.wrap_app(environ, session_start_response) diff -r d122a9532630 -r b6b6955981a5 kallithea/lib/rcmail/message.py --- a/kallithea/lib/rcmail/message.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/lib/rcmail/message.py Fri Feb 07 01:38:30 2020 +0100 @@ -2,35 +2,6 @@ from kallithea.lib.rcmail.response import MailResponse -class Attachment(object): - """ - Encapsulates file attachment information. - - :param filename: filename of attachment - :param content_type: file mimetype - :param data: the raw file data, either as string or file obj - :param disposition: content-disposition (if any) - """ - - def __init__(self, - filename=None, - content_type=None, - data=None, - disposition=None): - - self.filename = filename - self.content_type = content_type - self.disposition = disposition or 'attachment' - self._data = data - - @property - def data(self): - if isinstance(self._data, str): - return self._data - self._data = self._data.read() - return self._data - - class Message(object): """ Encapsulates an email message. diff -r d122a9532630 -r b6b6955981a5 kallithea/lib/rcmail/response.py --- a/kallithea/lib/rcmail/response.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/lib/rcmail/response.py Fri Feb 07 01:38:30 2020 +0100 @@ -392,7 +392,7 @@ if mail.body is None: return # only None, '' is still ok - ctype, ctype_params = mail.content_encoding['Content-Type'] + ctype, _ctype_params = mail.content_encoding['Content-Type'] cdisp, cdisp_params = mail.content_encoding['Content-Disposition'] assert ctype, ("Extract payload requires that mail.content_encoding " diff -r d122a9532630 -r b6b6955981a5 kallithea/lib/vcs/backends/base.py --- a/kallithea/lib/vcs/backends/base.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/lib/vcs/backends/base.py Fri Feb 07 01:38:30 2020 +0100 @@ -258,8 +258,6 @@ """ Persists current changes made on this repository and returns newly created changeset. - - :raises ``NothingChangedError``: if no changes has been made """ raise NotImplementedError diff -r d122a9532630 -r b6b6955981a5 kallithea/lib/vcs/exceptions.py --- a/kallithea/lib/vcs/exceptions.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/lib/vcs/exceptions.py Fri Feb 07 01:38:30 2020 +0100 @@ -30,10 +30,6 @@ pass -class BranchAlreadyExistError(RepositoryError): - pass - - class BranchDoesNotExistError(RepositoryError): pass @@ -50,10 +46,6 @@ pass -class NothingChangedError(CommitError): - pass - - class NodeError(VCSError): pass @@ -88,7 +80,3 @@ class ImproperArchiveTypeError(VCSError): pass - - -class CommandError(VCSError): - pass diff -r d122a9532630 -r b6b6955981a5 kallithea/lib/vcs/subprocessio.py --- a/kallithea/lib/vcs/subprocessio.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/lib/vcs/subprocessio.py Fri Feb 07 01:38:30 2020 +0100 @@ -221,17 +221,6 @@ return not self.worker.keep_reading.is_set() @property - def done_reading_event(self): - """ - Done_reading does not mean that the iterator's buffer is empty. - Iterator might have done reading from underlying source, but the read - chunks might still be available for serving through .next() method. - - :returns: An threading.Event class instance. - """ - return self.worker.EOF - - @property def done_reading(self): """ Done_reading does not mean that the iterator's buffer is empty. diff -r d122a9532630 -r b6b6955981a5 kallithea/lib/vcs/utils/lazy.py --- a/kallithea/lib/vcs/utils/lazy.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/lib/vcs/utils/lazy.py Fri Feb 07 01:38:30 2020 +0100 @@ -1,6 +1,3 @@ -import threading - - class _Missing(object): def __repr__(self): @@ -44,21 +41,3 @@ value = self._func(obj) obj.__dict__[self.__name__] = value return value - - -class ThreadLocalLazyProperty(LazyProperty): - """ - Same as above but uses thread local dict for cache storage. - """ - - def __get__(self, obj, klass=None): - if obj is None: - return self - if not hasattr(obj, '__tl_dict__'): - obj.__tl_dict__ = threading.local().__dict__ - - value = obj.__tl_dict__.get(self.__name__, _missing) - if value is _missing: - value = self._func(obj) - obj.__tl_dict__[self.__name__] = value - return value diff -r d122a9532630 -r b6b6955981a5 kallithea/lib/vcs/utils/paths.py --- a/kallithea/lib/vcs/utils/paths.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/lib/vcs/utils/paths.py Fri Feb 07 01:38:30 2020 +0100 @@ -11,7 +11,7 @@ for path in paths: head = path while head: - head, tail = os.path.split(head) + head, _tail = os.path.split(head) if head: yield head else: diff -r d122a9532630 -r b6b6955981a5 kallithea/model/notification.py --- a/kallithea/model/notification.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/model/notification.py Fri Feb 07 01:38:30 2020 +0100 @@ -33,7 +33,6 @@ from tg import tmpl_context as c from tg.i18n import ugettext as _ -import kallithea from kallithea.lib import helpers as h from kallithea.model.db import User @@ -149,7 +148,6 @@ def __init__(self): super(EmailNotificationModel, self).__init__() - self._template_root = kallithea.CONFIG['paths']['templates'][0] self._tmpl_lookup = app_globals.mako_lookup self.email_types = { self.TYPE_CHANGESET_COMMENT: 'changeset_comment', diff -r d122a9532630 -r b6b6955981a5 kallithea/model/repo_permission.py --- a/kallithea/model/repo_permission.py Thu Feb 06 02:38:25 2020 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -# -*- 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 . -""" -kallithea.model.repo_permission -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -repository permission model for Kallithea - -This file was forked by the Kallithea project in July 2014. -Original author and date, and relevant copyright and licensing information is below: -:created_on: Oct 1, 2011 -:author: nvinot, marcink -""" - -import logging - -from kallithea.model.db import Permission, Repository, Session, User, UserGroupRepoToPerm, UserRepoToPerm - - -log = logging.getLogger(__name__) - - -class RepositoryPermissionModel(object): - - def get_user_permission(self, repository, user): - repository = Repository.guess_instance(repository) - user = User.guess_instance(user) - - return UserRepoToPerm.query() \ - .filter(UserRepoToPerm.user == user) \ - .filter(UserRepoToPerm.repository == repository) \ - .scalar() - - def update_user_permission(self, repository, user, permission): - permission = Permission.get_by_key(permission) - current = self.get_user_permission(repository, user) - if current: - if current.permission is not permission: - current.permission = permission - else: - p = UserRepoToPerm() - p.user = user - p.repository = repository - p.permission = permission - Session().add(p) - - def delete_user_permission(self, repository, user): - current = self.get_user_permission(repository, user) - if current: - Session().delete(current) - - def get_users_group_permission(self, repository, users_group): - return UserGroupRepoToPerm.query() \ - .filter(UserGroupRepoToPerm.users_group == users_group) \ - .filter(UserGroupRepoToPerm.repository == repository) \ - .scalar() - - def update_users_group_permission(self, repository, users_group, - permission): - permission = Permission.get_by_key(permission) - current = self.get_users_group_permission(repository, users_group) - if current: - if current.permission is not permission: - current.permission = permission - else: - p = UserGroupRepoToPerm() - p.users_group = users_group - p.repository = repository - p.permission = permission - Session().add(p) - - def delete_users_group_permission(self, repository, users_group): - current = self.get_users_group_permission(repository, users_group) - if current: - Session().delete(current) - - def update_or_delete_user_permission(self, repository, user, permission): - if permission: - self.update_user_permission(repository, user, permission) - else: - self.delete_user_permission(repository, user) - - def update_or_delete_users_group_permission(self, repository, user_group, - permission): - if permission: - self.update_users_group_permission(repository, user_group, - permission) - else: - self.delete_users_group_permission(repository, user_group) diff -r d122a9532630 -r b6b6955981a5 kallithea/model/ssh_key.py --- a/kallithea/model/ssh_key.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/model/ssh_key.py Fri Feb 07 01:38:30 2020 +0100 @@ -52,7 +52,7 @@ Will raise SshKeyModelException on errors """ try: - keytype, pub, comment = ssh.parse_pub_key(public_key) + keytype, _pub, comment = ssh.parse_pub_key(public_key) except ssh.SshKeyParseError as e: raise SshKeyModelException(_('SSH key %r is invalid: %s') % (public_key, e.args[0])) if not description.strip(): diff -r d122a9532630 -r b6b6955981a5 kallithea/model/validators.py --- a/kallithea/model/validators.py Thu Feb 06 02:38:25 2020 +0100 +++ b/kallithea/model/validators.py Fri Feb 07 01:38:30 2020 +0100 @@ -584,11 +584,11 @@ for k, v, t in perms_new: try: if t == 'user': - self.user_db = User.query() \ + _user_db = User.query() \ .filter(User.active == True) \ .filter(User.username == k).one() if t == 'users_group': - self.user_db = UserGroup.query() \ + _user_db = UserGroup.query() \ .filter(UserGroup.users_group_active == True) \ .filter(UserGroup.users_group_name == k).one()