annotate rhodecode/model/settings.py @ 962:72f008ed9b18 beta

implemented #84 downloads can be enabled/disabled per each repository from now.
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 26 Jan 2011 18:37:42 +0100
parents 07a6e8c65526
children b232a36cc51f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 #!/usr/bin/env python
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 # encoding: utf-8
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 # Model for RhodeCode settings
902
07a6e8c65526 fixed copyright year to 2011
Marcin Kuzminski <marcin@python-works.com>
parents: 892
diff changeset
4 # Copyright (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5 #
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 # This program is free software; you can redistribute it and/or
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 # modify it under the terms of the GNU General Public License
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 # as published by the Free Software Foundation; version 2
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 # of the License or (at your opinion) any later version of the license.
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 #
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 # GNU General Public License for more details.
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 #
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # You should have received a copy of the GNU General Public License
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 # along with this program; if not, write to the Free Software
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # MA 02110-1301, USA.
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 """
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 Created on Nov 17, 2010
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 Model for RhodeCode
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
23 :author: marcink
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 """
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
25
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 from rhodecode.lib import helpers as h
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
27 from rhodecode.model import BaseModel
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 from rhodecode.model.caching_query import FromCache
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 from rhodecode.model.db import RhodeCodeSettings
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 from sqlalchemy.orm import joinedload
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 import logging
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 log = logging.getLogger(__name__)
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 705
diff changeset
35 class SettingsModel(BaseModel):
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 """
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 Settings model
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 """
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 def get(self, settings_key, cache=False):
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 r = self.sa.query(RhodeCodeSettings)\
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 .filter(RhodeCodeSettings.app_settings_name == settings_key).scalar()
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 if cache:
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 r = r.options(FromCache("sql_cache_short",
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 "get_setting_%s" % settings_key))
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 return r
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47
892
9adc0c1d9a87 Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 890
diff changeset
48 def get_app_settings(self, cache=False):
890
042d38683d42 implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
49 """Get's config from database, each config key is prefixed with
042d38683d42 implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
50 'rhodecode_' prefix, than global pylons config is updated with such
042d38683d42 implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
51 keys
042d38683d42 implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
52 """
042d38683d42 implemented #89 google analytics code
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
53
892
9adc0c1d9a87 Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 890
diff changeset
54 ret = self.sa.query(RhodeCodeSettings)
9adc0c1d9a87 Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 890
diff changeset
55
9adc0c1d9a87 Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 890
diff changeset
56 if cache:
9adc0c1d9a87 Added optional cache into get_application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 890
diff changeset
57 ret = ret.options(FromCache("sql_cache_short", "get_hg_settings"))
756
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
58
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
59 if not ret:
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
60 raise Exception('Could not get application settings !')
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
61 settings = {}
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
62 for each in ret:
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
63 settings['rhodecode_' + each.app_settings_name] = each.app_settings_value
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
64
01be209b9828 project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
65 return settings
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 def get_ldap_settings(self):
705
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
68 """
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
69 Returns ldap settings from database
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
70 :returns:
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
71 ldap_active
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
72 ldap_host
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
73 ldap_port
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
74 ldap_ldaps
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
75 ldap_dn_user
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
76 ldap_dn_pass
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
77 ldap_base_dn
9e9f1b919c0c implements #60, ldap configuration and authentication.
Marcin Kuzminski <marcin@python-works.com>
parents: 704
diff changeset
78 """
704
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 r = self.sa.query(RhodeCodeSettings)\
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 .filter(RhodeCodeSettings.app_settings_name\
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 .startswith('ldap_'))\
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 .all()
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 fd = {}
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 for row in r:
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 v = row.app_settings_value
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 if v in ['0', '1']:
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 v = v == '1'
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 fd.update({row.app_settings_name:v})
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92
26237de9b613 Added settings model, and Exceptions lib.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
93 return fd