2b7d194b4b
Added translations to files * sahara/service/direct_engine.py * sahara/service/edp/job_manager.py * sahara/service/volumes.py * sahara/utils/crypto.py * sahara/utils/general.py * sahara/utils/openstack/base.py * sahara/utils/openstack/neutron.py * sahara/utils/remote.py * sahara/utils/tempfiles.py * tox.ini Change-Id: Idc4a1c7c4d6bfb2f25f33595dea7160dff4769cb
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
# Copyright (c) 2013 Mirantis Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
# implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import contextlib
|
|
import shutil
|
|
import tempfile
|
|
|
|
from sahara import exceptions as ex
|
|
from sahara.i18n import _
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def tempdir(**kwargs):
|
|
argdict = kwargs.copy()
|
|
if 'dir' not in argdict:
|
|
argdict['dir'] = '/tmp/'
|
|
tmpdir = tempfile.mkdtemp(**argdict)
|
|
try:
|
|
yield tmpdir
|
|
finally:
|
|
try:
|
|
shutil.rmtree(tmpdir)
|
|
except OSError as e:
|
|
raise ex.SystemError(
|
|
_("Failed to delete temp dir %(dir)s (reason: %(reason)s)") %
|
|
{'dir': tmpdir, 'reason': e})
|