1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 17:24:46 +00:00

Merge branch 'master' of github.com:deadc0de6/dotdrop

This commit is contained in:
deadc0de6
2020-11-04 20:52:38 +01:00
2 changed files with 33 additions and 3 deletions

View File

@@ -251,3 +251,7 @@ export DOTDROP_DEBUG=
```bash
export DOTDROP_FORCE_NODEBUG=
```
* `DOTDROP_TMPDIR`: defines a temporary directory for dotdrop to use for its operations instead of using a system generated one
```bash
export DOTDROP_TMPDIR="/tmp/dotdrop-tmp"
```

View File

@@ -19,6 +19,10 @@ from dotdrop.logger import Logger
LOG = Logger()
STAR = '*'
# the environment variable for temporary
ENV_TEMP = 'DOTDROP_TMPDIR'
# the temporary directory
TMPDIR = None
# files dotdrop refuses to remove
DONOTDELETE = [
@@ -87,20 +91,42 @@ def diff(original, modified, raw=True,
def get_tmpdir():
"""create a temporary directory"""
"""create and return the temporary directory"""
global TMPDIR
if TMPDIR:
return TMPDIR
t = _get_tmpdir()
TMPDIR = t
return t
def _get_tmpdir():
"""create the tmpdir"""
try:
if ENV_TEMP in os.environ:
t = os.environ[ENV_TEMP]
t = os.path.expanduser(t)
t = os.path.abspath(t)
t = os.path.normpath(t)
os.makedirs(t, exist_ok=True)
return t
except Exception:
pass
return tempfile.mkdtemp(prefix='dotdrop-')
def get_tmpfile():
"""create a temporary file"""
(_, path) = tempfile.mkstemp(prefix='dotdrop-')
tmpdir = get_tmpdir()
(_, path) = tempfile.mkstemp(prefix='dotdrop-', dir=tmpdir)
return path
def get_unique_tmp_name():
"""get a unique file name (not created)"""
unique = str(uuid.uuid4())
return os.path.join(tempfile.gettempdir(), unique)
tmpdir = get_tmpdir()
return os.path.join(tmpdir, unique)
def remove(path, logger=None):