comparison rhodecode/lib/db_manage.py @ 2284:e285aa097a81 beta

new setup-rhodecode command with optional defaults
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 16 May 2012 23:16:04 +0200
parents 1477e048292e
children 393c53cbd0d8 533a126dc9ab
comparison
equal deleted inserted replaced
2281:1927dcb05178 2284:e285aa097a81
236 self.sa.commit() 236 self.sa.commit()
237 except: 237 except:
238 self.sa.rollback() 238 self.sa.rollback()
239 raise 239 raise
240 240
241 def admin_prompt(self, second=False): 241 def admin_prompt(self, second=False, defaults={}):
242 if not self.tests: 242 if not self.tests:
243 import getpass 243 import getpass
244
245 # defaults
246 username = defaults.get('username')
247 password = defaults.get('password')
248 email = defaults.get('email')
244 249
245 def get_password(): 250 def get_password():
246 password = getpass.getpass('Specify admin password ' 251 password = getpass.getpass('Specify admin password '
247 '(min 6 chars):') 252 '(min 6 chars):')
248 confirm = getpass.getpass('Confirm password:') 253 confirm = getpass.getpass('Confirm password:')
253 if len(password) < 6: 258 if len(password) < 6:
254 log.error('password is to short use at least 6 characters') 259 log.error('password is to short use at least 6 characters')
255 return False 260 return False
256 261
257 return password 262 return password
258 263 if username is None:
259 username = raw_input('Specify admin username:') 264 username = raw_input('Specify admin username:')
260 265 if password is None:
261 password = get_password()
262 if not password:
263 #second try
264 password = get_password() 266 password = get_password()
265 if not password: 267 if not password:
266 sys.exit() 268 #second try
267 269 password = get_password()
268 email = raw_input('Specify admin email:') 270 if not password:
271 sys.exit()
272 if email is None:
273 email = raw_input('Specify admin email:')
269 self.create_user(username, password, email, True) 274 self.create_user(username, password, email, True)
270 else: 275 else:
271 log.info('creating admin and regular test users') 276 log.info('creating admin and regular test users')
272 from rhodecode.tests import TEST_USER_ADMIN_LOGIN,\ 277 from rhodecode.tests import TEST_USER_ADMIN_LOGIN,\
273 TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL,\ 278 TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL,\
368 373
369 if default is None: 374 if default is None:
370 log.debug('missing default permission for group %s adding' % g) 375 log.debug('missing default permission for group %s adding' % g)
371 ReposGroupModel()._create_default_perms(g) 376 ReposGroupModel()._create_default_perms(g)
372 377
373 def config_prompt(self, test_repo_path='', retries=3): 378 def config_prompt(self, test_repo_path='', retries=3, defaults={}):
379 _path = defaults.get('repos_location')
374 if retries == 3: 380 if retries == 3:
375 log.info('Setting up repositories config') 381 log.info('Setting up repositories config')
376 382
377 if not self.tests and not test_repo_path: 383 if _path is not None:
384 path = _path
385 elif not self.tests and not test_repo_path:
378 path = raw_input( 386 path = raw_input(
379 'Enter a valid absolute path to store repositories. ' 387 'Enter a valid absolute path to store repositories. '
380 'All repositories in that path will be added automatically:' 388 'All repositories in that path will be added automatically:'
381 ) 389 )
382 else: 390 else: