|
36 | 36 | import time
|
37 | 37 | import shutil
|
38 | 38 | import fnmatch
|
| 39 | +from tempfile import TemporaryDirectory |
39 | 40 | started = time.time()
|
40 | 41 |
|
41 | 42 | import supybot
|
42 | 43 | import logging
|
43 | 44 | import traceback
|
44 | 45 |
|
45 | 46 | # We need to do this before we import conf.
|
46 |
| -if not os.path.exists('test-conf'): |
47 |
| - os.mkdir('test-conf') |
| 47 | +main_temp_dir = TemporaryDirectory() |
48 | 48 |
|
49 |
| -registryFilename = os.path.join('test-conf', 'test.conf') |
50 |
| -fd = open(registryFilename, 'w') |
51 |
| -fd.write(""" |
| 49 | +os.makedirs(os.path.join(main_temp_dir.name, 'conf')) |
| 50 | +os.makedirs(os.path.join(main_temp_dir.name, 'data')) |
| 51 | +os.makedirs(os.path.join(main_temp_dir.name, 'logs')) |
| 52 | + |
| 53 | +registryFilename = os.path.join(main_temp_dir.name, 'conf', 'test.conf') |
| 54 | +with open(registryFilename, 'w') as fd: |
| 55 | + fd.write(""" |
52 | 56 | supybot.directories.backup: /dev/null
|
53 |
| -supybot.directories.conf: %(base_dir)s/test-conf |
54 |
| -supybot.directories.data: %(base_dir)s/test-data |
55 |
| -supybot.directories.log: %(base_dir)s/test-logs |
| 57 | +supybot.directories.conf: {temp_conf} |
| 58 | +supybot.directories.data: {temp_data} |
| 59 | +supybot.directories.log: {temp_logs} |
56 | 60 | supybot.reply.whenNotCommand: True
|
57 | 61 | supybot.log.stdout: False
|
58 | 62 | supybot.log.stdout.level: ERROR
|
|
67 | 71 | supybot.networks.testnet3.server: should.not.need.this
|
68 | 72 | supybot.nick: test
|
69 | 73 | supybot.databases.users.allowUnregistration: True
|
70 |
| -""" % {'base_dir': os.getcwd()}) |
71 |
| -fd.close() |
| 74 | +""".format( |
| 75 | + temp_conf=os.path.join(main_temp_dir.name, 'conf'), |
| 76 | + temp_data=os.path.join(main_temp_dir.name, 'data'), |
| 77 | + temp_logs=os.path.join(main_temp_dir.name, 'logs') |
| 78 | + )) |
72 | 79 |
|
73 | 80 | import supybot.registry as registry
|
74 | 81 | registry.open_registry(registryFilename)
|
@@ -251,6 +258,9 @@ def main():
|
251 | 258 | if result.wasSuccessful():
|
252 | 259 | sys.exit(0)
|
253 | 260 | else:
|
| 261 | + # Deactivate autocleaning for the temporary directiories to allow inspection. |
| 262 | + main_temp_dir._finalizer.detach() |
| 263 | + print(f"Temporary directory path: {main_temp_dir.name}") |
254 | 264 | sys.exit(1)
|
255 | 265 |
|
256 | 266 |
|
|
0 commit comments