Show More
@@ -50,6 +50,16 b' class SetupCommand(AbstractInstallComman' | |||
|
50 | 50 | dest='section_name', |
|
51 | 51 | default=None, |
|
52 | 52 | help='The name of the section to set up (default: app:main)') |
|
53 | parser.add_option('--force-yes', | |
|
54 | action='store_true', | |
|
55 | dest='force_ask', | |
|
56 | default=None, | |
|
57 | help='Force yes to every question') | |
|
58 | parser.add_option('--force-no', | |
|
59 | action='store_false', | |
|
60 | dest='force_ask', | |
|
61 | default=None, | |
|
62 | help='Force no to every question') | |
|
53 | 63 | |
|
54 | 64 | def command(self): |
|
55 | 65 | config_spec = self.args[0] |
@@ -61,7 +71,7 b' class SetupCommand(AbstractInstallComman' | |||
|
61 | 71 | section = 'main' |
|
62 | 72 | if not ':' in section: |
|
63 | 73 | plain_section = section |
|
64 | section = 'app:'+section | |
|
74 | section = 'app:' + section | |
|
65 | 75 | else: |
|
66 | 76 | plain_section = section.split(':', 1)[0] |
|
67 | 77 | if not config_spec.startswith('config:'): |
@@ -57,32 +57,39 b' def notify(msg):' | |||
|
57 | 57 | |
|
58 | 58 | |
|
59 | 59 | class DbManage(object): |
|
60 | def __init__(self, log_sql, dbconf, root, tests=False): | |
|
60 | def __init__(self, log_sql, dbconf, root, tests=False, cli_args={}): | |
|
61 | 61 | self.dbname = dbconf.split('/')[-1] |
|
62 | 62 | self.tests = tests |
|
63 | 63 | self.root = root |
|
64 | 64 | self.dburi = dbconf |
|
65 | 65 | self.log_sql = log_sql |
|
66 | 66 | self.db_exists = False |
|
67 | self.cli_args = cli_args | |
|
67 | 68 | self.init_db() |
|
69 | global ask_ok | |
|
70 | ||
|
71 | if self.cli_args.get('force_ask') is True: | |
|
72 | ask_ok = lambda *args, **kwargs: True | |
|
73 | elif self.cli_args.get('force_ask') is False: | |
|
74 | ask_ok = lambda *args, **kwargs: False | |
|
68 | 75 | |
|
69 | 76 | def init_db(self): |
|
70 | 77 | engine = create_engine(self.dburi, echo=self.log_sql) |
|
71 | 78 | init_model(engine) |
|
72 | 79 | self.sa = Session() |
|
73 | 80 | |
|
74 |
def create_tables(self, override=False |
|
|
81 | def create_tables(self, override=False): | |
|
75 | 82 | """ |
|
76 | 83 | Create a auth database |
|
77 | 84 | """ |
|
78 | quiet = defaults.get('quiet') | |
|
85 | ||
|
79 | 86 | log.info("Any existing database is going to be destroyed") |
|
80 |
if self.tests |
|
|
87 | if self.tests: | |
|
81 | 88 | destroy = True |
|
82 | 89 | else: |
|
83 | 90 | destroy = ask_ok('Are you sure to destroy old database ? [y/n]') |
|
84 | 91 | if not destroy: |
|
85 | sys.exit() | |
|
92 | sys.exit('Nothing done') | |
|
86 | 93 | if destroy: |
|
87 | 94 | Base.metadata.drop_all() |
|
88 | 95 | |
@@ -328,11 +335,12 b' class DbManage(object):' | |||
|
328 | 335 | self.sa.rollback() |
|
329 | 336 | raise |
|
330 | 337 | |
|
331 |
def admin_prompt(self, second=False |
|
|
338 | def admin_prompt(self, second=False): | |
|
332 | 339 | if not self.tests: |
|
333 | 340 | import getpass |
|
334 | 341 | |
|
335 | 342 | # defaults |
|
343 | defaults = self.cli_args | |
|
336 | 344 | username = defaults.get('username') |
|
337 | 345 | password = defaults.get('password') |
|
338 | 346 | email = defaults.get('email') |
@@ -507,7 +515,8 b' class DbManage(object):' | |||
|
507 | 515 | self.populate_default_permissions() |
|
508 | 516 | return fixed |
|
509 | 517 | |
|
510 |
def config_prompt(self, test_repo_path='', retries=3 |
|
|
518 | def config_prompt(self, test_repo_path='', retries=3): | |
|
519 | defaults = self.cli_args | |
|
511 | 520 | _path = defaults.get('repos_location') |
|
512 | 521 | if retries == 3: |
|
513 | 522 | log.info('Setting up repositories config') |
@@ -1,6 +1,6 b'' | |||
|
1 | 1 | psql -U postgres -h localhost -c 'drop database if exists rhodecode;' |
|
2 | 2 | psql -U postgres -h localhost -c 'create database rhodecode;' |
|
3 |
paster setup-rhodecode rc.ini - |
|
|
3 | paster setup-rhodecode rc.ini --force-yes --user=marcink --password=qweqwe --email=marcin@python-blog.com --repos=/home/marcink/repos | |
|
4 | 4 | API_KEY=`psql -R " " -A -U postgres -h localhost -c "select api_key from users where admin=TRUE" -d rhodecode | awk '{print $2}'` |
|
5 | 5 | echo "run those after running server" |
|
6 | 6 | paster serve rc.ini --pid-file=rc.pid --daemon |
@@ -37,15 +37,15 b' def setup_app(command, conf, vars):' | |||
|
37 | 37 | """Place any commands to setup rhodecode here""" |
|
38 | 38 | dbconf = conf['sqlalchemy.db1.url'] |
|
39 | 39 | dbmanage = DbManage(log_sql=True, dbconf=dbconf, root=conf['here'], |
|
40 | tests=False) | |
|
41 |
dbmanage.create_tables(override=True |
|
|
40 | tests=False, cli_args=command.options.__dict__) | |
|
41 | dbmanage.create_tables(override=True) | |
|
42 | 42 | dbmanage.set_db_version() |
|
43 |
opts = dbmanage.config_prompt(None |
|
|
43 | opts = dbmanage.config_prompt(None) | |
|
44 | 44 | dbmanage.create_settings(opts) |
|
45 | 45 | dbmanage.create_default_user() |
|
46 |
dbmanage.admin_prompt( |
|
|
46 | dbmanage.admin_prompt() | |
|
47 | 47 | dbmanage.create_permissions() |
|
48 | 48 | dbmanage.populate_default_permissions() |
|
49 | Session.commit() | |
|
49 | Session().commit() | |
|
50 | 50 | load_environment(conf.global_conf, conf.local_conf, initial=True) |
|
51 | 51 | dbmanage.finish() |
General Comments 0
You need to be logged in to leave comments.
Login now