changeset 8229:b6b6955981a5

cleanup: drop some dead code spotted by "vulture"
author Mads Kiilerich <mads@kiilerich.com>
date Fri, 07 Feb 2020 01:38:30 +0100
parents d122a9532630
children 563708f2275d
files docs/api/models.rst kallithea/controllers/admin/repo_groups.py kallithea/controllers/admin/user_groups.py kallithea/controllers/admin/users.py kallithea/controllers/changeset.py kallithea/lib/db_manage.py kallithea/lib/exceptions.py kallithea/lib/middleware/sessionmiddleware.py kallithea/lib/rcmail/message.py kallithea/lib/rcmail/response.py kallithea/lib/vcs/backends/base.py kallithea/lib/vcs/exceptions.py kallithea/lib/vcs/subprocessio.py kallithea/lib/vcs/utils/lazy.py kallithea/lib/vcs/utils/paths.py kallithea/model/notification.py kallithea/model/repo_permission.py kallithea/model/ssh_key.py kallithea/model/validators.py
diffstat 19 files changed, 5 insertions(+), 257 deletions(-) [+]
line wrap: on
line diff
--- 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:
 
--- 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')
 
--- 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')
 
--- 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')
 
--- 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()
--- 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)
 
--- 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
--- 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 <http://www.gnu.org/licenses/>.
-"""
-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)
--- 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.
--- 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 "
--- 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
 
--- 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
--- 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.
--- 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
--- 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:
--- 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',
--- 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 <http://www.gnu.org/licenses/>.
-"""
-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)
--- 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():
--- 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()