File: tmp.py

package info (click to toggle)
python-nixio 1.5.4%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,888 kB
  • sloc: python: 12,527; cpp: 832; makefile: 25
file content (16 lines) | stat: -rw-r--r-- 297 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import os
import shutil
from tempfile import mkdtemp


class TempDir:

    def __init__(self, prefix=None):
        self.path = mkdtemp(prefix=prefix)

    def cleanup(self):
        if os.path.exists(self.path):
            shutil.rmtree(self.path)

    def __del__(self):
        self.cleanup()