Changeset - 29630805893d
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 13 years ago 2012-10-11 20:56:01
marcin@python-works.com
Implemented proposed changes from pull request #77
4 files changed with 33 insertions and 14 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/setup_rhodecode.py
Show inline comments
 
@@ -47,24 +47,34 @@ class SetupCommand(AbstractInstallComman
 
                      help='Absolute path to repositories location')
 
    parser.add_option('--name',
 
                      action='store',
 
                      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]
 
        section = self.options.section_name
 
        if section is None:
 
            if '#' in config_spec:
 
                config_spec, section = config_spec.split('#', 1)
 
            else:
 
                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:'):
 
            config_spec = 'config:' + config_spec
 
        if plain_section != 'main':
 
            config_spec += '#' + plain_section
rhodecode/lib/db_manage.py
Show inline comments
 
@@ -54,38 +54,45 @@ def notify(msg):
 
    """
 
    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):
 
    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()
 

	
 
        checkfirst = not override
 
        Base.metadata.create_all(checkfirst=checkfirst)
 
        log.info('Created tables for %s' % self.dbname)
 
@@ -325,17 +332,18 @@ class DbManage(object):
 
            self.sa.add(hgsettings3)
 
            self.sa.commit()
 
        except:
 
            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')
 

	
 
            def get_password():
 
                password = getpass.getpass('Specify admin password '
 
@@ -504,13 +512,14 @@ class DbManage(object):
 
            for p in u2p:
 
                Session().delete(p)
 
            fixed = True
 
            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')
 

	
 
        if _path is not None:
 
            path = _path
rhodecode/tests/scripts/create_rc.sh
Show inline comments
 
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
 
sleep 3
 
rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo1 password:qweqwe email:demo1@rhodecode.org
 
rhodecode-api --apikey=$API_KEY --apihost=http://127.0.0.1:5001 create_user username:demo2 password:qweqwe email:demo2@rhodecode.org
rhodecode/websetup.py
Show inline comments
 
@@ -34,18 +34,18 @@ log = logging.getLogger(__name__)
 

	
 

	
 
def setup_app(command, conf, vars):
 
    """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()
0 comments (0 inline, 0 general)