changeset 2919:29630805893d beta

Implemented proposed changes from pull request #77
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 11 Oct 2012 20:56:01 +0200
parents ce8572f45c85
children 8464d0e96e97
files rhodecode/config/setup_rhodecode.py rhodecode/lib/db_manage.py rhodecode/tests/scripts/create_rc.sh rhodecode/websetup.py
diffstat 4 files changed, 33 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/config/setup_rhodecode.py	Thu Oct 11 20:31:37 2012 +0200
+++ b/rhodecode/config/setup_rhodecode.py	Thu Oct 11 20:56:01 2012 +0200
@@ -50,6 +50,16 @@
                       dest='section_name',
                       default=None,
                       help='The name of the section to set up (default: app:main)')
+    parser.add_option('--force-yes',
+                       action='store_true',
+                       dest='force_ask',
+                       default=None,
+                       help='Force yes to every question')
+    parser.add_option('--force-no',
+                       action='store_false',
+                       dest='force_ask',
+                       default=None,
+                       help='Force no to every question')
 
     def command(self):
         config_spec = self.args[0]
@@ -61,7 +71,7 @@
                 section = 'main'
         if not ':' in section:
             plain_section = section
-            section = 'app:'+section
+            section = 'app:' + section
         else:
             plain_section = section.split(':', 1)[0]
         if not config_spec.startswith('config:'):
--- a/rhodecode/lib/db_manage.py	Thu Oct 11 20:31:37 2012 +0200
+++ b/rhodecode/lib/db_manage.py	Thu Oct 11 20:56:01 2012 +0200
@@ -57,32 +57,39 @@
 
 
 class DbManage(object):
-    def __init__(self, log_sql, dbconf, root, tests=False):
+    def __init__(self, log_sql, dbconf, root, tests=False, cli_args={}):
         self.dbname = dbconf.split('/')[-1]
         self.tests = tests
         self.root = root
         self.dburi = dbconf
         self.log_sql = log_sql
         self.db_exists = False
+        self.cli_args = cli_args
         self.init_db()
+        global ask_ok
+
+        if self.cli_args.get('force_ask') is True:
+            ask_ok = lambda *args, **kwargs: True
+        elif self.cli_args.get('force_ask') is False:
+            ask_ok = lambda *args, **kwargs: False
 
     def init_db(self):
         engine = create_engine(self.dburi, echo=self.log_sql)
         init_model(engine)
         self.sa = Session()
 
-    def create_tables(self, override=False, defaults={}):
+    def create_tables(self, override=False):
         """
         Create a auth database
         """
-        quiet = defaults.get('quiet')
+
         log.info("Any existing database is going to be destroyed")
-        if self.tests or quiet:
+        if self.tests:
             destroy = True
         else:
             destroy = ask_ok('Are you sure to destroy old database ? [y/n]')
         if not destroy:
-            sys.exit()
+            sys.exit('Nothing done')
         if destroy:
             Base.metadata.drop_all()
 
@@ -328,11 +335,12 @@
             self.sa.rollback()
             raise
 
-    def admin_prompt(self, second=False, defaults={}):
+    def admin_prompt(self, second=False):
         if not self.tests:
             import getpass
 
             # defaults
+            defaults = self.cli_args
             username = defaults.get('username')
             password = defaults.get('password')
             email = defaults.get('email')
@@ -507,7 +515,8 @@
             self.populate_default_permissions()
         return fixed
 
-    def config_prompt(self, test_repo_path='', retries=3, defaults={}):
+    def config_prompt(self, test_repo_path='', retries=3):
+        defaults = self.cli_args
         _path = defaults.get('repos_location')
         if retries == 3:
             log.info('Setting up repositories config')
--- a/rhodecode/tests/scripts/create_rc.sh	Thu Oct 11 20:31:37 2012 +0200
+++ b/rhodecode/tests/scripts/create_rc.sh	Thu Oct 11 20:56:01 2012 +0200
@@ -1,6 +1,6 @@
 psql -U postgres -h localhost -c 'drop database if exists rhodecode;'
 psql -U postgres -h localhost -c 'create database rhodecode;'
-paster setup-rhodecode rc.ini -q --user=marcink --password=qweqwe --email=marcin@python-blog.com --repos=/home/marcink/repos
+paster setup-rhodecode rc.ini --force-yes --user=marcink --password=qweqwe --email=marcin@python-blog.com --repos=/home/marcink/repos
 API_KEY=`psql -R " " -A -U postgres -h localhost -c "select api_key from users where admin=TRUE" -d rhodecode | awk '{print $2}'`
 echo "run those after running server"
 paster serve rc.ini --pid-file=rc.pid --daemon
--- a/rhodecode/websetup.py	Thu Oct 11 20:31:37 2012 +0200
+++ b/rhodecode/websetup.py	Thu Oct 11 20:56:01 2012 +0200
@@ -37,15 +37,15 @@
     """Place any commands to setup rhodecode here"""
     dbconf = conf['sqlalchemy.db1.url']
     dbmanage = DbManage(log_sql=True, dbconf=dbconf, root=conf['here'],
-                        tests=False)
-    dbmanage.create_tables(override=True, defaults=command.options.__dict__)
+                        tests=False, cli_args=command.options.__dict__)
+    dbmanage.create_tables(override=True)
     dbmanage.set_db_version()
-    opts = dbmanage.config_prompt(None, defaults=command.options.__dict__)
+    opts = dbmanage.config_prompt(None)
     dbmanage.create_settings(opts)
     dbmanage.create_default_user()
-    dbmanage.admin_prompt(defaults=command.options.__dict__)
+    dbmanage.admin_prompt()
     dbmanage.create_permissions()
     dbmanage.populate_default_permissions()
-    Session.commit()
+    Session().commit()
     load_environment(conf.global_conf, conf.local_conf, initial=True)
     dbmanage.finish()