Show More
@@ -32,7 +32,6 b' import logging' | |||||
32 | from os.path import dirname as dn, join as jn |
|
32 | from os.path import dirname as dn, join as jn | |
33 |
|
33 | |||
34 | from rhodecode import __dbversion__ |
|
34 | from rhodecode import __dbversion__ | |
35 | from rhodecode.model.db import |
|
|||
36 | from rhodecode.model import meta |
|
35 | from rhodecode.model import meta | |
37 |
|
36 | |||
38 | from rhodecode.lib.auth import get_crypt_password |
|
37 | from rhodecode.lib.auth import get_crypt_password | |
@@ -68,9 +67,9 b' class DbManage(object):' | |||||
68 | raise Exception('database already exists') |
|
67 | raise Exception('database already exists') | |
69 |
|
68 | |||
70 | def create_tables(self, override=False): |
|
69 | def create_tables(self, override=False): | |
|
70 | """Create a auth database | |||
71 |
|
|
71 | """ | |
72 | Create a auth database |
|
72 | ||
73 | """ |
|
|||
74 | self.check_for_db(override) |
|
73 | self.check_for_db(override) | |
75 | if self.db_exists: |
|
74 | if self.db_exists: | |
76 | log.info("database exist and it's going to be destroyed") |
|
75 | log.info("database exist and it's going to be destroyed") | |
@@ -101,6 +100,25 b' class DbManage(object):' | |||||
101 | raise |
|
100 | raise | |
102 | log.info('db version set to: %s', __dbversion__) |
|
101 | log.info('db version set to: %s', __dbversion__) | |
103 |
|
102 | |||
|
103 | def fix_repo_paths(self): | |||
|
104 | """Fixes a old rhodecode version path into new one without a '*' | |||
|
105 | """ | |||
|
106 | ||||
|
107 | paths = self.sa.query(RhodeCodeUi)\ | |||
|
108 | .filter(RhodeCodeUi.ui_key == '/')\ | |||
|
109 | .scalar() | |||
|
110 | ||||
|
111 | paths.ui_value = paths.ui_value.replace('*', '') | |||
|
112 | ||||
|
113 | try: | |||
|
114 | self.sa.add(paths) | |||
|
115 | self.sa.commit() | |||
|
116 | except: | |||
|
117 | self.sa.rollback() | |||
|
118 | raise | |||
|
119 | ||||
|
120 | ||||
|
121 | ||||
104 | def admin_prompt(self, second=False): |
|
122 | def admin_prompt(self, second=False): | |
105 | if not self.tests: |
|
123 | if not self.tests: | |
106 | import getpass |
|
124 | import getpass | |
@@ -136,7 +154,72 b' class DbManage(object):' | |||||
136 | self.create_user('test_regular', 'test12', 'test_regular@mail.com', False) |
|
154 | self.create_user('test_regular', 'test12', 'test_regular@mail.com', False) | |
137 | self.create_user('test_regular2', 'test12', 'test_regular2@mail.com', False) |
|
155 | self.create_user('test_regular2', 'test12', 'test_regular2@mail.com', False) | |
138 |
|
156 | |||
|
157 | def create_ui_settings(self): | |||
|
158 | """Creates ui settings, fills out hooks | |||
|
159 | and disables dotencode | |||
139 |
|
160 | |||
|
161 | """ | |||
|
162 | #HOOKS | |||
|
163 | hooks1_key = 'changegroup.update' | |||
|
164 | hooks1_ = self.sa.query(RhodeCodeUi)\ | |||
|
165 | .filter(RhodeCodeUi.ui_key == hooks1_key).scalar() | |||
|
166 | ||||
|
167 | hooks1 = RhodeCodeUi() if hooks1_ is None else hooks1_ | |||
|
168 | hooks1.ui_section = 'hooks' | |||
|
169 | hooks1.ui_key = hooks1_key | |||
|
170 | hooks1.ui_value = 'hg update >&2' | |||
|
171 | hooks1.ui_active = False | |||
|
172 | ||||
|
173 | hooks2_key = 'changegroup.repo_size' | |||
|
174 | hooks2_ = self.sa.query(RhodeCodeUi)\ | |||
|
175 | .filter(RhodeCodeUi.ui_key == hooks2_key).scalar() | |||
|
176 | ||||
|
177 | hooks2 = RhodeCodeUi() if hooks2_ is None else hooks2_ | |||
|
178 | hooks2.ui_section = 'hooks' | |||
|
179 | hooks2.ui_key = hooks2_key | |||
|
180 | hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size' | |||
|
181 | ||||
|
182 | hooks3 = RhodeCodeUi() | |||
|
183 | hooks3.ui_section = 'hooks' | |||
|
184 | hooks3.ui_key = 'pretxnchangegroup.push_logger' | |||
|
185 | hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action' | |||
|
186 | ||||
|
187 | hooks4 = RhodeCodeUi() | |||
|
188 | hooks4.ui_section = 'hooks' | |||
|
189 | hooks4.ui_key = 'preoutgoing.pull_logger' | |||
|
190 | hooks4.ui_value = 'python:rhodecode.lib.hooks.log_pull_action' | |||
|
191 | ||||
|
192 | #For mercurial 1.7 set backward comapatibility with format | |||
|
193 | dotencode_disable = RhodeCodeUi() | |||
|
194 | dotencode_disable.ui_section = 'format' | |||
|
195 | dotencode_disable.ui_key = 'dotencode' | |||
|
196 | dotencode_disable.ui_value = 'false' | |||
|
197 | ||||
|
198 | try: | |||
|
199 | self.sa.add(hooks1) | |||
|
200 | self.sa.add(hooks2) | |||
|
201 | self.sa.add(hooks3) | |||
|
202 | self.sa.add(hooks4) | |||
|
203 | self.sa.add(dotencode_disable) | |||
|
204 | self.sa.commit() | |||
|
205 | except: | |||
|
206 | self.sa.rollback() | |||
|
207 | raise | |||
|
208 | ||||
|
209 | ||||
|
210 | def create_ldap_options(self): | |||
|
211 | """Creates ldap settings""" | |||
|
212 | ||||
|
213 | try: | |||
|
214 | for k in ['ldap_active', 'ldap_host', 'ldap_port', 'ldap_ldaps', | |||
|
215 | 'ldap_dn_user', 'ldap_dn_pass', 'ldap_base_dn']: | |||
|
216 | ||||
|
217 | setting = RhodeCodeSettings(k, '') | |||
|
218 | self.sa.add(setting) | |||
|
219 | self.sa.commit() | |||
|
220 | except: | |||
|
221 | self.sa.rollback() | |||
|
222 | raise | |||
140 |
|
223 | |||
141 | def config_prompt(self, test_repo_path=''): |
|
224 | def config_prompt(self, test_repo_path=''): | |
142 | log.info('Setting up repositories config') |
|
225 | log.info('Setting up repositories config') | |
@@ -151,35 +234,9 b' class DbManage(object):' | |||||
151 | log.error('You entered wrong path: %s', path) |
|
234 | log.error('You entered wrong path: %s', path) | |
152 | sys.exit() |
|
235 | sys.exit() | |
153 |
|
236 | |||
154 | hooks1 = RhodeCodeUi() |
|
237 | self.create_ui_settings() | |
155 | hooks1.ui_section = 'hooks' |
|
|||
156 | hooks1.ui_key = 'changegroup.update' |
|
|||
157 | hooks1.ui_value = 'hg update >&2' |
|
|||
158 | hooks1.ui_active = False |
|
|||
159 |
|
||||
160 | hooks2 = RhodeCodeUi() |
|
|||
161 | hooks2.ui_section = 'hooks' |
|
|||
162 | hooks2.ui_key = 'changegroup.repo_size' |
|
|||
163 | hooks2.ui_value = 'python:rhodecode.lib.hooks.repo_size' |
|
|||
164 |
|
238 | |||
165 | hooks3 = RhodeCodeUi() |
|
239 | #HG UI OPTIONS | |
166 | hooks3.ui_section = 'hooks' |
|
|||
167 | hooks3.ui_key = 'pretxnchangegroup.push_logger' |
|
|||
168 | hooks3.ui_value = 'python:rhodecode.lib.hooks.log_push_action' |
|
|||
169 |
|
||||
170 | hooks4 = RhodeCodeUi() |
|
|||
171 | hooks4.ui_section = 'hooks' |
|
|||
172 | hooks4.ui_key = 'preoutgoing.pull_logger' |
|
|||
173 | hooks4.ui_value = 'python:rhodecode.lib.hooks.log_pull_action' |
|
|||
174 |
|
||||
175 | #for mercurial 1.7 set backward comapatibility with format |
|
|||
176 |
|
||||
177 | dotencode_disable = RhodeCodeUi() |
|
|||
178 | dotencode_disable.ui_section = 'format' |
|
|||
179 | dotencode_disable.ui_key = 'dotencode' |
|
|||
180 | dotencode_disable.ui_section = 'false' |
|
|||
181 |
|
||||
182 |
|
||||
183 | web1 = RhodeCodeUi() |
|
240 | web1 = RhodeCodeUi() | |
184 | web1.ui_section = 'web' |
|
241 | web1.ui_section = 'web' | |
185 | web1.ui_key = 'push_ssl' |
|
242 | web1.ui_key = 'push_ssl' | |
@@ -211,10 +268,6 b' class DbManage(object):' | |||||
211 |
|
268 | |||
212 |
|
269 | |||
213 | try: |
|
270 | try: | |
214 | self.sa.add(hooks1) |
|
|||
215 | self.sa.add(hooks2) |
|
|||
216 | self.sa.add(hooks3) |
|
|||
217 | self.sa.add(hooks4) |
|
|||
218 | self.sa.add(web1) |
|
271 | self.sa.add(web1) | |
219 | self.sa.add(web2) |
|
272 | self.sa.add(web2) | |
220 | self.sa.add(web3) |
|
273 | self.sa.add(web3) | |
@@ -222,17 +275,14 b' class DbManage(object):' | |||||
222 | self.sa.add(paths) |
|
275 | self.sa.add(paths) | |
223 | self.sa.add(hgsettings1) |
|
276 | self.sa.add(hgsettings1) | |
224 | self.sa.add(hgsettings2) |
|
277 | self.sa.add(hgsettings2) | |
225 | self.sa.add(dotencode_disable) |
|
|||
226 | for k in ['ldap_active', 'ldap_host', 'ldap_port', 'ldap_ldaps', |
|
|||
227 | 'ldap_dn_user', 'ldap_dn_pass', 'ldap_base_dn']: |
|
|||
228 |
|
||||
229 | setting = RhodeCodeSettings(k, '') |
|
|||
230 | self.sa.add(setting) |
|
|||
231 |
|
278 | |||
232 | self.sa.commit() |
|
279 | self.sa.commit() | |
233 | except: |
|
280 | except: | |
234 | self.sa.rollback() |
|
281 | self.sa.rollback() | |
235 | raise |
|
282 | raise | |
|
283 | ||||
|
284 | self.create_ldap_options() | |||
|
285 | ||||
236 | log.info('created ui config') |
|
286 | log.info('created ui config') | |
237 |
|
287 | |||
238 | def create_user(self, username, password, email='', admin=False): |
|
288 | def create_user(self, username, password, email='', admin=False): |
@@ -33,6 +33,7 b' from rhodecode.lib.dbmigrate.migrate.ver' | |||||
33 | from rhodecode.lib.dbmigrate.migrate.exceptions import \ |
|
33 | from rhodecode.lib.dbmigrate.migrate.exceptions import \ | |
34 | DatabaseNotControlledError |
|
34 | DatabaseNotControlledError | |
35 | from rhodecode.lib.utils import BasePasterCommand, Command, add_cache |
|
35 | from rhodecode.lib.utils import BasePasterCommand, Command, add_cache | |
|
36 | from rhodecode.lib.db_manage import DbManage | |||
36 |
|
37 | |||
37 | log = logging.getLogger(__name__) |
|
38 | log = logging.getLogger(__name__) | |
38 |
|
39 | |||
@@ -54,7 +55,7 b' class UpgradeDb(BasePasterCommand):' | |||||
54 |
|
55 | |||
55 | add_cache(config) |
|
56 | add_cache(config) | |
56 |
|
57 | |||
57 | #engine = engine_from_config(config, 'sqlalchemy.db1.') |
|
58 | ||
58 |
|
59 | |||
59 | repository_path = 'rhodecode/lib/dbmigrate' |
|
60 | repository_path = 'rhodecode/lib/dbmigrate' | |
60 | db_uri = config['sqlalchemy.db1.url'] |
|
61 | db_uri = config['sqlalchemy.db1.url'] | |
@@ -70,13 +71,27 b' class UpgradeDb(BasePasterCommand):' | |||||
70 | ' as version %s' % curr_version) |
|
71 | ' as version %s' % curr_version) | |
71 | api.version_control(db_uri, repository_path, curr_version) |
|
72 | api.version_control(db_uri, repository_path, curr_version) | |
72 |
|
73 | |||
|
74 | self.notify_msg(msg) | |||
73 |
|
75 | |||
74 | print msg |
|
|||
75 | #now we have our dbversion we can do upgrade |
|
76 | #now we have our dbversion we can do upgrade | |
|
77 | self.notify_msg('attempting to do database upgrade to version %s' \ | |||
|
78 | % __dbversion__) | |||
|
79 | ||||
|
80 | api.upgrade(db_uri, repository_path, __dbversion__) | |||
|
81 | self.notify_msg('Schema upgrade completed') | |||
76 |
|
82 | |||
77 | msg = 'attempting to do database upgrade to version %s' % __dbversion__ |
|
83 | #we need to make now some extra operations into database | |
78 | print msg |
|
84 | self.notify_msg('Prociding with database updates') | |
79 | api.upgrade(db_uri, repository_path, __dbversion__) |
|
85 | ||
|
86 | dbmanage = DbManage(log_sql=True, dbconf=db_uri, | |||
|
87 | root=config['here'], tests=False) | |||
|
88 | ||||
|
89 | self.notify_msg('Patching repo paths for newer version of rhodecode') | |||
|
90 | dbmanage.fix_repo_paths() | |||
|
91 | ||||
|
92 | self.notify_msg('Changing ui settings') | |||
|
93 | dbmanage.create_ui_settings() | |||
|
94 | ||||
80 |
|
95 | |||
81 | def update_parser(self): |
|
96 | def update_parser(self): | |
82 | self.parser.add_option('--sql', |
|
97 | self.parser.add_option('--sql', |
@@ -49,25 +49,23 b' def upgrade(migrate_engine):' | |||||
49 | #========================================================================== |
|
49 | #========================================================================== | |
50 | # Upgrade of `repositories` table |
|
50 | # Upgrade of `repositories` table | |
51 | #========================================================================== |
|
51 | #========================================================================== | |
52 |
tblname = ' |
|
52 | tblname = 'repositories' | |
53 | tbl = Table(tblname, MetaData(bind=migrate_engine), autoload=True, |
|
53 | tbl = Table(tblname, MetaData(bind=migrate_engine), autoload=True, | |
54 | autoload_with=migrate_engine) |
|
54 | autoload_with=migrate_engine) | |
55 |
|
55 | |||
56 | #ADD repo_type column |
|
56 | #ADD repo_type column# | |
57 | repo_type = Column("repo_type", String(length=None, convert_unicode=False, |
|
57 | repo_type = Column("repo_type", String(length=None, convert_unicode=False, | |
58 | assert_unicode=None), |
|
58 | assert_unicode=None), | |
59 | nullable=True, unique=False, default='hg') |
|
59 | nullable=True, unique=False, default='hg') | |
60 |
|
60 | |||
61 | repo_type.create(tbl, populate_default=True) |
|
61 | repo_type.create(tbl, populate_default=True) | |
62 | repo_type.alter(nullable=False) |
|
62 | #repo_type.alter(nullable=False) | |
63 |
|
63 | |||
64 | #ADD statistics column |
|
64 | #ADD statistics column# | |
65 | enable_statistics = Column("statistics", Boolean(), nullable=True, |
|
65 | enable_statistics = Column("statistics", Boolean(), nullable=True, | |
66 | unique=None, default=True) |
|
66 | unique=None, default=True) | |
67 | enable_statistics.create(tbl) |
|
67 | enable_statistics.create(tbl) | |
68 |
|
68 | |||
69 |
|
||||
70 |
|
||||
71 | #========================================================================== |
|
69 | #========================================================================== | |
72 | # Add table `user_followings` |
|
70 | # Add table `user_followings` | |
73 | #========================================================================== |
|
71 | #========================================================================== |
@@ -563,6 +563,19 b' class BasePasterCommand(Command):' | |||||
563 | takes_config_file = 1 |
|
563 | takes_config_file = 1 | |
564 | requires_config_file = True |
|
564 | requires_config_file = True | |
565 |
|
565 | |||
|
566 | def notify_msg(self, msg, log=False): | |||
|
567 | """Make a notification to user, additionally if logger is passed | |||
|
568 | it logs this action using given logger | |||
|
569 | ||||
|
570 | :param msg: message that will be printed to user | |||
|
571 | :param log: logging instance, to use to additionally log this message | |||
|
572 | ||||
|
573 | """ | |||
|
574 | print msg | |||
|
575 | if log and isinstance(log, logging): | |||
|
576 | log(msg) | |||
|
577 | ||||
|
578 | ||||
566 | def run(self, args): |
|
579 | def run(self, args): | |
567 | """ |
|
580 | """ | |
568 | Overrides Command.run |
|
581 | Overrides Command.run |
General Comments 0
You need to be logged in to leave comments.
Login now