comparison rhodecode/lib/utils.py @ 688:8acbfa837180 beta

Tests rewrite for 1.2 added some globals configs to make tests easier. Fixed search index_location to take from configuration files now fixed git http_user_agent bug
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 14 Nov 2010 17:24:32 +0100
parents 2abb398cd9a7
children ecc566f8b69f
comparison
equal deleted inserted replaced
687:b9442a8b5e02 688:8acbfa837180
62 then have git client version given. 62 then have git client version given.
63 63
64 :param environ: 64 :param environ:
65 """ 65 """
66 http_user_agent = environ.get('HTTP_USER_AGENT') 66 http_user_agent = environ.get('HTTP_USER_AGENT')
67 if http_user_agent.startswith('git'): 67 if http_user_agent and http_user_agent.startswith('git'):
68 return True 68 return True
69 return False 69 return False
70 70
71 def action_logger(user, action, repo, ipaddr, sa=None): 71 def action_logger(user, action, repo, ipaddr, sa=None):
72 """ 72 """
453 :param repo_location: 453 :param repo_location:
454 :param full_index: 454 :param full_index:
455 """ 455 """
456 from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon 456 from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon
457 from rhodecode.lib.pidlock import DaemonLock, LockHeld 457 from rhodecode.lib.pidlock import DaemonLock, LockHeld
458 from rhodecode.lib.indexers import IDX_LOCATION
459 import shutil 458 import shutil
460 459
461 if os.path.exists(IDX_LOCATION): 460 index_location = os.path.join(repo_location, 'index')
462 shutil.rmtree(IDX_LOCATION) 461 if os.path.exists(index_location):
462 shutil.rmtree(index_location)
463 463
464 try: 464 try:
465 l = DaemonLock() 465 l = DaemonLock()
466 WhooshIndexingDaemon(repo_location=repo_location)\ 466 WhooshIndexingDaemon(index_location=index_location,
467 repo_location=repo_location)\
467 .run(full_index=full_index) 468 .run(full_index=full_index)
468 l.release() 469 l.release()
469 except LockHeld: 470 except LockHeld:
470 pass 471 pass
471 472
472 def create_test_env(repos_test_path, config): 473 def create_test_env(repos_test_path, config):
473 """Makes a fresh database and 474 """Makes a fresh database and
474 install test repository into tmp dir 475 install test repository into tmp dir
475 """ 476 """
476 from rhodecode.lib.db_manage import DbManage 477 from rhodecode.lib.db_manage import DbManage
478 from rhodecode.tests import HG_REPO, GIT_REPO, NEW_HG_REPO, NEW_GIT_REPO, \
479 HG_FORK, GIT_FORK, TESTS_TMP_PATH
477 import tarfile 480 import tarfile
478 import shutil 481 import shutil
479 from os.path import dirname as dn, join as jn, abspath 482 from os.path import dirname as dn, join as jn, abspath
480 483
481 log = logging.getLogger('TestEnvCreator') 484 log = logging.getLogger('TestEnvCreator')
507 dbmanage.admin_prompt() 510 dbmanage.admin_prompt()
508 dbmanage.create_permissions() 511 dbmanage.create_permissions()
509 dbmanage.populate_default_permissions() 512 dbmanage.populate_default_permissions()
510 513
511 #PART TWO make test repo 514 #PART TWO make test repo
512 log.debug('making test vcs repo') 515 log.debug('making test vcs repositories')
513 if os.path.isdir('/tmp/vcs_test'): 516
514 shutil.rmtree('/tmp/vcs_test') 517 #remove old one from previos tests
515 518 for r in [HG_REPO, GIT_REPO, NEW_HG_REPO, NEW_GIT_REPO, HG_FORK, GIT_FORK]:
519
520 if os.path.isdir(jn(TESTS_TMP_PATH, r)):
521 log.debug('removing %s', r)
522 shutil.rmtree(jn(TESTS_TMP_PATH, r))
523
524 #CREATE DEFAULT HG REPOSITORY
516 cur_dir = dn(dn(abspath(__file__))) 525 cur_dir = dn(dn(abspath(__file__)))
517 tar = tarfile.open(jn(cur_dir, 'tests', "vcs_test.tar.gz")) 526 tar = tarfile.open(jn(cur_dir, 'tests', "vcs_test_hg.tar.gz"))
518 tar.extractall('/tmp') 527 tar.extractall(jn(TESTS_TMP_PATH, HG_REPO))
519 tar.close() 528 tar.close()
520 529
521 class UpgradeDb(command.Command): 530 class UpgradeDb(command.Command):
522 """Command used for paster to upgrade our database to newer version 531 """Command used for paster to upgrade our database to newer version
523 """ 532 """