File: __init__.py

package info (click to toggle)
procserv 2.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,356 kB
  • sloc: sh: 4,154; cpp: 1,715; ansic: 1,417; python: 870; makefile: 65
file content (38 lines) | stat: -rwxr-xr-x 786 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

import os
from functools import reduce
from glob import glob

from shutil import rmtree
from tempfile import mkdtemp

from .. import conf

class TestDir(object):
    """Patch procServUtils.conf to use files from temp location
    """
    def __init__(self):
        self.dir = None

    def close(self):
        if self.dir is not None:
            rmtree(self.dir, ignore_errors=True)
            self.dir = None

            conf._testprefix = None

    def __enter__(self):
        self.dir = mkdtemp()
        try:
            os.makedirs(self.dir+'/run')
            os.makedirs(self.dir+'/procServ.d')

            conf._testprefix = self.dir

            return self
        except:
            self.close()
            raise

    def __exit__(self,A,B,C):
        self.close()