[go: up one dir, main page]

File: util.py

package info (click to toggle)
txtorcon 18.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,672 kB
  • sloc: python: 17,521; makefile: 227
file content (23 lines) | stat: -rw-r--r-- 435 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

import tempfile
import shutil


class TempDir(object):
    '''
    This is a simple context manager that handles creating and
    cleaning up a tempdir.

    See also: https://gist.github.com/meejah/6430613

    '''

    def __enter__(self, *args):
        self.dir_name = tempfile.mkdtemp()
        return self

    def __exit__(self, *args):
        shutil.rmtree(self.dir_name)

    def __str__(self):
        return self.dir_name