일단 정리..
This commit is contained in:
42
UtilPack.py
42
UtilPack.py
@@ -10,17 +10,14 @@ import subprocess
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
m_dbgLevel = 0
|
||||
listDbgStr = []
|
||||
|
||||
|
||||
#
|
||||
def IsEmptyStr(string):
|
||||
temp = f"{string}"
|
||||
return 0 == len(temp.strip())
|
||||
|
||||
|
||||
#
|
||||
def GetCurrentTime():
|
||||
# 현재 시간을 구하고 구조체로 변환
|
||||
@@ -38,7 +35,6 @@ def GetCurrentTime():
|
||||
|
||||
return strRet
|
||||
|
||||
|
||||
#for debug
|
||||
def DbgOut(strInput, bPrint = False):
|
||||
strMsg = (f"{GetCurrentTime()} : {strInput}")
|
||||
@@ -46,12 +42,21 @@ def DbgOut(strInput, bPrint = False):
|
||||
|
||||
if True == bPrint:
|
||||
print(strMsg)
|
||||
|
||||
|
||||
#
|
||||
def printDbgMessages():
|
||||
for line in listDbgStr:
|
||||
print(line)
|
||||
|
||||
|
||||
|
||||
#
|
||||
def SaveDbgMessages(Path):
|
||||
try:
|
||||
with open(Path, 'w') as file:
|
||||
for line in listDbgStr:
|
||||
file.write(line + "\n")
|
||||
except IOError:
|
||||
DbgOut(f"Error: Could not write to the file at {Path}.", True)
|
||||
|
||||
# 입력된 경로의 자식 폴더를 찾아 반환한다.
|
||||
# 반환하는 리스트는 리커시브 - 손자, 증손자 폴더까지 전부 포함한다
|
||||
def ListSubDirectories(root_dir):
|
||||
@@ -68,7 +73,6 @@ def ListSubDirectories(root_dir):
|
||||
|
||||
return subdirectories
|
||||
|
||||
|
||||
# 자식 폴더를 구해온다. 직계 자식만
|
||||
def ListChildDirectories(pathDir):
|
||||
listRet = []
|
||||
@@ -79,7 +83,6 @@ def ListChildDirectories(pathDir):
|
||||
|
||||
return listRet
|
||||
|
||||
|
||||
# 파일목록만 구해온다. 자식 폴더에 있는건 무시.
|
||||
def ListContainFiles(pathDir):
|
||||
listRet = []
|
||||
@@ -90,7 +93,7 @@ def ListContainFiles(pathDir):
|
||||
|
||||
return listRet
|
||||
|
||||
|
||||
#
|
||||
def ListFileExtRcr(pathTrg, listExt):
|
||||
listRet= []
|
||||
|
||||
@@ -107,8 +110,7 @@ def ListFileExtRcr(pathTrg, listExt):
|
||||
|
||||
return listRet
|
||||
|
||||
|
||||
# 입력된 패스에서 부모 폴더를 찾는다. 0 은 자기자신 1은 부모, 숫자대로 위로.
|
||||
# 입력된 경로에서 부모 폴더를 찾는다. 0 은 자기자신 1은 부모, 숫자대로 위로.
|
||||
def GetParentDirName(FullPath, nUp):
|
||||
parts = FullPath.split(os.sep)
|
||||
|
||||
@@ -122,7 +124,6 @@ def GetParentDirName(FullPath, nUp):
|
||||
|
||||
return parts[nTrgIdx]
|
||||
|
||||
|
||||
# 입력된 경로가 자식 폴더를 가지고 있는지 판단한다.- 최종 폴더인지 여부
|
||||
# 자식이 없으면 True, 자식이 있으면 False
|
||||
def IsFinalFolder(path):
|
||||
@@ -136,7 +137,6 @@ def IsFinalFolder(path):
|
||||
|
||||
return bRet;
|
||||
|
||||
|
||||
# 어떤 경로 안에서 특정 확장자의 파일을 뽑아내어 그 리스트를 반환한다.
|
||||
def FindFileFromExt(path, ext):
|
||||
bDot = False
|
||||
@@ -158,7 +158,6 @@ def FindFileFromExt(path, ext):
|
||||
|
||||
return listRet
|
||||
|
||||
|
||||
# 파일 이름에서 확장자를 뽑아낸다. True : '.' 을 포함한다.
|
||||
def GetExtStr(file_path, bDot = True):
|
||||
retStr = ""
|
||||
@@ -174,7 +173,6 @@ def GetExtStr(file_path, bDot = True):
|
||||
|
||||
return retStr
|
||||
|
||||
|
||||
# 문자열에 포함된 단어를 지운다.
|
||||
def RmvSubString(mainString, subString):
|
||||
# 문자열에서 부분 문자열의 인덱스를 찾습니다.
|
||||
@@ -187,12 +185,11 @@ def RmvSubString(mainString, subString):
|
||||
# 부분 문자열을 제거하고 새로운 문자열을 반환합니다.
|
||||
return mainString[:strIdx] + mainString[endIdx:]
|
||||
|
||||
|
||||
#
|
||||
def ExtractZIP(zip_file, extract_to):
|
||||
with zipfile.ZipFile(zip_file, 'r') as zf:
|
||||
zf.extractall(extract_to)
|
||||
|
||||
|
||||
#
|
||||
def CreateZIP(output_zip, *files):
|
||||
with zipfile.ZipFile(output_zip, 'w') as zf:
|
||||
@@ -236,7 +233,6 @@ def CreateZIPShell(zipName, *files, bRmvRPath = True):
|
||||
|
||||
return bRet
|
||||
|
||||
|
||||
# 특정 확장자만 쉘을 이용해서 압축한다
|
||||
def CreateZIPShExt(zipName, TrgExt):
|
||||
command = f"zip -j {zipName} *.{TrgExt}"
|
||||
@@ -249,7 +245,6 @@ def CreateZIPShExt(zipName, TrgExt):
|
||||
|
||||
return bRet
|
||||
|
||||
|
||||
# 압축 파일 내의 모든 파일 및 디렉토리 목록 가져오기
|
||||
def GetZipContentList(path):
|
||||
if None == path or not os.path.isfile(path):
|
||||
@@ -261,7 +256,7 @@ def GetZipContentList(path):
|
||||
|
||||
return listRet
|
||||
|
||||
|
||||
#
|
||||
def GetZippedFileByte(pathZip, FileName):
|
||||
if None == pathZip or not os.path.isfile(pathZip):
|
||||
return None
|
||||
@@ -275,7 +270,6 @@ def GetZippedFileByte(pathZip, FileName):
|
||||
retBytes = file.read()
|
||||
|
||||
return retBytes
|
||||
|
||||
|
||||
# JSON 을 트리 구조로 출력한다.
|
||||
def PrintJSONTree(data, indent=0):
|
||||
@@ -289,13 +283,12 @@ def PrintJSONTree(data, indent=0):
|
||||
else:
|
||||
print(' ' * indent + str(data))
|
||||
|
||||
|
||||
#
|
||||
def IsPathWithin(base_path: str, target_path: str) -> bool:
|
||||
base = Path(base_path).resolve()
|
||||
target = Path(target_path).resolve()
|
||||
return target.is_relative_to(base)
|
||||
|
||||
|
||||
# 랜덤 UUID 생성
|
||||
def UUIDGenRandom():
|
||||
random_uuid = uuid.uuid4()
|
||||
@@ -306,5 +299,6 @@ def UUIDGenName(SeedName):
|
||||
namespace_uuid = uuid.uuid5(uuid.NAMESPACE_DNS, SeedName)
|
||||
return namespace_uuid
|
||||
|
||||
#
|
||||
def GetTextInBrakets(text):
|
||||
return re.findall(r'\[(.*?)\]', text)
|
||||
Reference in New Issue
Block a user