##// END OF EJS Templates
lib: drop own asbool implementation and consistently use tg.support.converters as utils2.asbool...
Mads Kiilerich -
r8286:cf062064 default
parent child Browse files
Show More
@@ -21,7 +21,7 b' import click'
21
21
22 import kallithea
22 import kallithea
23 import kallithea.bin.kallithea_cli_base as cli_base
23 import kallithea.bin.kallithea_cli_base as cli_base
24 from kallithea.lib.utils2 import str2bool
24 from kallithea.lib.utils2 import asbool
25 from kallithea.lib.vcs.backends.git.ssh import GitSshHandler
25 from kallithea.lib.vcs.backends.git.ssh import GitSshHandler
26 from kallithea.lib.vcs.backends.hg.ssh import MercurialSshHandler
26 from kallithea.lib.vcs.backends.hg.ssh import MercurialSshHandler
27 from kallithea.model.ssh_key import SshKeyModel, SshKeyModelException
27 from kallithea.model.ssh_key import SshKeyModel, SshKeyModelException
@@ -40,8 +40,7 b' def ssh_serve(user_id, key_id):'
40 protocol access. The access will be granted as the specified user ID, and
40 protocol access. The access will be granted as the specified user ID, and
41 logged as using the specified key ID.
41 logged as using the specified key ID.
42 """
42 """
43 ssh_enabled = kallithea.CONFIG.get('ssh_enabled', False)
43 if not asbool(kallithea.CONFIG.get('ssh_enabled', False)):
44 if not str2bool(ssh_enabled):
45 sys.stderr.write("SSH access is disabled.\n")
44 sys.stderr.write("SSH access is disabled.\n")
46 return sys.exit(1)
45 return sys.exit(1)
47
46
@@ -29,7 +29,6 b' from alembic.migration import MigrationC'
29 from alembic.script.base import ScriptDirectory
29 from alembic.script.base import ScriptDirectory
30 from sqlalchemy import create_engine
30 from sqlalchemy import create_engine
31 from tg.configuration import AppConfig
31 from tg.configuration import AppConfig
32 from tg.support.converters import asbool
33
32
34 import kallithea.lib.locale
33 import kallithea.lib.locale
35 import kallithea.model.base
34 import kallithea.model.base
@@ -41,7 +40,7 b' from kallithea.lib.middleware.simplegit '
41 from kallithea.lib.middleware.simplehg import SimpleHg
40 from kallithea.lib.middleware.simplehg import SimpleHg
42 from kallithea.lib.middleware.wrapper import RequestWrapper
41 from kallithea.lib.middleware.wrapper import RequestWrapper
43 from kallithea.lib.utils import check_git_version, load_rcextensions, set_app_settings, set_indexer_config, set_vcs_config
42 from kallithea.lib.utils import check_git_version, load_rcextensions, set_app_settings, set_indexer_config, set_vcs_config
44 from kallithea.lib.utils2 import str2bool
43 from kallithea.lib.utils2 import asbool
45 from kallithea.model import db
44 from kallithea.model import db
46
45
47
46
@@ -160,7 +159,7 b' def setup_configuration(app):'
160 # store some globals into kallithea
159 # store some globals into kallithea
161 kallithea.DEFAULT_USER_ID = db.User.get_default_user().user_id
160 kallithea.DEFAULT_USER_ID = db.User.get_default_user().user_id
162
161
163 if str2bool(config.get('use_celery')):
162 if asbool(config.get('use_celery')):
164 kallithea.CELERY_APP = celerypylons.make_app()
163 kallithea.CELERY_APP = celerypylons.make_app()
165 kallithea.CONFIG = config
164 kallithea.CONFIG = config
166
165
@@ -205,7 +204,7 b' def setup_application(app):'
205 app = PermanentRepoUrl(app, config)
204 app = PermanentRepoUrl(app, config)
206
205
207 # Optional and undocumented wrapper - gives more verbose request/response logging, but has a slight overhead
206 # Optional and undocumented wrapper - gives more verbose request/response logging, but has a slight overhead
208 if str2bool(config.get('use_wsgi_wrapper')):
207 if asbool(config.get('use_wsgi_wrapper')):
209 app = RequestWrapper(app, config)
208 app = RequestWrapper(app, config)
210
209
211 return app
210 return app
@@ -39,7 +39,7 b' from kallithea.lib import helpers as h'
39 from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
39 from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired
40 from kallithea.lib.base import BaseRepoController
40 from kallithea.lib.base import BaseRepoController
41 from kallithea.lib.diffs import DiffProcessor
41 from kallithea.lib.diffs import DiffProcessor
42 from kallithea.lib.utils2 import safe_int, safe_str, str2bool
42 from kallithea.lib.utils2 import asbool, safe_int, safe_str
43
43
44
44
45 log = logging.getLogger(__name__)
45 log = logging.getLogger(__name__)
@@ -92,7 +92,7 b' class FeedController(BaseRepoController)'
92 desc_msg.append(h.urlify_text(cs.message))
92 desc_msg.append(h.urlify_text(cs.message))
93 desc_msg.append('\n')
93 desc_msg.append('\n')
94 desc_msg.extend(changes)
94 desc_msg.extend(changes)
95 if str2bool(CONFIG.get('rss_include_diff', False)):
95 if asbool(CONFIG.get('rss_include_diff', False)):
96 desc_msg.append('\n\n')
96 desc_msg.append('\n\n')
97 desc_msg.append(safe_str(raw_diff))
97 desc_msg.append(safe_str(raw_diff))
98 desc_msg.append('</pre>')
98 desc_msg.append('</pre>')
@@ -46,7 +46,7 b' from kallithea.lib.auth import HasRepoPe'
46 from kallithea.lib.base import BaseRepoController, jsonify, render
46 from kallithea.lib.base import BaseRepoController, jsonify, render
47 from kallithea.lib.exceptions import NonRelativePathError
47 from kallithea.lib.exceptions import NonRelativePathError
48 from kallithea.lib.utils import action_logger
48 from kallithea.lib.utils import action_logger
49 from kallithea.lib.utils2 import convert_line_endings, detect_mode, safe_int, safe_str, str2bool
49 from kallithea.lib.utils2 import asbool, convert_line_endings, detect_mode, safe_int, safe_str
50 from kallithea.lib.vcs.backends.base import EmptyChangeset
50 from kallithea.lib.vcs.backends.base import EmptyChangeset
51 from kallithea.lib.vcs.conf import settings
51 from kallithea.lib.vcs.conf import settings
52 from kallithea.lib.vcs.exceptions import (ChangesetDoesNotExistError, ChangesetError, EmptyRepositoryError, ImproperArchiveTypeError, NodeAlreadyExistsError,
52 from kallithea.lib.vcs.exceptions import (ChangesetDoesNotExistError, ChangesetError, EmptyRepositoryError, ImproperArchiveTypeError, NodeAlreadyExistsError,
@@ -577,7 +577,7 b' class FilesController(BaseRepoController'
577 # to reduce JS and callbacks
577 # to reduce JS and callbacks
578
578
579 if request.GET.get('show_rev'):
579 if request.GET.get('show_rev'):
580 if str2bool(request.GET.get('annotate', 'False')):
580 if asbool(request.GET.get('annotate', 'False')):
581 _url = url('files_annotate_home', repo_name=c.repo_name,
581 _url = url('files_annotate_home', repo_name=c.repo_name,
582 revision=diff1, f_path=c.f_path)
582 revision=diff1, f_path=c.f_path)
583 else:
583 else:
@@ -21,7 +21,7 b' import traceback'
21
21
22 from kallithea.lib.auth import AuthUser, PasswordGenerator
22 from kallithea.lib.auth import AuthUser, PasswordGenerator
23 from kallithea.lib.compat import hybrid_property
23 from kallithea.lib.compat import hybrid_property
24 from kallithea.lib.utils2 import str2bool
24 from kallithea.lib.utils2 import asbool
25 from kallithea.model.db import Setting, User
25 from kallithea.model.db import Setting, User
26 from kallithea.model.meta import Session
26 from kallithea.model.meta import Session
27 from kallithea.model.user import UserModel
27 from kallithea.model.user import UserModel
@@ -350,7 +350,7 b' def authenticate(username, password, env'
350 plugin_settings[v["name"]] = setting.app_settings_value if setting else None
350 plugin_settings[v["name"]] = setting.app_settings_value if setting else None
351 log.debug('Settings for auth plugin %s: %s', plugin_name, plugin_settings)
351 log.debug('Settings for auth plugin %s: %s', plugin_name, plugin_settings)
352
352
353 if not str2bool(plugin_settings["enabled"]):
353 if not asbool(plugin_settings["enabled"]):
354 log.info("Authentication plugin %s is disabled, skipping for %s",
354 log.info("Authentication plugin %s is disabled, skipping for %s",
355 module, username)
355 module, username)
356 continue
356 continue
@@ -29,7 +29,7 b' import logging'
29
29
30 from kallithea.lib import auth_modules
30 from kallithea.lib import auth_modules
31 from kallithea.lib.compat import hybrid_property
31 from kallithea.lib.compat import hybrid_property
32 from kallithea.lib.utils2 import str2bool
32 from kallithea.lib.utils2 import asbool
33 from kallithea.model.db import Setting
33 from kallithea.model.db import Setting
34
34
35
35
@@ -131,7 +131,7 b' class KallitheaAuthPlugin(auth_modules.K'
131 username = environ.get(header)
131 username = environ.get(header)
132 log.debug('extracted %s:%s', header, username)
132 log.debug('extracted %s:%s', header, username)
133
133
134 if username and str2bool(settings.get('clean_username')):
134 if username and asbool(settings.get('clean_username')):
135 log.debug('Received username %s from container', username)
135 log.debug('Received username %s from container', username)
136 username = self._clean_username(username)
136 username = self._clean_username(username)
137 log.debug('New cleanup user is: %s', username)
137 log.debug('New cleanup user is: %s', username)
@@ -49,7 +49,7 b' from kallithea.lib import auth_modules, '
49 from kallithea.lib.auth import AuthUser, HasPermissionAnyMiddleware
49 from kallithea.lib.auth import AuthUser, HasPermissionAnyMiddleware
50 from kallithea.lib.exceptions import UserCreationError
50 from kallithea.lib.exceptions import UserCreationError
51 from kallithea.lib.utils import get_repo_slug, is_valid_repo
51 from kallithea.lib.utils import get_repo_slug, is_valid_repo
52 from kallithea.lib.utils2 import AttributeDict, ascii_bytes, safe_int, safe_str, set_hook_environment, str2bool
52 from kallithea.lib.utils2 import AttributeDict, asbool, ascii_bytes, safe_int, safe_str, set_hook_environment
53 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError
53 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError
54 from kallithea.model import meta
54 from kallithea.model import meta
55 from kallithea.model.db import PullRequest, Repository, Setting, User
55 from kallithea.model.db import PullRequest, Repository, Setting, User
@@ -375,14 +375,14 b' class BaseController(TGController):'
375 c.visual = AttributeDict({})
375 c.visual = AttributeDict({})
376
376
377 ## DB stored
377 ## DB stored
378 c.visual.show_public_icon = str2bool(rc_config.get('show_public_icon'))
378 c.visual.show_public_icon = asbool(rc_config.get('show_public_icon'))
379 c.visual.show_private_icon = str2bool(rc_config.get('show_private_icon'))
379 c.visual.show_private_icon = asbool(rc_config.get('show_private_icon'))
380 c.visual.stylify_metalabels = str2bool(rc_config.get('stylify_metalabels'))
380 c.visual.stylify_metalabels = asbool(rc_config.get('stylify_metalabels'))
381 c.visual.page_size = safe_int(rc_config.get('dashboard_items', 100))
381 c.visual.page_size = safe_int(rc_config.get('dashboard_items', 100))
382 c.visual.admin_grid_items = safe_int(rc_config.get('admin_grid_items', 100))
382 c.visual.admin_grid_items = safe_int(rc_config.get('admin_grid_items', 100))
383 c.visual.repository_fields = str2bool(rc_config.get('repository_fields'))
383 c.visual.repository_fields = asbool(rc_config.get('repository_fields'))
384 c.visual.show_version = str2bool(rc_config.get('show_version'))
384 c.visual.show_version = asbool(rc_config.get('show_version'))
385 c.visual.use_gravatar = str2bool(rc_config.get('use_gravatar'))
385 c.visual.use_gravatar = asbool(rc_config.get('use_gravatar'))
386 c.visual.gravatar_url = rc_config.get('gravatar_url')
386 c.visual.gravatar_url = rc_config.get('gravatar_url')
387
387
388 c.ga_code = rc_config.get('ga_code')
388 c.ga_code = rc_config.get('ga_code')
@@ -404,9 +404,9 b' class BaseController(TGController):'
404 c.clone_ssh_tmpl = rc_config.get('clone_ssh_tmpl') or Repository.DEFAULT_CLONE_SSH
404 c.clone_ssh_tmpl = rc_config.get('clone_ssh_tmpl') or Repository.DEFAULT_CLONE_SSH
405
405
406 ## INI stored
406 ## INI stored
407 c.visual.allow_repo_location_change = str2bool(config.get('allow_repo_location_change', True))
407 c.visual.allow_repo_location_change = asbool(config.get('allow_repo_location_change', True))
408 c.visual.allow_custom_hooks_settings = str2bool(config.get('allow_custom_hooks_settings', True))
408 c.visual.allow_custom_hooks_settings = asbool(config.get('allow_custom_hooks_settings', True))
409 c.ssh_enabled = str2bool(config.get('ssh_enabled', False))
409 c.ssh_enabled = asbool(config.get('ssh_enabled', False))
410
410
411 c.instance_id = config.get('instance_id')
411 c.instance_id = config.get('instance_id')
412 c.issues_url = config.get('bugtracker', url('issues_url'))
412 c.issues_url = config.get('bugtracker', url('issues_url'))
@@ -42,7 +42,7 b' from kallithea.lib.helpers import person'
42 from kallithea.lib.hooks import log_create_repository
42 from kallithea.lib.hooks import log_create_repository
43 from kallithea.lib.rcmail.smtp_mailer import SmtpMailer
43 from kallithea.lib.rcmail.smtp_mailer import SmtpMailer
44 from kallithea.lib.utils import action_logger
44 from kallithea.lib.utils import action_logger
45 from kallithea.lib.utils2 import ascii_bytes, str2bool
45 from kallithea.lib.utils2 import asbool, ascii_bytes
46 from kallithea.lib.vcs.utils import author_email
46 from kallithea.lib.vcs.utils import author_email
47 from kallithea.model.db import RepoGroup, Repository, Statistics, User
47 from kallithea.model.db import RepoGroup, Repository, Statistics, User
48
48
@@ -289,9 +289,9 b' def send_email(recipients, subject, body'
289 passwd = email_config.get('smtp_password')
289 passwd = email_config.get('smtp_password')
290 mail_server = email_config.get('smtp_server')
290 mail_server = email_config.get('smtp_server')
291 mail_port = email_config.get('smtp_port')
291 mail_port = email_config.get('smtp_port')
292 tls = str2bool(email_config.get('smtp_use_tls'))
292 tls = asbool(email_config.get('smtp_use_tls'))
293 ssl = str2bool(email_config.get('smtp_use_ssl'))
293 ssl = asbool(email_config.get('smtp_use_ssl'))
294 debug = str2bool(email_config.get('debug'))
294 debug = asbool(email_config.get('debug'))
295 smtp_auth = email_config.get('smtp_auth')
295 smtp_auth = email_config.get('smtp_auth')
296
296
297 logmsg = ("Mail details:\n"
297 logmsg = ("Mail details:\n"
@@ -48,7 +48,7 b' from kallithea.lib.markup_renderer impor'
48 from kallithea.lib.pygmentsutils import get_custom_lexer
48 from kallithea.lib.pygmentsutils import get_custom_lexer
49 from kallithea.lib.utils2 import MENTIONS_REGEX, AttributeDict
49 from kallithea.lib.utils2 import MENTIONS_REGEX, AttributeDict
50 from kallithea.lib.utils2 import age as _age
50 from kallithea.lib.utils2 import age as _age
51 from kallithea.lib.utils2 import credentials_filter, safe_bytes, safe_int, safe_str, str2bool, time_to_datetime
51 from kallithea.lib.utils2 import asbool, credentials_filter, safe_bytes, safe_int, safe_str, time_to_datetime
52 from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset
52 from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset
53 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError
53 from kallithea.lib.vcs.exceptions import ChangesetDoesNotExistError
54 #==============================================================================
54 #==============================================================================
@@ -526,7 +526,7 b' def show_id(cs):'
526 """
526 """
527 from kallithea import CONFIG
527 from kallithea import CONFIG
528 def_len = safe_int(CONFIG.get('show_sha_length', 12))
528 def_len = safe_int(CONFIG.get('show_sha_length', 12))
529 show_rev = str2bool(CONFIG.get('show_revision_number', False))
529 show_rev = asbool(CONFIG.get('show_revision_number', False))
530
530
531 raw_id = cs.raw_id[:def_len]
531 raw_id = cs.raw_id[:def_len]
532 if show_rev:
532 if show_rev:
@@ -26,7 +26,7 b' Original author and date, and relevant c'
26 """
26 """
27
27
28
28
29 from kallithea.lib.utils2 import str2bool
29 from kallithea.lib.utils2 import asbool
30
30
31
31
32 class HttpsFixup(object):
32 class HttpsFixup(object):
@@ -37,11 +37,11 b' class HttpsFixup(object):'
37
37
38 def __call__(self, environ, start_response):
38 def __call__(self, environ, start_response):
39 self.__fixup(environ)
39 self.__fixup(environ)
40 debug = str2bool(self.config.get('debug'))
40 debug = asbool(self.config.get('debug'))
41 is_ssl = environ['wsgi.url_scheme'] == 'https'
41 is_ssl = environ['wsgi.url_scheme'] == 'https'
42
42
43 def custom_start_response(status, headers, exc_info=None):
43 def custom_start_response(status, headers, exc_info=None):
44 if is_ssl and str2bool(self.config.get('use_htsts')) and not debug:
44 if is_ssl and asbool(self.config.get('use_htsts')) and not debug:
45 headers.append(('Strict-Transport-Security',
45 headers.append(('Strict-Transport-Security',
46 'max-age=8640000; includeSubDomains'))
46 'max-age=8640000; includeSubDomains'))
47 return start_response(status, headers, exc_info)
47 return start_response(status, headers, exc_info)
@@ -66,7 +66,7 b' class HttpsFixup(object):'
66 org_proto = proto
66 org_proto = proto
67
67
68 # if we have force, just override
68 # if we have force, just override
69 if str2bool(self.config.get('force_https')):
69 if asbool(self.config.get('force_https')):
70 proto = 'https'
70 proto = 'https'
71
71
72 environ['wsgi.url_scheme'] = proto
72 environ['wsgi.url_scheme'] = proto
@@ -38,6 +38,7 b' import urllib.parse'
38 import urlobject
38 import urlobject
39 from tg.i18n import ugettext as _
39 from tg.i18n import ugettext as _
40 from tg.i18n import ungettext
40 from tg.i18n import ungettext
41 from tg.support.converters import asbool, aslist
41 from webhelpers2.text import collapse, remove_formatting, strip_tags
42 from webhelpers2.text import collapse, remove_formatting, strip_tags
42
43
43 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, safe_bytes, safe_str # re-export
44 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, safe_bytes, safe_str # re-export
@@ -51,6 +52,8 b' except ImportError:'
51
52
52
53
53 # mute pyflakes "imported but unused"
54 # mute pyflakes "imported but unused"
55 assert asbool
56 assert aslist
54 assert ascii_bytes
57 assert ascii_bytes
55 assert ascii_str
58 assert ascii_str
56 assert safe_bytes
59 assert safe_bytes
@@ -58,44 +61,6 b' assert safe_str'
58 assert LazyProperty
61 assert LazyProperty
59
62
60
63
61 def str2bool(_str):
62 """
63 returns True/False value from given string, it tries to translate the
64 string into boolean
65
66 :param _str: string value to translate into boolean
67 :rtype: boolean
68 :returns: boolean from given string
69 """
70 if _str is None:
71 return False
72 if _str in (True, False):
73 return _str
74 _str = str(_str).strip().lower()
75 return _str in ('t', 'true', 'y', 'yes', 'on', '1')
76
77
78 def aslist(obj, sep=None, strip=True):
79 """
80 Returns given string separated by sep as list
81
82 :param obj:
83 :param sep:
84 :param strip:
85 """
86 if isinstance(obj, (str)):
87 lst = obj.split(sep)
88 if strip:
89 lst = [v.strip() for v in lst]
90 return lst
91 elif isinstance(obj, (list, tuple)):
92 return obj
93 elif obj is None:
94 return []
95 else:
96 return [obj]
97
98
99 def convert_line_endings(line, mode):
64 def convert_line_endings(line, mode):
100 """
65 """
101 Converts a given line "line end" according to given mode
66 Converts a given line "line end" according to given mode
@@ -46,7 +46,7 b' from webob.exc import HTTPNotFound'
46 import kallithea
46 import kallithea
47 from kallithea.lib import ext_json
47 from kallithea.lib import ext_json
48 from kallithea.lib.exceptions import DefaultUserException
48 from kallithea.lib.exceptions import DefaultUserException
49 from kallithea.lib.utils2 import (Optional, ascii_bytes, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_str, str2bool,
49 from kallithea.lib.utils2 import (Optional, asbool, ascii_bytes, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_str,
50 urlreadable)
50 urlreadable)
51 from kallithea.lib.vcs import get_backend
51 from kallithea.lib.vcs import get_backend
52 from kallithea.lib.vcs.backends.base import EmptyChangeset
52 from kallithea.lib.vcs.backends.base import EmptyChangeset
@@ -185,7 +185,7 b' class Setting(Base, BaseDbModel):'
185 'str': safe_bytes,
185 'str': safe_bytes,
186 'int': safe_int,
186 'int': safe_int,
187 'unicode': safe_str,
187 'unicode': safe_str,
188 'bool': str2bool,
188 'bool': asbool,
189 'list': functools.partial(aslist, sep=',')
189 'list': functools.partial(aslist, sep=',')
190 }
190 }
191 DEFAULT_UPDATE_URL = ''
191 DEFAULT_UPDATE_URL = ''
@@ -1164,7 +1164,7 b' class Repository(Base, BaseDbModel):'
1164 if with_pullrequests:
1164 if with_pullrequests:
1165 data['pull_requests'] = repo.pull_requests_other
1165 data['pull_requests'] = repo.pull_requests_other
1166 rc_config = Setting.get_app_settings()
1166 rc_config = Setting.get_app_settings()
1167 repository_fields = str2bool(rc_config.get('repository_fields'))
1167 repository_fields = asbool(rc_config.get('repository_fields'))
1168 if repository_fields:
1168 if repository_fields:
1169 for f in self.extra_fields:
1169 for f in self.extra_fields:
1170 data[f.field_key_prefixed] = f.field_value
1170 data[f.field_key_prefixed] = f.field_value
@@ -31,7 +31,7 b' import traceback'
31
31
32 from sqlalchemy.exc import DatabaseError
32 from sqlalchemy.exc import DatabaseError
33
33
34 from kallithea.lib.utils2 import str2bool
34 from kallithea.lib.utils2 import asbool
35 from kallithea.model.db import Permission, Session, User, UserRepoGroupToPerm, UserRepoToPerm, UserToPerm, UserUserGroupToPerm
35 from kallithea.model.db import Permission, Session, User, UserRepoGroupToPerm, UserRepoToPerm, UserToPerm, UserUserGroupToPerm
36
36
37
37
@@ -97,7 +97,7 b' class PermissionModel(object):'
97 try:
97 try:
98 # stage 1 set anonymous access
98 # stage 1 set anonymous access
99 if perm_user.is_default_user:
99 if perm_user.is_default_user:
100 perm_user.active = str2bool(form_result['anonymous'])
100 perm_user.active = asbool(form_result['anonymous'])
101
101
102 # stage 2 reset defaults and set them from form data
102 # stage 2 reset defaults and set them from form data
103 def _make_new(usr, perm_name):
103 def _make_new(usr, perm_name):
@@ -29,7 +29,7 b' from tg import config'
29 from tg.i18n import ugettext as _
29 from tg.i18n import ugettext as _
30
30
31 from kallithea.lib import ssh
31 from kallithea.lib import ssh
32 from kallithea.lib.utils2 import str2bool
32 from kallithea.lib.utils2 import asbool
33 from kallithea.lib.vcs.exceptions import RepositoryError
33 from kallithea.lib.vcs.exceptions import RepositoryError
34 from kallithea.model.db import User, UserSshKeys
34 from kallithea.model.db import User, UserSshKeys
35 from kallithea.model.meta import Session
35 from kallithea.model.meta import Session
@@ -95,7 +95,7 b' class SshKeyModel(object):'
95 return user_ssh_keys
95 return user_ssh_keys
96
96
97 def write_authorized_keys(self):
97 def write_authorized_keys(self):
98 if not str2bool(config.get('ssh_enabled', False)):
98 if not asbool(config.get('ssh_enabled', False)):
99 log.error("Will not write SSH authorized_keys file - ssh_enabled is not configured")
99 log.error("Will not write SSH authorized_keys file - ssh_enabled is not configured")
100 return
100 return
101 authorized_keys = config.get('ssh_authorized_keys')
101 authorized_keys = config.get('ssh_authorized_keys')
@@ -32,7 +32,7 b' from kallithea.lib.auth import HasPermis'
32 from kallithea.lib.compat import OrderedSet
32 from kallithea.lib.compat import OrderedSet
33 from kallithea.lib.exceptions import InvalidCloneUriException, LdapImportError
33 from kallithea.lib.exceptions import InvalidCloneUriException, LdapImportError
34 from kallithea.lib.utils import is_valid_repo_uri
34 from kallithea.lib.utils import is_valid_repo_uri
35 from kallithea.lib.utils2 import aslist, repo_name_slug, str2bool
35 from kallithea.lib.utils2 import asbool, aslist, repo_name_slug
36 from kallithea.model import db
36 from kallithea.model import db
37 from kallithea.model.db import RepoGroup, Repository, User, UserGroup
37 from kallithea.model.db import RepoGroup, Repository, User, UserGroup
38
38
@@ -568,7 +568,7 b" def ValidPerms(type_='repo'):"
568 'g': 'users_group'
568 'g': 'users_group'
569 }[k[0]]
569 }[k[0]]
570 if member_name == User.DEFAULT_USER_NAME:
570 if member_name == User.DEFAULT_USER_NAME:
571 if str2bool(value.get('repo_private')):
571 if asbool(value.get('repo_private')):
572 # set none for default when updating to
572 # set none for default when updating to
573 # private repo protects against form manipulation
573 # private repo protects against form manipulation
574 v = EMPTY_PERM
574 v = EMPTY_PERM
@@ -119,12 +119,10 b' class TestLibs(base.TestController):'
119 ('F', False),
119 ('F', False),
120 ('FALSE', False),
120 ('FALSE', False),
121 ('0', False),
121 ('0', False),
122 ('-1', False),
123 ('', False)
124 ])
122 ])
125 def test_str2bool(self, str_bool, expected):
123 def test_asbool(self, str_bool, expected):
126 from kallithea.lib.utils2 import str2bool
124 from kallithea.lib.utils2 import asbool
127 assert str2bool(str_bool) == expected
125 assert asbool(str_bool) == expected
128
126
129 def test_mention_extractor(self):
127 def test_mention_extractor(self):
130 from kallithea.lib.utils2 import extract_mentioned_usernames
128 from kallithea.lib.utils2 import extract_mentioned_usernames
General Comments 0
You need to be logged in to leave comments. Login now