File size: 1,915 Bytes
3b83fd0 |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
from os import listdir, makedirs
from os.path import isdir, isfile, join
from re import search, IGNORECASE
from shutil import copy
def getFilesWith(path: str, reg: str):
if not isdir(path):
print(path, "is not a valid path")
return None
content = listdir(path)
if len(content) == 0:
print(path, "has no content")
return None
files = [f for f in content if isfile(join(path, f)) and search(reg, f, IGNORECASE)]
if len(files) == 0:
print(path, "contains no", reg)
return None
return files
def createNewFolders(dirs: list):
for d in dirs:
if not isdir(d):
makedirs(d)
else:
print("directory already exists", d)
def createNewTemplates(objs, templatesDir, regTemplate, root):
templatefiles = getFilesWith(templatesDir, regTemplate)
for k in objs:
regPhase = r""
match k:
case "(i)SAT":
regPhase = r"sat"
case "iFAT":
regPhase = r"fat"
files = [f for f in templatefiles if search(regPhase, f, IGNORECASE)]
if len(files) == 0:
print("phase %s has no templates" % k)
continue
for o in objs[k]:
targetLocation = join(root, o)
tlFiles = getFilesWith(targetLocation, regPhase)
if tlFiles:
print(k, "files already exist in:", targetLocation)
print("--------------------")
[print("|-",f) for f in tlFiles]
print("--------------------")
continue
for f in files:
templatepath = join(templatesDir, f)
targetpath = targetLocation
if search(r"hut_\d{4}[a-zA-Z]{2}", f, IGNORECASE):
targetpath = join(targetLocation, f[:4] + o + f[10:])
copy(templatepath, targetpath)
|