Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0459830

Browse files
committed
add some prefixes for mkdtemp()
1 parentd800f48 commit0459830

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

‎testgres/backup.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from .constsimport \
1010
DATA_DIR, \
11+
TMP_NODE, \
12+
TMP_BACKUP, \
1113
PG_CONF_FILE, \
1214
BACKUP_LOG_FILE, \
1315
DEFAULT_XLOG_METHOD
@@ -49,7 +51,7 @@ def __init__(self,
4951

5052
# Set default arguments
5153
username=usernameordefault_username()
52-
base_dir=base_dirortempfile.mkdtemp()
54+
base_dir=base_dirortempfile.mkdtemp(prefix=TMP_BACKUP)
5355

5456
# public
5557
self.original_node=node
@@ -96,7 +98,7 @@ def _prepare_dir(self, destroy):
9698
available=notdestroy
9799

98100
ifavailable:
99-
dest_base_dir=tempfile.mkdtemp()
101+
dest_base_dir=tempfile.mkdtemp(prefix=TMP_NODE)
100102

101103
data1=os.path.join(self.base_dir,DATA_DIR)
102104
data2=os.path.join(dest_base_dir,DATA_DIR)

‎testgres/config.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
fromcontextlibimportcontextmanager
99

10+
from .constsimportTMP_CACHE
11+
1012

1113
classGlobalConfig(object):
1214
"""
@@ -101,6 +103,7 @@ def copy(self):
101103
config_stack= []
102104

103105

106+
@atexit.register
104107
defrm_cached_initdb_dirs():
105108
fordincached_initdb_dirs:
106109
shutil.rmtree(d,ignore_errors=True)
@@ -161,8 +164,5 @@ def configure_testgres(**options):
161164
testgres_config.update(options)
162165

163166

164-
# NOTE: to be executed at exit()
165-
atexit.register(rm_cached_initdb_dirs)
166-
167167
# NOTE: assign initial cached dir for initdb
168-
testgres_config.cached_initdb_dir=tempfile.mkdtemp()
168+
testgres_config.cached_initdb_dir=tempfile.mkdtemp(prefix=TMP_CACHE)

‎testgres/consts.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
DATA_DIR="data"
55
LOGS_DIR="logs"
66

7+
# prefixes for temp dirs
8+
TMP_NODE='tgsn_'
9+
TMP_CACHE='tgsc_'
10+
TMP_BACKUP='tgsb_'
11+
712
# names for config files
813
RECOVERY_CONF_FILE="recovery.conf"
914
PG_AUTO_CONF_FILE="postgresql.auto.conf"

‎testgres/node.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .constsimport \
2424
DATA_DIR, \
2525
LOGS_DIR, \
26+
TMP_NODE, \
2627
PG_CONF_FILE, \
2728
PG_AUTO_CONF_FILE, \
2829
HBA_CONF_FILE, \
@@ -106,7 +107,9 @@ def __enter__(self):
106107
def__exit__(self,type,value,traceback):
107108
self.free_port()
108109

109-
got_exception=valueisnotNone
110+
# NOTE: ctrl+C does not count!
111+
got_exception=typeisnotNoneandtype!=KeyboardInterrupt
112+
110113
c1=self.cleanup_on_good_exitandnotgot_exception
111114
c2=self.cleanup_on_bad_exitandgot_exception
112115

@@ -152,8 +155,9 @@ def _try_shutdown(self, max_attempts):
152155
exceptExecUtilException:
153156
pass# one more time
154157
exceptException:
155-
# TODO: probably kill stray instance
158+
# TODO: probablyshouldkill stray instance
156159
eprint('cannot stop node {}'.format(self.name))
160+
break
157161

158162
attempts+=1
159163

@@ -195,7 +199,7 @@ def _create_recovery_conf(self, username):
195199

196200
def_prepare_dirs(self):
197201
ifnotself.base_dir:
198-
self.base_dir=tempfile.mkdtemp()
202+
self.base_dir=tempfile.mkdtemp(prefix=TMP_NODE)
199203

200204
ifnotos.path.exists(self.base_dir):
201205
os.makedirs(self.base_dir)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp