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