##// END OF EJS Templates
configs: refactor and updated for python3 migrations
super-admin -
r5060:bbd1552d default
parent child Browse files
Show More
@@ -184,17 +184,6 b''
184 {
184 {
185 "license": [
185 "license": [
186 {
186 {
187 "fullName": "MIT License",
188 "shortName": "mit",
189 "spdxId": "MIT",
190 "url": "http://spdx.org/licenses/MIT.html"
191 }
192 ],
193 "name": "python2.7-pathlib2-2.3.5"
194 },
195 {
196 "license": [
197 {
198 "fullName": "BSD 4-clause \"Original\" or \"Old\" License",
187 "fullName": "BSD 4-clause \"Original\" or \"Old\" License",
199 "shortName": "bsdOriginal",
188 "shortName": "bsdOriginal",
200 "spdxId": "BSD-4-Clause",
189 "spdxId": "BSD-4-Clause",
@@ -1868,17 +1857,6 b''
1868 "url": "http://spdx.org/licenses/BSD-4-Clause.html"
1857 "url": "http://spdx.org/licenses/BSD-4-Clause.html"
1869 }
1858 }
1870 ],
1859 ],
1871 "name": "python2.7-configobj-5.0.6"
1872 },
1873 {
1874 "license": [
1875 {
1876 "fullName": "BSD 4-clause \"Original\" or \"Old\" License",
1877 "shortName": "bsdOriginal",
1878 "spdxId": "BSD-4-Clause",
1879 "url": "http://spdx.org/licenses/BSD-4-Clause.html"
1880 }
1881 ],
1882 "name": "python2.7-channelstream-0.6.14"
1860 "name": "python2.7-channelstream-0.6.14"
1883 },
1861 },
1884 {
1862 {
@@ -120,8 +120,7 b' def make_pyramid_app(global_config, **se'
120 meta.Session.remove()
120 meta.Session.remove()
121
121
122 total_time = time.time() - start_time
122 total_time = time.time() - start_time
123 log.info('Pyramid app `%s` created and configured in %.2fs',
123 log.info('Pyramid app created and configured in %.2fs', total_time)
124 getattr(pyramid_app, 'func_name', 'pyramid_app'), total_time)
125 return pyramid_app
124 return pyramid_app
126
125
127
126
@@ -241,11 +240,20 b' def error_handler(exception, request):'
241 c.exception_id_url = request.route_url(
240 c.exception_id_url = request.route_url(
242 'admin_settings_exception_tracker_show', exception_id=c.exception_id)
241 'admin_settings_exception_tracker_show', exception_id=c.exception_id)
243
242
243 debug_mode = rhodecode.ConfigGet().get_bool('debug')
244 if c.show_exception_id:
244 if c.show_exception_id:
245 store_exception(c.exception_id, exc_info)
245 store_exception(c.exception_id, exc_info)
246 c.exception_debug = str2bool(rhodecode.CONFIG.get('debug'))
246 c.exception_debug = debug_mode
247 c.exception_config_ini = rhodecode.CONFIG.get('__file__')
247 c.exception_config_ini = rhodecode.CONFIG.get('__file__')
248
248
249 if debug_mode:
250 try:
251 from rich.traceback import install
252 install(show_locals=True)
253 log.debug('Installing rich tracebacks...')
254 except ImportError:
255 pass
256
249 response = render_to_response(
257 response = render_to_response(
250 '/errors/error_document.mako', {'c': c, 'h': helpers}, request=request,
258 '/errors/error_document.mako', {'c': c, 'h': helpers}, request=request,
251 response=base_response)
259 response=base_response)
@@ -283,6 +291,17 b' def includeme_first(config):'
283 '_static/rhodecode', path='rhodecode:public', cache_max_age=3600 * 24)
291 '_static/rhodecode', path='rhodecode:public', cache_max_age=3600 * 24)
284
292
285
293
294 ce_auth_resources = [
295 'rhodecode.authentication.plugins.auth_crowd',
296 'rhodecode.authentication.plugins.auth_headers',
297 'rhodecode.authentication.plugins.auth_jasig_cas',
298 'rhodecode.authentication.plugins.auth_ldap',
299 'rhodecode.authentication.plugins.auth_pam',
300 'rhodecode.authentication.plugins.auth_rhodecode',
301 'rhodecode.authentication.plugins.auth_token',
302 ]
303
304
286 def includeme(config, auth_resources=None):
305 def includeme(config, auth_resources=None):
287 from rhodecode.lib.celerylib.loader import configure_celery
306 from rhodecode.lib.celerylib.loader import configure_celery
288 log.debug('Initializing main includeme from %s', os.path.basename(__file__))
307 log.debug('Initializing main includeme from %s', os.path.basename(__file__))
@@ -306,21 +325,14 b' def includeme(config, auth_resources=Non'
306 config.include('pyramid_mako')
325 config.include('pyramid_mako')
307 config.include('rhodecode.lib.rc_beaker')
326 config.include('rhodecode.lib.rc_beaker')
308 config.include('rhodecode.lib.rc_cache')
327 config.include('rhodecode.lib.rc_cache')
328 config.include('rhodecode.lib.rc_cache.archive_cache')
329
309 config.include('rhodecode.apps._base.navigation')
330 config.include('rhodecode.apps._base.navigation')
310 config.include('rhodecode.apps._base.subscribers')
331 config.include('rhodecode.apps._base.subscribers')
311 config.include('rhodecode.tweens')
332 config.include('rhodecode.tweens')
312 config.include('rhodecode.authentication')
333 config.include('rhodecode.authentication')
313
334
314 if load_all:
335 if load_all:
315 ce_auth_resources = [
316 'rhodecode.authentication.plugins.auth_crowd',
317 'rhodecode.authentication.plugins.auth_headers',
318 'rhodecode.authentication.plugins.auth_jasig_cas',
319 'rhodecode.authentication.plugins.auth_ldap',
320 'rhodecode.authentication.plugins.auth_pam',
321 'rhodecode.authentication.plugins.auth_rhodecode',
322 'rhodecode.authentication.plugins.auth_token',
323 ]
324
336
325 # load CE authentication plugins
337 # load CE authentication plugins
326
338
@@ -384,9 +396,6 b' def includeme(config, auth_resources=Non'
384 config.add_subscriber(write_js_routes_if_enabled,
396 config.add_subscriber(write_js_routes_if_enabled,
385 pyramid.events.ApplicationCreated)
397 pyramid.events.ApplicationCreated)
386
398
387 # Set the authorization policy.
388 authz_policy = ACLAuthorizationPolicy()
389 config.set_authorization_policy(authz_policy)
390
399
391 # Set the default renderer for HTML templates to mako.
400 # Set the default renderer for HTML templates to mako.
392 config.add_mako_renderer('.html')
401 config.add_mako_renderer('.html')
@@ -448,7 +457,7 b' def wrap_app_in_wsgi_middlewares(pyramid'
448 # In a single threaded mode server, on non sqlite db we should have
457 # In a single threaded mode server, on non sqlite db we should have
449 # '0 Current Checked out connections' at the end of a request,
458 # '0 Current Checked out connections' at the end of a request,
450 # if not, then something, somewhere is leaving a connection open
459 # if not, then something, somewhere is leaving a connection open
451 pool = meta.Base.metadata.bind.engine.pool
460 pool = meta.get_engine().pool
452 log.debug('sa pool status: %s', pool.status())
461 log.debug('sa pool status: %s', pool.status())
453 total = time.time() - start
462 total = time.time() - start
454 log.debug('Request processing finalized: %.4fs', total)
463 log.debug('Request processing finalized: %.4fs', total)
@@ -531,7 +540,7 b' def sanitize_settings_and_apply_defaults'
531
540
532 settings_maker.make_setting('vcs.svn.compatible_version', '')
541 settings_maker.make_setting('vcs.svn.compatible_version', '')
533 settings_maker.make_setting('vcs.hooks.protocol', 'http')
542 settings_maker.make_setting('vcs.hooks.protocol', 'http')
534 settings_maker.make_setting('vcs.hooks.host', '127.0.0.1')
543 settings_maker.make_setting('vcs.hooks.host', '*')
535 settings_maker.make_setting('vcs.scm_app_implementation', 'http')
544 settings_maker.make_setting('vcs.scm_app_implementation', 'http')
536 settings_maker.make_setting('vcs.server', '')
545 settings_maker.make_setting('vcs.server', '')
537 settings_maker.make_setting('vcs.server.protocol', 'http')
546 settings_maker.make_setting('vcs.server.protocol', 'http')
@@ -586,17 +595,17 b' def sanitize_settings_and_apply_defaults'
586 # cache_perms
595 # cache_perms
587 settings_maker.make_setting('rc_cache.cache_perms.backend', 'dogpile.cache.rc.file_namespace')
596 settings_maker.make_setting('rc_cache.cache_perms.backend', 'dogpile.cache.rc.file_namespace')
588 settings_maker.make_setting('rc_cache.cache_perms.expiration_time', 60 * 60, parser='int')
597 settings_maker.make_setting('rc_cache.cache_perms.expiration_time', 60 * 60, parser='int')
589 settings_maker.make_setting('rc_cache.cache_perms.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_perms.db'))
598 settings_maker.make_setting('rc_cache.cache_perms.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_perms_db'))
590
599
591 # cache_repo
600 # cache_repo
592 settings_maker.make_setting('rc_cache.cache_repo.backend', 'dogpile.cache.rc.file_namespace')
601 settings_maker.make_setting('rc_cache.cache_repo.backend', 'dogpile.cache.rc.file_namespace')
593 settings_maker.make_setting('rc_cache.cache_repo.expiration_time', 60 * 60 * 24 * 30, parser='int')
602 settings_maker.make_setting('rc_cache.cache_repo.expiration_time', 60 * 60 * 24 * 30, parser='int')
594 settings_maker.make_setting('rc_cache.cache_repo.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_repo.db'))
603 settings_maker.make_setting('rc_cache.cache_repo.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_repo_db'))
595
604
596 # cache_license
605 # cache_license
597 settings_maker.make_setting('rc_cache.cache_license.backend', 'dogpile.cache.rc.file_namespace')
606 settings_maker.make_setting('rc_cache.cache_license.backend', 'dogpile.cache.rc.file_namespace')
598 settings_maker.make_setting('rc_cache.cache_license.expiration_time', 60 * 5, parser='int')
607 settings_maker.make_setting('rc_cache.cache_license.expiration_time', 60 * 5, parser='int')
599 settings_maker.make_setting('rc_cache.cache_license.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_license.db'))
608 settings_maker.make_setting('rc_cache.cache_license.arguments.filename', os.path.join(default_cache_dir, 'rhodecode_cache_license_db'))
600
609
601 # cache_repo_longterm memory, 96H
610 # cache_repo_longterm memory, 96H
602 settings_maker.make_setting('rc_cache.cache_repo_longterm.backend', 'dogpile.cache.rc.memory_lru')
611 settings_maker.make_setting('rc_cache.cache_repo_longterm.backend', 'dogpile.cache.rc.memory_lru')
@@ -608,6 +617,11 b' def sanitize_settings_and_apply_defaults'
608 settings_maker.make_setting('rc_cache.sql_cache_short.expiration_time', 30, parser='int')
617 settings_maker.make_setting('rc_cache.sql_cache_short.expiration_time', 30, parser='int')
609 settings_maker.make_setting('rc_cache.sql_cache_short.max_size', 10000, parser='int')
618 settings_maker.make_setting('rc_cache.sql_cache_short.max_size', 10000, parser='int')
610
619
620 # archive_cache
621 settings_maker.make_setting('archive_cache.store_dir', os.path.join(default_cache_dir, 'archive_cache'), default_when_empty=True,)
622 settings_maker.make_setting('archive_cache.cache_size_gb', 10, parser='float')
623 settings_maker.make_setting('archive_cache.cache_shards', 10, parser='int')
624
611 settings_maker.env_expand()
625 settings_maker.env_expand()
612
626
613 # configure instance id
627 # configure instance id
@@ -94,6 +94,7 b' def inspect_getargspec():'
94 args, varargs, varkw = inspect.getargs(func.func_code)
94 args, varargs, varkw = inspect.getargs(func.func_code)
95 return inspect.ArgSpec(args, varargs, varkw, func.func_defaults)
95 return inspect.ArgSpec(args, varargs, varkw, func.func_defaults)
96
96
97 inspect.getargspec = custom_getargspec
97 #TODO: fix it and test it on python3.11
98 inspect.getargspec = inspect.getfullargspec #custom_getargspec
98
99
99 return inspect
100 return inspect
@@ -32,7 +32,7 b' import json'
32 from rhodecode.lib import diffs
32 from rhodecode.lib import diffs
33 from rhodecode.lib.vcs.backends.hg.diff import MercurialDiff
33 from rhodecode.lib.vcs.backends.hg.diff import MercurialDiff
34 from rhodecode.lib.vcs.backends.git.diff import GitDiff
34 from rhodecode.lib.vcs.backends.git.diff import GitDiff
35 from vcsserver.utils import safe_int
35 from rhodecode.lib.str_utils import safe_int
36
36
37
37
38 def get_svn_files(repo, vcs_repo, refs):
38 def get_svn_files(repo, vcs_repo, refs):
@@ -108,7 +108,7 b' def get_git_files(repo, vcs_repo, refs):'
108 stdout, stderr = vcs_repo.run_git_command(cmd, extra_env=git_env)
108 stdout, stderr = vcs_repo.run_git_command(cmd, extra_env=git_env)
109 vcs_diff = GitDiff(stdout)
109 vcs_diff = GitDiff(stdout)
110
110
111 diff_processor = diffs.DiffProcessor(vcs_diff, format='newdiff')
111 diff_processor = diffs.DiffProcessor(vcs_diff, diff_format='newdiff')
112 # this is list of dicts with diff information
112 # this is list of dicts with diff information
113 # _parsed[0].keys()
113 # _parsed[0].keys()
114 # ['raw_diff', 'old_revision', 'stats', 'original_filename',
114 # ['raw_diff', 'old_revision', 'stats', 'original_filename',
@@ -21,7 +21,9 b' import os'
21 import string
21 import string
22 import functools
22 import functools
23 import collections
23 import collections
24 import urllib.request, urllib.parse, urllib.error
24 import urllib.request
25 import urllib.parse
26 import urllib.error
25
27
26 log = logging.getLogger('rhodecode.' + __name__)
28 log = logging.getLogger('rhodecode.' + __name__)
27
29
@@ -48,7 +50,7 b' class DotDict(dict):'
48 def __contains__(self, k):
50 def __contains__(self, k):
49 try:
51 try:
50 return dict.__contains__(self, k) or hasattr(self, k)
52 return dict.__contains__(self, k) or hasattr(self, k)
51 except:
53 except Exception:
52 return False
54 return False
53
55
54 # only called if k not found in normal places
56 # only called if k not found in normal places
@@ -153,14 +155,13 b' def maybe_log_call(name, args, kwargs):'
153 calls[name].append((args, kwargs))
155 calls[name].append((args, kwargs))
154
156
155
157
156 def str2bool(_str):
158 def str2bool(_str) -> bool:
157 """
159 """
158 returns True/False value from given string, it tries to translate the
160 returns True/False value from given string, it tries to translate the
159 string into boolean
161 string into boolean
160
162
161 :param _str: string value to translate into boolean
163 :param _str: string value to translate into boolean
162 :rtype: boolean
164 :returns: bool from given string
163 :returns: boolean from given string
164 """
165 """
165 if _str is None:
166 if _str is None:
166 return False
167 return False
@@ -24,55 +24,17 b' import functools'
24 import logging
24 import logging
25 import tempfile
25 import tempfile
26 import logging.config
26 import logging.config
27 from rhodecode.lib.type_utils import str2bool, aslist
28
27 log = logging.getLogger(__name__)
29 log = logging.getLogger(__name__)
28
30
31
29 # skip keys, that are set here, so we don't double process those
32 # skip keys, that are set here, so we don't double process those
30 set_keys = {
33 set_keys = {
31 '__file__': ''
34 '__file__': ''
32 }
35 }
33
36
34
37
35 def str2bool(_str):
36 """
37 returns True/False value from given string, it tries to translate the
38 string into boolean
39
40 :param _str: string value to translate into boolean
41 :rtype: boolean
42 :returns: boolean from given string
43 """
44 if _str is None:
45 return False
46 if _str in (True, False):
47 return _str
48 _str = str(_str).strip().lower()
49 return _str in ('t', 'true', 'y', 'yes', 'on', '1')
50
51
52 def aslist(obj, sep=None, strip=True):
53 """
54 Returns given string separated by sep as list
55
56 :param obj:
57 :param sep:
58 :param strip:
59 """
60 if isinstance(obj, str):
61 if obj in ['', ""]:
62 return []
63
64 lst = obj.split(sep)
65 if strip:
66 lst = [v.strip() for v in lst]
67 return lst
68 elif isinstance(obj, (list, tuple)):
69 return obj
70 elif obj is None:
71 return []
72 else:
73 return [obj]
74
75
76 class SettingsMaker(object):
38 class SettingsMaker(object):
77
39
78 def __init__(self, app_settings):
40 def __init__(self, app_settings):
@@ -87,6 +49,10 b' class SettingsMaker(object):'
87 return int(input_val)
49 return int(input_val)
88
50
89 @classmethod
51 @classmethod
52 def _float_func(cls, input_val):
53 return float(input_val)
54
55 @classmethod
90 def _list_func(cls, input_val, sep=','):
56 def _list_func(cls, input_val, sep=','):
91 return aslist(input_val, sep=sep)
57 return aslist(input_val, sep=sep)
92
58
@@ -97,10 +63,6 b' class SettingsMaker(object):'
97 return input_val
63 return input_val
98
64
99 @classmethod
65 @classmethod
100 def _float_func(cls, input_val):
101 return float(input_val)
102
103 @classmethod
104 def _dir_func(cls, input_val, ensure_dir=False, mode=0o755):
66 def _dir_func(cls, input_val, ensure_dir=False, mode=0o755):
105
67
106 # ensure we have our dir created
68 # ensure we have our dir created
@@ -160,7 +122,7 b' class SettingsMaker(object):'
160 'file does not exist.... specify path using logging.logging_conf_file= config setting. ', logging_conf)
122 'file does not exist.... specify path using logging.logging_conf_file= config setting. ', logging_conf)
161 return
123 return
162
124
163 with open(logging_conf, 'rb') as f:
125 with open(logging_conf, 'rt') as f:
164 ini_template = textwrap.dedent(f.read())
126 ini_template = textwrap.dedent(f.read())
165 ini_template = string.Template(ini_template).safe_substitute(
127 ini_template = string.Template(ini_template).safe_substitute(
166 RC_LOGGING_LEVEL=os.environ.get('RC_LOGGING_LEVEL', '') or level,
128 RC_LOGGING_LEVEL=os.environ.get('RC_LOGGING_LEVEL', '') or level,
@@ -184,6 +146,7 b' class SettingsMaker(object):'
184 parser_func = {
146 parser_func = {
185 'bool': self._bool_func,
147 'bool': self._bool_func,
186 'int': self._int_func,
148 'int': self._int_func,
149 'float': self._float_func,
187 'list': self._list_func,
150 'list': self._list_func,
188 'list:newline': functools.partial(self._list_func, sep='/n'),
151 'list:newline': functools.partial(self._list_func, sep='/n'),
189 'list:spacesep': functools.partial(self._list_func, sep=' '),
152 'list:spacesep': functools.partial(self._list_func, sep=' '),
@@ -95,9 +95,25 b' def set_instance_id(config):'
95
95
96
96
97 def get_default_user_id():
97 def get_default_user_id():
98 from rhodecode.model.db import User, Session
98 DEFAULT_USER = 'default'
99 user_id = Session()\
99 from sqlalchemy import text
100 .query(User.user_id)\
100 from rhodecode.model import meta
101 .filter(User.username == User.DEFAULT_USER)\
101
102 .scalar()
102 engine = meta.get_engine()
103 with meta.SA_Session(engine) as session:
104 result = session.execute(text("SELECT user_id from users where username = :uname"), {'uname': DEFAULT_USER})
105 user_id = result.first()[0]
106
103 return user_id
107 return user_id
108
109
110 def get_default_base_path():
111 from sqlalchemy import text
112 from rhodecode.model import meta
113
114 engine = meta.get_engine()
115 with meta.SA_Session(engine) as session:
116 result = session.execute(text("SELECT ui_value from rhodecode_ui where ui_key = '/'"))
117 base_path = result.first()[0]
118
119 return base_path
General Comments 0
You need to be logged in to leave comments. Login now