|
1 | 1 | # coding: utf-8 |
2 | 2 |
|
3 | | -import atexit |
4 | 3 | import io |
5 | 4 | import os |
6 | 5 | import shutil |
|
10 | 9 |
|
11 | 10 | from enum import Enum |
12 | 11 |
|
| 12 | +from .cache import cached_initdb as _cached_initdb |
| 13 | + |
13 | 14 | from .config import TestgresConfig |
14 | 15 |
|
15 | 16 | from .connection import \ |
|
27 | 28 | from .exceptions import \ |
28 | 29 | CatchUpException, \ |
29 | 30 | ExecUtilException, \ |
30 | | - InitNodeException, \ |
31 | 31 | QueryException, \ |
32 | 32 | StartNodeException, \ |
33 | 33 | TimeoutException |
@@ -875,47 +875,3 @@ def connect(self, dbname='postgres', username=None): |
875 | 875 |
|
876 | 876 | return NodeConnection( |
877 | 877 | parent_node=self, dbname=dbname, username=username) |
878 | | - |
879 | | - |
880 | | -def _cached_initdb(data_dir, initdb_logfile, initdb_params=[]): |
881 | | - """ |
882 | | - Perform initdb or use cached node files. |
883 | | - """ |
884 | | - |
885 | | - def call_initdb(_data_dir): |
886 | | - try: |
887 | | - _params = [get_bin_path("initdb"), "-D", _data_dir, "-N"] |
888 | | - _execute_utility(_params + initdb_params, initdb_logfile) |
889 | | - except ExecUtilException as e: |
890 | | - raise InitNodeException(_explain_exception(e)) |
891 | | - |
892 | | - # Call initdb if we have custom params |
893 | | - if initdb_params or not TestgresConfig.cache_initdb: |
894 | | - call_initdb(data_dir) |
895 | | - # Else we can use cached dir |
896 | | - else: |
897 | | - # Set default temp dir for cached initdb |
898 | | - if TestgresConfig.cached_initdb_dir is None: |
899 | | - |
900 | | - def rm_cached_data_dir(rm_dir): |
901 | | - shutil.rmtree(rm_dir, ignore_errors=True) |
902 | | - |
903 | | - # Create default temp dir |
904 | | - TestgresConfig.cached_initdb_dir = tempfile.mkdtemp() |
905 | | - |
906 | | - # Schedule cleanup |
907 | | - atexit.register(rm_cached_data_dir, |
908 | | - TestgresConfig.cached_initdb_dir) |
909 | | - |
910 | | - # Fetch cached initdb dir |
911 | | - cached_data_dir = TestgresConfig.cached_initdb_dir |
912 | | - |
913 | | - # Initialize cached initdb |
914 | | - if not os.listdir(cached_data_dir): |
915 | | - call_initdb(cached_data_dir) |
916 | | - |
917 | | - try: |
918 | | - # Copy cached initdb to current data dir |
919 | | - shutil.copytree(cached_data_dir, data_dir) |
920 | | - except Exception as e: |
921 | | - raise InitNodeException(_explain_exception(e)) |
0 commit comments