Pull request #61 from kallithea-incoming#default

Title: Turbogears2 migration: preparatory commits (v2) (Closed)

Here are three commits originating from the tg2 branch, that can already be applied on current Pylons-based Kallithea.
Goal of this delivery is to make the 'real' Turbogears2 migration a smaller, more clear diff.

In v2 I think I adressed the comments, except for .ini file migration instructions (to be added to wiki and later release notes / manual).

--
This is a new iteration of https://kallithea-scm.org/repos/kallithea/pull-request/60 "Turbogears2 migration: preparatory commits".
Missing changesets since the previous iteration:
b60dc56eebfd "Turbogears2 migration: replace pylons.url by kallithea.lib.utils.url"
b2a608ed109e "Turbogears2 migration: use sqlalchemy.url iso sqlalchemy.db1.url"
5e9c82e429ec "Turbogears2 migration: remove some references to Pylons in comments"
New changesets on branch default since the previous iteration:
f65144842edc Turbogears2 migration: remove some references to Pylons in comments
4e53d2a4f00d Turbogears2 migration: use sqlalchemy.url iso sqlalchemy.db1.url
c2d5d4fbc79f Turbogears2 migration: replace pylons.url by kallithea.config.routing.url
Ancestor didn't change - diff since previous iteration:
https://kallithea-scm.org/repos/kallithea-incoming/compare/rev@5e9c82e429ec...rev@f65144842edc
Closed, Under review
hg pull https://kallithea-scm.org/repos/kallithea-incoming -r f65144842edc
2016-09-17 20:26:22
Thomas De Schampheleire (patrickdp)
thomas.de.schampheleire@gmail.com

This pull request has been closed and can not be updated.

Reviewers

  • Andrej Shadura (andrewsh)
  • Søren Løvborg (kwi)
  • Dominik Ruf (domruf)
  • Mads Kiilerich (kiilerix)
Pull Request Content
13 comments (0 inline, 13 general) First comment
Showing 3 commits
3 patrickdp f65144842edc
9 years ago
Draft default
2 patrickdp 4e53d2a4f00d
9 years ago
3 Draft default
1 patrickdp c2d5d4fbc79f
9 years ago
Draft default
Common ancestor: 591effa1fc4d
41 files changed with 151 insertions and 97 deletions:
development.ini
Show inline comments
 
@@ -484,18 +484,18 @@ logview.pylons.util = #eee
 
#########################################################
 

	
 
# SQLITE [default]
 
sqlalchemy.db1.url = sqlite:///%(here)s/kallithea.db?timeout=60
 
sqlalchemy.url = sqlite:///%(here)s/kallithea.db?timeout=60
 

	
 
# POSTGRESQL
 
#sqlalchemy.db1.url = postgresql://user:pass@localhost/kallithea
 
#sqlalchemy.url = postgresql://user:pass@localhost/kallithea
 

	
 
# MySQL
 
#sqlalchemy.db1.url = mysql://user:pass@localhost/kallithea?charset=utf8
 
#sqlalchemy.url = mysql://user:pass@localhost/kallithea?charset=utf8
 

	
 
# see sqlalchemy docs for others
 

	
 
sqlalchemy.db1.echo = false
 
sqlalchemy.db1.pool_recycle = 3600
 
sqlalchemy.echo = false
 
sqlalchemy.pool_recycle = 3600
 

	
 
################################
 
### ALEMBIC CONFIGURATION   ####
docs/upgrade.rst
Show inline comments
 
@@ -54,7 +54,7 @@ utility.
 
If using MySQL, please consult the documentation for the ``mysqldump``
 
utility.
 

	
 
Look for ``sqlalchemy.db1.url`` in your configuration file to determine
 
Look for ``sqlalchemy.url`` in your configuration file to determine
 
database type, settings, location, etc.
 

	
 

	
kallithea/__init__.py
Show inline comments
 
@@ -15,8 +15,9 @@
 
kallithea
 
~~~~~~~~~
 

	
 
Kallithea, a web based repository management based on pylons
 
versioning implementation: http://www.python.org/dev/peps/pep-0386/
 
Kallithea, a web based repository management system.
 

	
 
Versioning implementation: http://www.python.org/dev/peps/pep-0386/
 

	
 
This file was forked by the Kallithea project in July 2014.
 
Original author and date, and relevant copyright and licensing information is below:
 
@@ -38,7 +39,6 @@ BACKENDS = {
 
CELERY_ON = False
 
CELERY_EAGER = False
 

	
 
# link to config for pylons
 
CONFIG = {}
 

	
 
# Linked module for extensions
kallithea/alembic/env.py
Show inline comments
 
@@ -31,7 +31,7 @@ config = context.config
 
# [alembic] sqlalchemy.url.
 
database_url = (
 
    config.get_main_option('sqlalchemy.url') or
 
    config.get_section_option('app:main', 'sqlalchemy.db1.url')
 
    config.get_section_option('app:main', 'sqlalchemy.url')
 
)
 

	
 
# Configure default logging for Alembic. (This can be overriden by the
kallithea/bin/template.ini.mako
Show inline comments
 
@@ -484,21 +484,21 @@ logview.pylons.util = #eee
 

	
 
%if database_engine == 'sqlite':
 
# SQLITE [default]
 
sqlalchemy.db1.url = sqlite:///${here}/kallithea.db?timeout=60
 
sqlalchemy.url = sqlite:///${here}/kallithea.db?timeout=60
 

	
 
%elif database_engine == 'postgres':
 
# POSTGRESQL
 
sqlalchemy.db1.url = postgresql://user:pass@localhost/kallithea
 
sqlalchemy.url = postgresql://user:pass@localhost/kallithea
 

	
 
%elif database_engine == 'mysql':
 
# MySQL
 
sqlalchemy.db1.url = mysql://user:pass@localhost/kallithea?charset=utf8
 
sqlalchemy.url = mysql://user:pass@localhost/kallithea?charset=utf8
 

	
 
%endif
 
# see sqlalchemy docs for others
 

	
 
sqlalchemy.db1.echo = false
 
sqlalchemy.db1.pool_recycle = 3600
 
sqlalchemy.echo = false
 
sqlalchemy.pool_recycle = 3600
 

	
 
<%text>################################</%text>
 
<%text>### ALEMBIC CONFIGURATION   ####</%text>
kallithea/config/deployment.ini_tmpl
Show inline comments
 
@@ -476,18 +476,18 @@ logview.pylons.util = #eee
 
#########################################################
 

	
 
# SQLITE [default]
 
sqlalchemy.db1.url = sqlite:///%(here)s/kallithea.db?timeout=60
 
sqlalchemy.url = sqlite:///%(here)s/kallithea.db?timeout=60
 

	
 
# POSTGRESQL
 
#sqlalchemy.db1.url = postgresql://user:pass@localhost/kallithea
 
#sqlalchemy.url = postgresql://user:pass@localhost/kallithea
 

	
 
# MySQL
 
#sqlalchemy.db1.url = mysql://user:pass@localhost/kallithea?charset=utf8
 
#sqlalchemy.url = mysql://user:pass@localhost/kallithea?charset=utf8
 

	
 
# see sqlalchemy docs for others
 

	
 
sqlalchemy.db1.echo = false
 
sqlalchemy.db1.pool_recycle = 3600
 
sqlalchemy.echo = false
 
sqlalchemy.pool_recycle = 3600
 

	
 
################################
 
### ALEMBIC CONFIGURATION   ####
kallithea/config/environment.py
Show inline comments
 
@@ -93,7 +93,7 @@ def load_environment(global_conf, app_co
 
            test_index = not int(os.environ.get('KALLITHEA_WHOOSH_TEST_DISABLE', 0))
 
        if os.environ.get('TEST_DB'):
 
            # swap config if we pass enviroment variable
 
            config['sqlalchemy.db1.url'] = os.environ.get('TEST_DB')
 
            config['sqlalchemy.url'] = os.environ.get('TEST_DB')
 

	
 
        from kallithea.lib.utils import create_test_env, create_test_index
 
        from kallithea.tests import TESTS_TMP_PATH
 
@@ -107,8 +107,8 @@ def load_environment(global_conf, app_co
 

	
 
    # MULTIPLE DB configs
 
    # Setup the SQLAlchemy database engine
 
    sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.')
 
    init_model(sa_engine_db1)
 
    sa_engine = engine_from_config(config, 'sqlalchemy.')
 
    init_model(sa_engine)
 

	
 
    set_available_permissions(config)
 
    repos_path = make_ui('db').configitems('paths')[0][1]
kallithea/config/routing.py
Show inline comments
 
@@ -19,6 +19,7 @@ may take precedent over the more generic
 
refer to the routes manual at http://routes.groovie.org/docs/
 
"""
 

	
 
from pylons import request
 
from routes import Mapper
 

	
 
# prefix for non repository related links needs to be prefixed with `/`
 
@@ -800,3 +801,29 @@ def make_map(config):
 
                 conditions=dict(function=check_repo))
 

	
 
    return rmap
 

	
 

	
 
class UrlGenerator(object):
 
    """Emulate pylons.url in providing a wrapper around routes.url
 

	
 
    This code was added during migration from Pylons to Turbogears2. Pylons
 
    already provided a wrapper like this, but Turbogears2 does not.
 

	
 
    When the routing of Kallithea is changed to use less Routes and more
 
    Turbogears2-style routing, this class may disappear or change.
 

	
 
    url() (the __call__ method) returns the URL based on a route name and
 
    arguments.
 
    url.current() returns the URL of the current page with arguments applied.
 

	
 
    Refer to documentation of Routes for details:
 
    https://routes.readthedocs.io/en/latest/generating.html#generation
 
    """
 
    def __call__(self, *args, **kwargs):
 
        return request.environ['routes.url'](*args, **kwargs)
 
    def current(self, *args, **kwargs):
 
        return request.environ['routes.url'].current(*args, **kwargs)
 

	
 
url = UrlGenerator()
 

	
 

	
kallithea/controllers/admin/admin.py
Show inline comments
 
@@ -28,13 +28,14 @@ Original author and date, and relevant c
 

	
 
import logging
 

	
 
from pylons import request, tmpl_context as c, url
 
from pylons import request, tmpl_context as c
 
from sqlalchemy.orm import joinedload
 
from whoosh.qparser.default import QueryParser
 
from whoosh.qparser.dateparse import DateParserPlugin
 
from whoosh import query
 
from sqlalchemy.sql.expression import or_, and_, func
 

	
 
from kallithea.config.routing import url
 
from kallithea.model.db import UserLog
 
from kallithea.lib.auth import LoginRequired, HasPermissionAnyDecorator
 
from kallithea.lib.base import BaseController, render
kallithea/controllers/admin/auth_settings.py
Show inline comments
 
@@ -27,10 +27,11 @@ import logging
 
import formencode.htmlfill
 
import traceback
 

	
 
from pylons import request, tmpl_context as c, url
 
from pylons import request, tmpl_context as c
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib import helpers as h
 
from kallithea.lib.compat import formatted_json
 
from kallithea.lib.base import BaseController, render
kallithea/controllers/admin/defaults.py
Show inline comments
 
@@ -30,10 +30,11 @@ import traceback
 
import formencode
 
from formencode import htmlfill
 

	
 
from pylons import request, tmpl_context as c, url
 
from pylons import request, tmpl_context as c
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib import helpers as h
 
from kallithea.lib.auth import LoginRequired, HasPermissionAnyDecorator
 
from kallithea.lib.base import BaseController, render
kallithea/controllers/admin/gists.py
Show inline comments
 
@@ -30,10 +30,11 @@ import logging
 
import traceback
 
import formencode.htmlfill
 

	
 
from pylons import request, response, tmpl_context as c, url
 
from pylons import request, response, tmpl_context as c
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound, HTTPNotFound, HTTPForbidden
 

	
 
from kallithea.config.routing import url
 
from kallithea.model.forms import GistForm
 
from kallithea.model.gist import GistModel
 
from kallithea.model.meta import Session
kallithea/controllers/admin/my_account.py
Show inline comments
 
@@ -31,10 +31,11 @@ import formencode
 

	
 
from sqlalchemy import func
 
from formencode import htmlfill
 
from pylons import request, tmpl_context as c, url
 
from pylons import request, tmpl_context as c
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib import helpers as h
 
from kallithea.lib import auth_modules
 
from kallithea.lib.auth import LoginRequired, NotAnonymous, AuthUser
kallithea/controllers/admin/permissions.py
Show inline comments
 
@@ -31,10 +31,11 @@ import traceback
 
import formencode
 
from formencode import htmlfill
 

	
 
from pylons import request, tmpl_context as c, url
 
from pylons import request, tmpl_context as c
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib import helpers as h
 
from kallithea.lib.auth import LoginRequired, HasPermissionAnyDecorator
 
from kallithea.lib.base import BaseController, render
kallithea/controllers/admin/repo_groups.py
Show inline comments
 
@@ -32,11 +32,12 @@ import itertools
 

	
 
from formencode import htmlfill
 

	
 
from pylons import request, tmpl_context as c, url
 
from pylons import request, tmpl_context as c
 
from pylons.i18n.translation import _, ungettext
 
from webob.exc import HTTPFound, HTTPForbidden, HTTPNotFound, HTTPInternalServerError
 

	
 
import kallithea
 
from kallithea.config.routing import url
 
from kallithea.lib import helpers as h
 
from kallithea.lib.compat import json
 
from kallithea.lib.auth import LoginRequired, \
kallithea/controllers/admin/repos.py
Show inline comments
 
@@ -29,11 +29,12 @@ import logging
 
import traceback
 
import formencode
 
from formencode import htmlfill
 
from pylons import request, tmpl_context as c, url
 
from pylons import request, tmpl_context as c
 
from pylons.i18n.translation import _
 
from sqlalchemy.sql.expression import func
 
from webob.exc import HTTPFound, HTTPInternalServerError, HTTPForbidden, HTTPNotFound
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib import helpers as h
 
from kallithea.lib.auth import LoginRequired, \
 
    HasRepoPermissionAnyDecorator, NotAnonymous, HasPermissionAny
kallithea/controllers/admin/settings.py
Show inline comments
 
@@ -30,10 +30,11 @@ import traceback
 
import formencode
 

	
 
from formencode import htmlfill
 
from pylons import request, tmpl_context as c, url, config
 
from pylons import request, tmpl_context as c, config
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib import helpers as h
 
from kallithea.lib.auth import LoginRequired, HasPermissionAnyDecorator
 
from kallithea.lib.base import BaseController, render
kallithea/controllers/admin/user_groups.py
Show inline comments
 
@@ -15,7 +15,7 @@
 
kallithea.controllers.admin.user_groups
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
User Groups crud controller for pylons
 
User Groups crud controller
 

	
 
This file was forked by the Kallithea project in July 2014.
 
Original author and date, and relevant copyright and licensing information is below:
 
@@ -30,7 +30,7 @@ import traceback
 
import formencode
 

	
 
from formencode import htmlfill
 
from pylons import request, tmpl_context as c, url, config
 
from pylons import request, tmpl_context as c, config
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound
 

	
 
@@ -39,6 +39,7 @@ from sqlalchemy.sql.expression import fu
 
from webob.exc import HTTPInternalServerError
 

	
 
import kallithea
 
from kallithea.config.routing import url
 
from kallithea.lib import helpers as h
 
from kallithea.lib.exceptions import UserGroupsAssignedException, \
 
    RepoGroupAssignmentError
kallithea/controllers/admin/users.py
Show inline comments
 
@@ -15,7 +15,7 @@
 
kallithea.controllers.admin.users
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
Users crud controller for pylons
 
Users crud controller
 

	
 
This file was forked by the Kallithea project in July 2014.
 
Original author and date, and relevant copyright and licensing information is below:
 
@@ -30,12 +30,13 @@ import traceback
 
import formencode
 

	
 
from formencode import htmlfill
 
from pylons import request, tmpl_context as c, url, config
 
from pylons import request, tmpl_context as c, config
 
from pylons.i18n.translation import _
 
from sqlalchemy.sql.expression import func
 
from webob.exc import HTTPFound, HTTPNotFound
 

	
 
import kallithea
 
from kallithea.config.routing import url
 
from kallithea.lib.exceptions import DefaultUserException, \
 
    UserOwnsReposException, UserCreationError
 
from kallithea.lib import helpers as h
kallithea/controllers/changelog.py
Show inline comments
 
@@ -28,11 +28,12 @@ Original author and date, and relevant c
 
import logging
 
import traceback
 

	
 
from pylons import request, url, session, tmpl_context as c
 
from pylons import request, session, tmpl_context as c
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound, HTTPNotFound, HTTPBadRequest
 

	
 
import kallithea.lib.helpers as h
 
from kallithea.config.routing import url
 
from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
 
from kallithea.lib.base import BaseRepoController, render
 
from kallithea.lib.helpers import RepoPage
kallithea/controllers/changeset.py
Show inline comments
 
@@ -15,8 +15,7 @@
 
kallithea.controllers.changeset
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
changeset controller for pylons showing changes between
 
revisions
 
changeset controller showing changes between revisions
 

	
 
This file was forked by the Kallithea project in July 2014.
 
Original author and date, and relevant copyright and licensing information is below:
kallithea/controllers/compare.py
Show inline comments
 
@@ -15,7 +15,7 @@
 
kallithea.controllers.compare
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
compare controller for pylons showing differences between two
 
compare controller showing differences between two
 
repos, branches, bookmarks or tips
 

	
 
This file was forked by the Kallithea project in July 2014.
 
@@ -30,10 +30,11 @@ Original author and date, and relevant c
 
import logging
 
import re
 

	
 
from pylons import request, tmpl_context as c, url
 
from pylons import request, tmpl_context as c
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound, HTTPBadRequest
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib.utils2 import safe_str, safe_int
 
from kallithea.lib.vcs.utils.hgcompat import unionrepo
 
from kallithea.lib import helpers as h
kallithea/controllers/files.py
Show inline comments
 
@@ -32,10 +32,11 @@ import traceback
 
import tempfile
 
import shutil
 

	
 
from pylons import request, response, tmpl_context as c, url
 
from pylons import request, response, tmpl_context as c
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib.utils import jsonify, action_logger
 
from kallithea.lib import diffs
 
from kallithea.lib import helpers as h
kallithea/controllers/forks.py
Show inline comments
 
@@ -30,12 +30,13 @@ import formencode
 
import traceback
 
from formencode import htmlfill
 

	
 
from pylons import tmpl_context as c, request, url
 
from pylons import tmpl_context as c, request
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound
 

	
 
import kallithea.lib.helpers as h
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib.helpers import Page
 
from kallithea.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator, \
 
    NotAnonymous, HasRepoPermissionAny, HasPermissionAnyDecorator, HasPermissionAny
kallithea/controllers/journal.py
Show inline comments
 
@@ -15,7 +15,7 @@
 
kallithea.controllers.journal
 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

	
 
Journal controller for pylons
 
Journal controller
 

	
 
This file was forked by the Kallithea project in July 2014.
 
Original author and date, and relevant copyright and licensing information is below:
 
@@ -37,9 +37,10 @@ from sqlalchemy.sql.expression import fu
 
from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
 

	
 
from webob.exc import HTTPBadRequest
 
from pylons import request, tmpl_context as c, response, url
 
from pylons import request, tmpl_context as c, response
 
from pylons.i18n.translation import _
 

	
 
from kallithea.config.routing import url
 
from kallithea.controllers.admin.admin import _journal_filter
 
from kallithea.model.db import UserLog, UserFollowing, Repository, User
 
from kallithea.model.meta import Session
kallithea/controllers/login.py
Show inline comments
 
@@ -32,10 +32,11 @@ import formencode
 

	
 
from formencode import htmlfill
 
from pylons.i18n.translation import _
 
from pylons import request, session, tmpl_context as c, url
 
from pylons import request, session, tmpl_context as c
 
from webob.exc import HTTPFound, HTTPBadRequest
 

	
 
import kallithea.lib.helpers as h
 
from kallithea.config.routing import url
 
from kallithea.lib.auth import AuthUser, HasPermissionAnyDecorator
 
from kallithea.lib.base import BaseController, log_in_user, render
 
from kallithea.lib.exceptions import UserCreationError
kallithea/controllers/pullrequests.py
Show inline comments
 
@@ -30,10 +30,11 @@ import traceback
 
import formencode
 
import re
 

	
 
from pylons import request, tmpl_context as c, url
 
from pylons import request, tmpl_context as c
 
from pylons.i18n.translation import _
 
from webob.exc import HTTPFound, HTTPNotFound, HTTPForbidden, HTTPBadRequest
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib.vcs.utils.hgcompat import unionrepo
 
from kallithea.lib.compat import json, OrderedDict
 
from kallithea.lib.base import BaseRepoController, render
kallithea/lib/auth.py
Show inline comments
 
@@ -34,7 +34,7 @@ import collections
 

	
 
from decorator import decorator
 

	
 
from pylons import url, request, session
 
from pylons import request, session
 
from pylons.i18n.translation import _
 
from webhelpers.pylonslib import secure_form
 
from sqlalchemy import or_
 
@@ -43,6 +43,7 @@ from sqlalchemy.orm import joinedload
 
from webob.exc import HTTPFound, HTTPBadRequest, HTTPForbidden, HTTPMethodNotAllowed
 

	
 
from kallithea import __platform__, is_windows, is_unix
 
from kallithea.config.routing import url
 
from kallithea.lib.vcs.utils.lazy import LazyProperty
 
from kallithea.model import meta
 
from kallithea.model.meta import Session
 
@@ -679,12 +680,12 @@ class AuthUser(object):
 

	
 
def set_available_permissions(config):
 
    """
 
    This function will propagate pylons globals with all available defined
 
    This function will propagate globals with all available defined
 
    permission given in db. We don't want to check each time from db for new
 
    permissions since adding a new permission also requires application restart
 
    ie. to decorate new views with the newly created permission
 

	
 
    :param config: current pylons config instance
 
    :param config: current config instance
 

	
 
    """
 
    log.info('getting information about all available permissions')
kallithea/lib/base.py
Show inline comments
 
@@ -38,13 +38,14 @@ import paste.httpexceptions
 
import paste.auth.basic
 
import paste.httpheaders
 

	
 
from pylons import config, tmpl_context as c, request, session, url
 
from pylons import config, tmpl_context as c, request, session
 
from pylons.controllers import WSGIController
 
from pylons.templating import render_mako as render  # don't remove this import
 
from pylons.i18n.translation import _
 

	
 
from kallithea import __version__, BACKENDS
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib.utils2 import str2bool, safe_unicode, AttributeDict, \
 
    safe_str, safe_int
 
from kallithea.lib import auth_modules
kallithea/lib/celerylib/__init__.py
Show inline comments
 
@@ -122,7 +122,7 @@ def locked_task(func):
 

	
 
def get_session():
 
    if CELERY_ON:
 
        engine = engine_from_config(config, 'sqlalchemy.db1.')
 
        engine = engine_from_config(config, 'sqlalchemy.')
 
        init_model(engine)
 
    sa = meta.Session()
 
    return sa
kallithea/lib/helpers.py
Show inline comments
 
@@ -28,7 +28,6 @@ import textwrap
 
from beaker.cache import cache_region
 
from pygments.formatters.html import HtmlFormatter
 
from pygments import highlight as code_highlight
 
from pylons import url
 
from pylons.i18n.translation import _, ungettext
 

	
 
from webhelpers.html import literal, HTML, escape
 
@@ -52,6 +51,7 @@ from webhelpers.paginate import Page as 
 
from webhelpers.html.tags import _set_input_attrs, _set_id_attr, \
 
    convert_boolean_attrs, NotGiven, _make_safe_id_component
 

	
 
from kallithea.config.routing import url
 
from kallithea.lib.annotate import annotate_highlight
 
from kallithea.lib.utils import repo_name_slug, get_custom_lexer
 
from kallithea.lib.utils2 import str2bool, safe_unicode, safe_str, \
 
@@ -866,7 +866,7 @@ def gravatar(email_address, cls='', size
 

	
 
def gravatar_url(email_address, size=30, default=''):
 
    # doh, we need to re-import those to mock it later
 
    from pylons import url
 
    from kallithea.config.routing import url
 
    from pylons import tmpl_context as c
 
    if not c.visual.use_gravatar:
 
        return ""
 
@@ -1290,7 +1290,7 @@ def urlify_text(s, repo_name=None, link_
 
            return '<b>%s</b>' % mention
 
        hash_ = match_obj.group('hash')
 
        if hash_ is not None and repo_name is not None:
 
            from pylons import url  # doh, we need to re-import url to mock it later
 
            from kallithea.config.routing import url  # doh, we need to re-import url to mock it later
 
            return '<a class="revision-link" href="%(url)s">%(hash)s</a>' % {
 
                 'url': url('changeset_home', repo_name=repo_name, revision=hash_),
 
                 'hash': hash_,
kallithea/lib/hooks.py
Show inline comments
 
@@ -373,8 +373,8 @@ def handle_git_post_receive(repo_path, r
 
def handle_git_receive(repo_path, revs, env, hook_type):
 
    """
 
    A really hacky method that is run by git post-receive hook and logs
 
    an push action together with pushed revisions. It's executed by subprocess
 
    thus needs all info to be able to create a on the fly pylons environment,
 
    a push action together with pushed revisions. It's executed by subprocess
 
    thus needs all info to be able to create an on the fly app environment,
 
    connect to database and run the logging code. Hacky as sh*t but works.
 

	
 
    :param repo_path:
 
@@ -395,7 +395,7 @@ def handle_git_receive(repo_path, revs, 
 
    load_environment(conf.global_conf, conf.local_conf, test_env=False,
 
                     test_index=False)
 

	
 
    engine = engine_from_config(conf, 'sqlalchemy.db1.')
 
    engine = engine_from_config(conf, 'sqlalchemy.')
 
    init_model(engine)
 

	
 
    baseui = make_ui('db')
kallithea/lib/paster_commands/common.py
Show inline comments
 
@@ -85,7 +85,7 @@ class BasePasterCommand(Command):
 

	
 
    def bootstrap_config(self, conf):
 
        """
 
        Loads the pylons configuration.
 
        Loads the app configuration.
 
        """
 
        from pylons import config as pylonsconfig
 

	
 
@@ -103,5 +103,5 @@ class BasePasterCommand(Command):
 
        from kallithea.model import init_model
 
        from kallithea.lib.utils2 import engine_from_config
 
        setup_cache_regions(config)
 
        engine = engine_from_config(config, 'sqlalchemy.db1.')
 
        engine = engine_from_config(config, 'sqlalchemy.')
 
        init_model(engine)
kallithea/lib/utils.py
Show inline comments
 
@@ -378,7 +378,7 @@ def make_ui(read_from='file', path=None,
 

	
 
def set_app_settings(config):
 
    """
 
    Updates pylons config with new settings from database
 
    Updates app config with new settings from database
 

	
 
    :param config:
 
    """
 
@@ -632,7 +632,7 @@ def create_test_env(repos_test_path, con
 
    from kallithea.tests import HG_REPO, GIT_REPO, TESTS_TMP_PATH
 

	
 
    # PART ONE create db
 
    dbconf = config['sqlalchemy.db1.url']
 
    dbconf = config['sqlalchemy.url']
 
    log.debug('making test db %s', dbconf)
 

	
 
    # create test dir if it doesn't exist
kallithea/tests/__init__.py
Show inline comments
 
@@ -13,12 +13,7 @@
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
"""
 
Pylons application test package
 

	
 
This package assumes the Pylons environment is already loaded.
 

	
 
This module initializes the application via ``websetup`` (`paster
 
setup-app`) and provides the base testing objects.
 
Kallithea test package
 

	
 
Refer to docs/contributing.rst for details on running the test suite.
 
"""
kallithea/tests/other/test_libs.py
Show inline comments
 
@@ -66,6 +66,24 @@ TEST_URLS += [
 
     '%s://example.com:8080' % proto),
 
]
 

	
 
class FakeUrlGenerator(object):
 

	
 
    def __init__(self, current_url=None, default_route=None, **routes):
 
        """Initialize using specified 'current' URL template,
 
        default route template, and all other aguments describing known
 
        routes (format: route=template)"""
 
        self.current_url = current_url
 
        self.default_route = default_route
 
        self.routes = routes
 

	
 
    def __call__(self, route_name, *args, **kwargs):
 
        if route_name in self.routes:
 
            return self.routes[route_name] % kwargs
 

	
 
        return self.default_route % kwargs
 

	
 
    def current(self, *args, **kwargs):
 
        return self.current_url % kwargs
 

	
 
class TestLibs(TestController):
 

	
 
@@ -202,12 +220,6 @@ class TestLibs(TestController):
 
        from kallithea.lib.helpers import gravatar_url
 
        _md5 = lambda s: hashlib.md5(s).hexdigest()
 

	
 
        #mock pylons.url
 
        class fake_url(object):
 
            @classmethod
 
            def current(cls, *args, **kwargs):
 
                return 'https://example.com'
 

	
 
        #mock pylons.tmpl_context
 
        def fake_tmpl_context(_url):
 
            _c = AttributeDict()
 
@@ -217,11 +229,11 @@ class TestLibs(TestController):
 

	
 
            return _c
 

	
 

	
 
        with mock.patch('pylons.url', fake_url):
 
        fake_url = FakeUrlGenerator(current_url='https://example.com')
 
        with mock.patch('kallithea.config.routing.url', fake_url):
 
            fake = fake_tmpl_context(_url='http://example.com/{email}')
 
            with mock.patch('pylons.tmpl_context', fake):
 
                    from pylons import url
 
                    from kallithea.config.routing import url
 
                    assert url.current() == 'https://example.com'
 
                    grav = gravatar_url(email_address='test@example.com', size=24)
 
                    assert grav == 'http://example.com/test@example.com'
 
@@ -283,7 +295,7 @@ class TestLibs(TestController):
 

	
 
        def url_func(match_obj):
 
            _url = match_obj.groups()[0]
 
            return tmpl % (url_ or '/some-url', _url)
 
            return tmpl % (url_ or '/repo_name/changeset/%s' % _url, _url)
 
        return URL_PAT.sub(url_func, text)
 

	
 
    @parametrize('sample,expected', [
 
@@ -314,12 +326,9 @@ class TestLibs(TestController):
 
       """       sometimes !"""),
 
    ])
 
    def test_urlify_text(self, sample, expected):
 
        def fake_url(self, *args, **kwargs):
 
            return '/some-url'
 

	
 
        expected = self._quick_url(expected)
 

	
 
        with mock.patch('pylons.url', fake_url):
 
        fake_url = FakeUrlGenerator(changeset_home='/%(repo_name)s/changeset/%(revision)s')
 
        with mock.patch('kallithea.config.routing.url', fake_url):
 
            from kallithea.lib.helpers import urlify_text
 
            assert urlify_text(sample, 'repo_name') == expected
 

	
 
@@ -368,10 +377,12 @@ class TestLibs(TestController):
 
      # tags are covered by test_tag_extractor
 
    ])
 
    def test_urlify_test(self, sample, expected, url_):
 
        from kallithea.lib.helpers import urlify_text
 
        expected = self._quick_url(expected,
 
                                   tmpl="""<a href="%s">%s</a>""", url_=url_)
 
        assert urlify_text(sample, 'repo_name', stylize=True) == expected
 
        fake_url = FakeUrlGenerator(changeset_home='/%(repo_name)s/changeset/%(revision)s')
 
        with mock.patch('kallithea.config.routing.url', fake_url):
 
            from kallithea.lib.helpers import urlify_text
 
            assert urlify_text(sample, 'repo_name', stylize=True) == expected
 

	
 
    @parametrize('sample,expected', [
 
      ("deadbeefcafe @mention, and http://foo.bar/ yo",
 
@@ -381,8 +392,10 @@ class TestLibs(TestController):
 
       """<a class="message-link" href="#the-link"> yo</a>"""),
 
    ])
 
    def test_urlify_link(self, sample, expected):
 
        from kallithea.lib.helpers import urlify_text
 
        assert urlify_text(sample, 'repo_name', link_='#the-link') == expected
 
        fake_url = FakeUrlGenerator(changeset_home='/%(repo_name)s/changeset/%(revision)s')
 
        with mock.patch('kallithea.config.routing.url', fake_url):
 
            from kallithea.lib.helpers import urlify_text
 
            assert urlify_text(sample, 'repo_name', link_='#the-link') == expected
 

	
 
    @parametrize('test,expected', [
 
      ("", None),
kallithea/tests/scripts/manual_test_concurrency.py
Show inline comments
 
@@ -82,7 +82,7 @@ class Command(object):
 

	
 

	
 
def get_session():
 
    engine = engine_from_config(conf, 'sqlalchemy.db1.')
 
    engine = engine_from_config(conf, 'sqlalchemy.')
 
    init_model(engine)
 
    sa = meta.Session
 
    return sa
kallithea/tests/test.ini
Show inline comments
 
@@ -488,19 +488,19 @@ logview.pylons.util = #eee
 
#########################################################
 

	
 
# SQLITE [default]
 
#sqlalchemy.db1.url = sqlite:///%(here)s/kallithea.db?timeout=60
 
sqlalchemy.db1.url = sqlite:///%(here)s/kallithea_test.sqlite
 
#sqlalchemy.url = sqlite:///%(here)s/kallithea.db?timeout=60
 
sqlalchemy.url = sqlite:///%(here)s/kallithea_test.sqlite
 

	
 
# POSTGRESQL
 
#sqlalchemy.db1.url = postgresql://user:pass@localhost/kallithea
 
#sqlalchemy.url = postgresql://user:pass@localhost/kallithea
 

	
 
# MySQL
 
#sqlalchemy.db1.url = mysql://user:pass@localhost/kallithea?charset=utf8
 
#sqlalchemy.url = mysql://user:pass@localhost/kallithea?charset=utf8
 

	
 
# see sqlalchemy docs for others
 

	
 
sqlalchemy.db1.echo = false
 
sqlalchemy.db1.pool_recycle = 3600
 
sqlalchemy.echo = false
 
sqlalchemy.pool_recycle = 3600
 

	
 
################################
 
### ALEMBIC CONFIGURATION   ####
kallithea/websetup.py
Show inline comments
 
@@ -37,7 +37,7 @@ log = logging.getLogger(__name__)
 

	
 
def setup_app(command, conf, vars):
 
    """Place any commands to setup kallithea here"""
 
    dbconf = conf['sqlalchemy.db1.url']
 
    dbconf = conf['sqlalchemy.url']
 
    dbmanage = DbManage(log_sql=True, dbconf=dbconf, root=conf['here'],
 
                        tests=False, cli_args=command.options.__dict__)
 
    dbmanage.create_tables(override=True)
scripts/dbmigrate-test
Show inline comments
 
modified file chmod 100755 => 100644
 
@@ -65,7 +65,7 @@ temp=$(readlink -f "$(mktemp --tmpdir -d
 
cat <<EOD
 
Config file:    $config_file
 
EOD
 
sed -n -e 's/^sqlalchemy\.db1\.url *= */Database URL:   /p' "$config_file"
 
sed -n -e 's/^sqlalchemy\.url *= */Database URL:   /p' "$config_file"
 
cat <<EOD
 
Working dir:    $temp
 
Repository:     $source_repo
scripts/generate-ini.py
Show inline comments
 
modified file chmod 100755 => 100644
 
@@ -60,7 +60,7 @@ ini_files = [
 
                'archive_cache_dir': '%(here)s/../../data/test/tarballcache',
 
                'beaker.cache.data_dir': '%(here)s/../../data/test/cache/data',
 
                'beaker.cache.lock_dir': '%(here)s/../../data/test/cache/lock',
 
                'sqlalchemy.db1.url': 'sqlite:///%(here)s/kallithea_test.sqlite',
 
                'sqlalchemy.url': 'sqlite:///%(here)s/kallithea_test.sqlite',
 
            },
 
            '[handler_console]': {
 
                'level': 'DEBUG',
13 comments (0 inline, 13 general) First comment
Thomas De Schampheleire (patrickdp) 8 years and 8 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"

Status change: Under review

Mads Kiilerich (kiilerix) 8 years and 8 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"
Thanks. I pushed the 2 changesets that didn't change since first iteration.

I will wait for a closer look, second opinion, and testing on the last changeset.

I like that the url method now lives so closely together with the routes definition it relies on instead of being in util like everything else. The extra import makes it explicit that routing depends on pylons. But also, in the existing code, that dependency is indirectly, by environment.py inserting make_map result in config['routes.map']. I guess people could have an opinion on that. Like if it would be better if the url dependency on pylons somehow was indirectly too.
Thomas De Schampheleire (patrickdp) 8 years and 8 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"
The pylons dependency in UrlGenerator is only for pylons.request.environ['routes.url']. It is not _really_ a dependency on pylons, but rather pylons happens to be the 'messenger' that we use to obtain a handle to the environment.

If we can get to the correct 'routes.url' via another path, I guess it could work just as fine.
For example, is 'pylons.request.environ['routes.url']' actually different than 'routes.url' ?
Mads Kiilerich (kiilerix) 8 years and 8 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"
Yes, all this to get to the right Mapper instance created by make_map ...

I don't think there is a 'routes.url' - it is set in the environment by RoutesMiddleware as a UrlGenerator instance based on the 'routes.map' config set in load_environment.

I wonder how this would fit together in a clean TG2 app ...
Thomas De Schampheleire (patrickdp) 8 years and 8 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"
I don't think a clean tg2 app uses Routes.
Thomas De Schampheleire (patrickdp) 8 years and 8 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"
I don't think a clean tg2 app uses Routes.
Mads Kiilerich (kiilerix) 8 years and 8 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"
Even without routes, there might be a pattern we can learn from.
Søren Løvborg (kwi) 8 years and 8 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"
Once make_map is called (during startup/config phase), the route map doesn't change again. It seems to me that it would thus be cleanest to simply store the route map in a module-level variable, and keep it as an internal implementation details of the kallithea.config.routing module.

Code speaks louder than words, so see db1f0a6adcae for the gist of it.
Søren Løvborg (kwi) 8 years and 8 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"
Søren Løvborg (kwi) 8 years and 8 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"
In general, I think it's fine to store static config data in global variables, as long as there's a well-defined "barrier" between time-of-definition and time-of-use. In the case of url, there's no reasonable use-case for generating URLs in the startup/config phase, so it's straightforward.

(On the other hand, kallithea.CONFIG and the associated problems are caused by the lack of a well-defined barrier.)
Thomas De Schampheleire (patrickdp) 8 years and 8 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"
As I commented on the commit, the implementation does not look right to me.

Note by the way that in my rcextensions package, I add a new route to the mapper. I would prefer that to continue working, of course.
Søren Løvborg (kwi) 8 years and 8 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"

Status change: Approved

Yes, disregard my comment. (I still think my approach is the *right* one, except for the pesky detail that it admittedly doesn't actually *work*.) ;-)

Let's stick to this, then.
Thomas De Schampheleire (patrickdp) 8 years and 7 months ago comment on pull request "Turbogears2 migration: preparatory commits (v2)"
These have landed...
You need to be logged in to comment. Login now