30 import getpass |
30 import getpass |
31 from hashlib import sha1 # pylint: disable=E0611 |
31 from hashlib import sha1 # pylint: disable=E0611 |
32 from os.path import abspath, join, exists, split, isdir, dirname |
32 from os.path import abspath, join, exists, split, isdir, dirname |
33 from functools import partial |
33 from functools import partial |
34 |
34 |
|
35 import filelock |
35 from six import text_type |
36 from six import text_type |
36 from six.moves import cPickle as pickle |
37 from six.moves import cPickle as pickle |
37 |
38 |
38 from logilab.common.decorators import cached, clear_cache |
39 from logilab.common.decorators import cached, clear_cache |
39 |
40 |
468 if ``test_db_id is DEFAULT_EMPTY_DB_ID`` self.init_test_database is |
469 if ``test_db_id is DEFAULT_EMPTY_DB_ID`` self.init_test_database is |
469 called. otherwise, DEFAULT_EMPTY_DB_ID is build/restored and |
470 called. otherwise, DEFAULT_EMPTY_DB_ID is build/restored and |
470 ``pre_setup_func`` to setup the database. |
471 ``pre_setup_func`` to setup the database. |
471 |
472 |
472 This function backup any database it build""" |
473 This function backup any database it build""" |
473 if self.has_cache(test_db_id): |
474 lockfile = join(self._ensure_test_backup_db_dir(), |
474 return # test_db_id, 'already in cache' |
475 '{}.lock'.format(test_db_id)) |
475 if test_db_id is DEFAULT_EMPTY_DB_ID: |
476 with filelock.FileLock(lockfile): |
476 self.init_test_database() |
477 if self.has_cache(test_db_id): |
477 else: |
478 return # test_db_id, 'already in cache' |
478 print('Building %s for database %s' % (test_db_id, self.dbname)) |
479 if test_db_id is DEFAULT_EMPTY_DB_ID: |
479 self.build_db_cache(DEFAULT_EMPTY_DB_ID) |
480 self.init_test_database() |
480 self.restore_database(DEFAULT_EMPTY_DB_ID) |
481 else: |
481 self.get_repo(startup=True) |
482 print('Building %s for database %s' % (test_db_id, self.dbname)) |
482 cnx = self.get_cnx() |
483 self.build_db_cache(DEFAULT_EMPTY_DB_ID) |
483 with cnx: |
484 self.restore_database(DEFAULT_EMPTY_DB_ID) |
484 pre_setup_func(cnx, self.config) |
485 self.get_repo(startup=True) |
485 cnx.commit() |
486 cnx = self.get_cnx() |
486 self.backup_database(test_db_id) |
487 with cnx: |
|
488 pre_setup_func(cnx, self.config) |
|
489 cnx.commit() |
|
490 self.backup_database(test_db_id) |
487 |
491 |
488 |
492 |
489 class NoCreateDropDatabaseHandler(TestDataBaseHandler): |
493 class NoCreateDropDatabaseHandler(TestDataBaseHandler): |
490 """This handler is used if config.skip_db_create_and_restore is True |
494 """This handler is used if config.skip_db_create_and_restore is True |
491 |
495 |