Commit 55cd90e7d66923158e1abd8b66f6b392833615dd
1 parent
b5a489a0
Exists in
master
and in
5 other branches
Update test settings and settings module import
Signed-off-by: Alexandre Barbosa <alexandreab@live.com> Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Showing
4 changed files
with
79 additions
and
23 deletions
Show diff stats
colab/utils/conf.py
@@ -38,7 +38,7 @@ def _load_yaml_file(yaml_path): | @@ -38,7 +38,7 @@ def _load_yaml_file(yaml_path): | ||
38 | 38 | ||
39 | def load_yaml_settings(): | 39 | def load_yaml_settings(): |
40 | settings_dir = '/etc/colab/settings.d' | 40 | settings_dir = '/etc/colab/settings.d' |
41 | - yaml_path = os.getenv('COLAB_SETTINGS', '/etc/colab/settings.yaml') | 41 | + yaml_path = os.getenv('COLAB_YAML_SETTINGS', '/etc/colab/settings.yaml') |
42 | 42 | ||
43 | if os.path.exists(yaml_path): | 43 | if os.path.exists(yaml_path): |
44 | global USING_YAML_SETTINGS | 44 | global USING_YAML_SETTINGS |
@@ -71,24 +71,37 @@ class InaccessiblePySettings(ImproperlyConfigured): | @@ -71,24 +71,37 @@ class InaccessiblePySettings(ImproperlyConfigured): | ||
71 | Check if the file exists and if you have read permissions.""" | 71 | Check if the file exists and if you have read permissions.""" |
72 | 72 | ||
73 | 73 | ||
74 | -def _load_py_file(py_path): | 74 | +def _load_py_file(py_path, path): |
75 | + original_path = sys.path | ||
76 | + | ||
77 | + sys.path = [path] | ||
75 | try: | 78 | try: |
76 | py_settings = importlib.import_module(py_path) | 79 | py_settings = importlib.import_module(py_path) |
77 | 80 | ||
78 | - except: | 81 | + except IOError: |
79 | msg = ('Could not open settings file {}. Please ' | 82 | msg = ('Could not open settings file {}. Please ' |
80 | 'check if the file exists and if user ' | 83 | 'check if the file exists and if user ' |
81 | 'has read rights.').format(py_path) | 84 | 'has read rights.').format(py_path) |
82 | raise InaccessiblePySettings(msg) | 85 | raise InaccessiblePySettings(msg) |
83 | 86 | ||
84 | - return py_settings | 87 | + except SyntaxError as excpt: |
88 | + msg = ('Syntax Error: {}'.format(excpt)) | ||
89 | + raise InaccessiblePySettings(msg) | ||
90 | + | ||
91 | + finally: | ||
92 | + sys.path = original_path | ||
93 | + | ||
94 | + py_setting = {var: getattr(py_settings, var) for var in dir(py_settings) | ||
95 | + if not var.startswith('__')} | ||
96 | + | ||
97 | + return py_setting | ||
85 | 98 | ||
86 | 99 | ||
87 | def load_py_settings(): | 100 | def load_py_settings(): |
88 | settings_dir = '/etc/colab/settings.d' | 101 | settings_dir = '/etc/colab/settings.d' |
89 | - settings_module = 'settings' | ||
90 | - py_path = os.getenv('COLAB_SETTINGS', | ||
91 | - "/etc/colab/{}.py".format(settings_module)) | 102 | + settings_file = os.getenv('COLAB_SETTINGS', '/etc/colab/settings.py') |
103 | + settings_module = settings_file.split('.')[-2].split('/')[-1] | ||
104 | + py_path = "/".join(settings_file.split('/')[:-1]) | ||
92 | 105 | ||
93 | global USING_YAML_SETTINGS | 106 | global USING_YAML_SETTINGS |
94 | if not os.path.exists(py_path) and not USING_YAML_SETTINGS: | 107 | if not os.path.exists(py_path) and not USING_YAML_SETTINGS: |
@@ -97,34 +110,28 @@ def load_py_settings(): | @@ -97,34 +110,28 @@ def load_py_settings(): | ||
97 | elif USING_YAML_SETTINGS: | 110 | elif USING_YAML_SETTINGS: |
98 | return {} | 111 | return {} |
99 | 112 | ||
100 | - sys.path.insert(0, '/etc/colab/') | ||
101 | - sys.path.insert(0, settings_dir) | ||
102 | - | ||
103 | - py_settings = _load_py_file(settings_module).__dict__ | 113 | + py_settings = _load_py_file(settings_module, py_path) |
104 | 114 | ||
105 | # Try to read settings from settings.d | 115 | # Try to read settings from settings.d |
116 | + | ||
106 | if os.path.exists(settings_dir): | 117 | if os.path.exists(settings_dir): |
118 | + return py_settings | ||
107 | for file_name in os.listdir(settings_dir): | 119 | for file_name in os.listdir(settings_dir): |
108 | if file_name.endswith('.py'): | 120 | if file_name.endswith('.py'): |
109 | file_module = file_name.split('.')[0] | 121 | file_module = file_name.split('.')[0] |
110 | - py_settings_d = _load_py_file(file_module).__dict__ | 122 | + py_settings_d = _load_py_file(file_module, settings_dir) |
111 | py_settings.update(py_settings_d) | 123 | py_settings.update(py_settings_d) |
112 | 124 | ||
113 | - sys.path.remove('/etc/colab/') | ||
114 | - sys.path.remove(settings_dir) | ||
115 | - | ||
116 | - return py_settings or {} | 125 | + return py_settings |
117 | 126 | ||
118 | 127 | ||
119 | def load_colab_apps(): | 128 | def load_colab_apps(): |
120 | - plugins_dir = '/etc/colab/plugins.d/' | 129 | + plugins_dir = os.getenv('COLAB_PLUGINS', '/etc/colab/plugins.d/') |
121 | 130 | ||
122 | global USING_YAML_SETTINGS | 131 | global USING_YAML_SETTINGS |
123 | if USING_YAML_SETTINGS: | 132 | if USING_YAML_SETTINGS: |
124 | return {} | 133 | return {} |
125 | 134 | ||
126 | - sys.path.insert(0, plugins_dir) | ||
127 | - | ||
128 | COLAB_APPS = {} | 135 | COLAB_APPS = {} |
129 | 136 | ||
130 | # Try to read settings from plugins.d | 137 | # Try to read settings from plugins.d |
@@ -132,7 +139,7 @@ def load_colab_apps(): | @@ -132,7 +139,7 @@ def load_colab_apps(): | ||
132 | for file_name in os.listdir(plugins_dir): | 139 | for file_name in os.listdir(plugins_dir): |
133 | if file_name.endswith('.py'): | 140 | if file_name.endswith('.py'): |
134 | file_module = file_name.split('.')[0] | 141 | file_module = file_name.split('.')[0] |
135 | - py_settings_d = _load_py_file(file_module) | 142 | + py_settings_d = _load_py_file(file_module, plugins_dir) |
136 | fields = ['urls', 'menu', 'upstream', 'middlewares', | 143 | fields = ['urls', 'menu', 'upstream', 'middlewares', |
137 | 'dependencies', 'context_processors'] | 144 | 'dependencies', 'context_processors'] |
138 | 145 | ||
@@ -147,8 +154,6 @@ def load_colab_apps(): | @@ -147,8 +154,6 @@ def load_colab_apps(): | ||
147 | if value: | 154 | if value: |
148 | COLAB_APPS[app_name][key] = value | 155 | COLAB_APPS[app_name][key] = value |
149 | 156 | ||
150 | - sys.path.remove(plugins_dir) | ||
151 | - | ||
152 | return {'COLAB_APPS': COLAB_APPS} | 157 | return {'COLAB_APPS': COLAB_APPS} |
153 | 158 | ||
154 | 159 |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +SECRET_KEY = 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddaddddddddd' | ||
2 | + | ||
3 | +DATABASES = { | ||
4 | + 'default': { | ||
5 | + 'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||
6 | + 'HOST': 'localhost', | ||
7 | + 'NAME': 'colab', | ||
8 | + 'USER': 'colab', | ||
9 | + 'PASSWORD': 'colab', | ||
10 | + } | ||
11 | +} |
@@ -0,0 +1,39 @@ | @@ -0,0 +1,39 @@ | ||
1 | +from django.utils.translation import ugettext_lazy as _ | ||
2 | + | ||
3 | +name = 'colab.plugins.gitlab' | ||
4 | +verbose_name = 'Gitlab Proxy' | ||
5 | + | ||
6 | +upstream = 'localhost' | ||
7 | +#middlewares = [] | ||
8 | + | ||
9 | +menu = { | ||
10 | +'title': _('Code'), | ||
11 | +'links': ( | ||
12 | + (_('Public Projects'), 'public/projects'), | ||
13 | +), | ||
14 | +'auth_links': ( | ||
15 | + (_('Profile'), 'profile'), | ||
16 | + (_('New Project'), 'projects/new'), | ||
17 | + (_('Projects'), 'dashboard/projects'), | ||
18 | + (_('Groups'), 'profile/groups'), | ||
19 | + (_('Issues'), 'dashboard/issues'), | ||
20 | + (_('Merge Requests'), 'dashboard/merge_requests'), | ||
21 | + | ||
22 | +), | ||
23 | +} | ||
24 | + | ||
25 | + | ||
26 | +# dpaste: | ||
27 | +# dependencies: | ||
28 | +# - 'mptt' | ||
29 | +# urls: | ||
30 | +# include: 'dpaste.urls.dpaste' | ||
31 | +# prefix: '^paste/' | ||
32 | +# namespace: 'dpaste' | ||
33 | +# menu: | ||
34 | +# title: 'Dpaste' | ||
35 | +# links: | ||
36 | +# Public Projects: '/paste' | ||
37 | +# auth_links: | ||
38 | +# Profile: '/projects' | ||
39 | +# New Project: '/projects/new' |
tests/run.py
@@ -4,7 +4,8 @@ import os | @@ -4,7 +4,8 @@ import os | ||
4 | import sys | 4 | import sys |
5 | 5 | ||
6 | os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' | 6 | os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings' |
7 | -os.environ['COLAB_SETTINGS'] = 'tests/settings.yaml' | 7 | +os.environ['COLAB_SETTINGS'] = 'tests/config_settings.py' |
8 | +os.environ['PLUGINS_SETTINGS'] = 'tests/plugins.d' | ||
8 | os.environ['COVERAGE_PROCESS_START'] = '.coveragerc' | 9 | os.environ['COVERAGE_PROCESS_START'] = '.coveragerc' |
9 | os.environ['REUSE_DB'] = '0' | 10 | os.environ['REUSE_DB'] = '0' |
10 | 11 |