Skip to content

Commit

Permalink
Merge branch 'pr_22' into dt_master
Browse files Browse the repository at this point in the history
  • Loading branch information
dougransom committed Aug 21, 2024
2 parents 22363e7 + 3191af4 commit eb53571
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
51 changes: 50 additions & 1 deletion src/dtactions/unimacro/utilsqh.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""utility functions from Quintijn, used in unimacro and in local programs.
in python3 also the path module as subclass of the standard path class
"""
#pylint:disable=C0116, C0302, W0613, R0912, R0914, R0915, R0911, W0702
#pylint:disable=C0116, C0302, W0613, R0912, R0914, R0915, R0911, W0702, C0209, W0719
import unicodedata
import os
import re
import collections
import shutil
from pathlib import Path

def unifyaccentedchars(to_translate):
Expand Down Expand Up @@ -828,6 +829,54 @@ def makeReadable(t):
return t[:50] + ' ... ' + t[-50:]
return t


def makeEmptyFolder(*args):
"""delete a folder and creates it again
arguments can be a string (giving the path of the folder),
a list or a tuple of these, or several of previous things
# if all goes well, action is performed. If something goes wrong
# an OSError is raised
#
# >>> folderName = testdrive + '/qhtemp'
# >>> try: shutil.rmtree(folderName)
# ... except OSError: pass
# >>> makeEmptyFolder(folderName)
# >>> os.listdir(folderName)
# []
# >>> makeEmptyFolder(folderName)
# >>> os.listdir(folderName)
# []
# >>> makeEmptyFolder(folderName, folderName)
# >>> os.listdir(folderName)
# []
# >>> makeEmptyFolder([folderName])
# >>> os.listdir(folderName)
# []
"""
for a in args:
if not a:
continue
if isinstance(a, str):
a = a.replace('\\', '/') # make outside path instances!
if isinstance(a, str):
if os.path.isdir(a):
if os.path.isdir(a):
shutil.rmtree(a)
if os.path.exists(a):
raise OSError('path already exists, but is not a folder, or could not be deleted: %s'% a)
os.mkdir(a)

elif isinstance(a, list):
makeEmptyFolder(*tuple(a))
elif isinstance(a, tuple):
makeEmptyFolder(*a)
else:
raise Exception('invalid type for makeEmptyFolder: %s'% repr(a))


## functions for generating alternative paths in virtual drives
## uses reAltenativePaths, defined in the top of this module
## put in utilsqh.py! used in sitegen AND in _folders.py grammar of Unimacro:
Expand Down
1 change: 0 additions & 1 deletion tests/test_extenvvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def test_otherEnvVariables():
assert len(result) > 0
assert isdir(result)


def test_windows_Library_dirs():
"""most of them with platformdirs.windows, some special treatment.
Expand Down

0 comments on commit eb53571

Please sign in to comment.