Changeset - 658ccf9727ef
[Not reviewed]
beta
0 1 0
Mads Kiilerich - 13 years ago 2013-04-04 16:51:38
madski@unity3d.com
setup_rhodecode: fix --force-no - force_ask is tri-state

Missed in 260a7a01b.
1 file changed with 4 insertions and 5 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/db_manage.py
Show inline comments
 
@@ -46,54 +46,53 @@ from rhodecode.model.meta import Session
 
from rhodecode.model.repo import RepoModel
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
def notify(msg):
 
    """
 
    Notification for migrations messages
 
    """
 
    ml = len(msg) + (4 * 2)
 
    print >> sys.stdout, ('*** %s ***\n%s' % (msg, '*' * ml)).upper()
 

	
 

	
 
class DbManage(object):
 
    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()
 

	
 
        force_ask = self.cli_args.get('force_ask')
 
        if force_ask is not None:
 
        global ask_ok
 

	
 
        if self.cli_args.get('force_ask'):
 
            ask_ok = lambda *args, **kwargs: True
 
        elif not self.cli_args.get('force_ask'):
 
            ask_ok = lambda *args, **kwargs: False
 
            ask_ok = lambda *args, **kwargs: force_ask
 

	
 
    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):
 
        """
 
        Create a auth database
 
        """
 

	
 
        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('Nothing done')
 
        if destroy:
 
            Base.metadata.drop_all()
 

	
 
        checkfirst = not override
 
        Base.metadata.create_all(checkfirst=checkfirst)
 
        log.info('Created tables for %s' % self.dbname)
0 comments (0 inline, 0 general)