changeset 1138:9c45e11493fb beta

fixed ldap settings creation, we need to fill in some bool defaults properly to make it work fine
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 17 Mar 2011 01:31:15 +0100
parents 82344ce0a892
children 0e6035a85980
files rhodecode/lib/db_manage.py
diffstat 1 files changed, 18 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/db_manage.py	Thu Mar 17 01:21:07 2011 +0100
+++ b/rhodecode/lib/db_manage.py	Thu Mar 17 01:31:15 2011 +0100
@@ -60,39 +60,19 @@
         init_model(engine)
         self.sa = meta.Session()
 
-    def check_for_db(self, override):
-        db_path = jn(self.root, self.dbname)
-        if self.dburi.startswith('sqlite'):
-            log.info('checking for existing db in %s', db_path)
-            if os.path.isfile(db_path):
-
-                self.db_exists = True
-                if not override:
-                    raise Exception('database already exists')
-            return 'sqlite'
-        if self.dburi.startswith('postgresql'):
-            self.db_exists = True
-            return 'postgresql'
-
-
     def create_tables(self, override=False):
         """Create a auth database
         """
 
-        db_type = self.check_for_db(override)
-        if self.db_exists:
-            log.info("database exist and it's going to be destroyed")
-            if self.tests:
-                destroy = True
-            else:
-                destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
-            if not destroy:
-                sys.exit()
-            if self.db_exists and destroy:
-                if db_type == 'sqlite':
-                    os.remove(jn(self.root, self.dbname))
-                if db_type == 'postgresql':
-                    meta.Base.metadata.drop_all()
+        log.info("Any existing database is going to be destroyed")
+        if self.tests:
+            destroy = True
+        else:
+            destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
+        if not destroy:
+            sys.exit()
+        if destroy:
+            meta.Base.metadata.drop_all()
 
         checkfirst = not override
         meta.Base.metadata.create_all(checkfirst=checkfirst)
@@ -335,13 +315,16 @@
         """Creates ldap settings"""
 
         try:
-            for k in ['ldap_active', 'ldap_host', 'ldap_port', 'ldap_ldaps',
-                      'ldap_tls_reqcert', 'ldap_dn_user', 'ldap_dn_pass',
-                      'ldap_base_dn', 'ldap_filter', 'ldap_search_scope',
-                      'ldap_attr_login', 'ldap_attr_firstname', 'ldap_attr_lastname',
-                      'ldap_attr_email']:
+            for k, v in [('ldap_active', 'false'), ('ldap_host', ''),
+                        ('ldap_port', '389'), ('ldap_ldaps', 'false'),
+                        ('ldap_tls_reqcert', ''), ('ldap_dn_user', ''),
+                        ('ldap_dn_pass', ''), ('ldap_base_dn', ''),
+                        ('ldap_filter', ''), ('ldap_search_scope', ''),
+                        ('ldap_attr_login', ''), ('ldap_attr_firstname', ''),
+                        ('ldap_attr_lastname', ''), ('ldap_attr_email', '')]:
 
-                setting = RhodeCodeSettings(k, '')
+
+                setting = RhodeCodeSettings(k, v)
                 self.sa.add(setting)
             self.sa.commit()
         except: