Update DataClass.py, GetArc_Ehentai.py, and 7 more files...
데이터 클래스 정의, 퍼필 다운로더 json 파서...
This commit is contained in:
177
UtilPack.py
177
UtilPack.py
@@ -1,5 +1,11 @@
|
||||
import os
|
||||
import time
|
||||
import rarfile
|
||||
import zipfile
|
||||
import shutil
|
||||
import difflib
|
||||
import subprocess
|
||||
|
||||
|
||||
m_dbgLevel = 0
|
||||
listDbgStr = []
|
||||
@@ -26,14 +32,177 @@ def GetCurrentTime():
|
||||
return strRet
|
||||
|
||||
#for debug
|
||||
def DbgOut(str):
|
||||
strMsg = GetCurrentTime() +" : " + str
|
||||
|
||||
def DbgOut(strInput, bPrint = False):
|
||||
strMsg = (f"{GetCurrentTime()} : {strInput}")
|
||||
listDbgStr.append(strMsg)
|
||||
print(strMsg)
|
||||
|
||||
if True == bPrint:
|
||||
print(strMsg)
|
||||
|
||||
def printDbgMessages():
|
||||
for line in listDbgStr:
|
||||
print(line)
|
||||
|
||||
|
||||
# 입력된 경로의 자식 폴더를 찾아 반환한다.
|
||||
# 반환하는 리스트는 리커시브 - 손자, 증손자 폴더까지 전부 포함한다
|
||||
def ListSubDirectories(root_dir):
|
||||
subdirectories = []
|
||||
|
||||
# root_dir에서 하위 디렉토리 및 파일 목록을 얻음
|
||||
for dirpath, dirnames, filenames in os.walk(root_dir):
|
||||
# 하위 디렉토리 목록을 반복하며 하위 디렉토리만 추출
|
||||
for dirname in dirnames:
|
||||
path = os.path.join(dirpath, dirname)
|
||||
|
||||
if True == IsFinalFolder(path):
|
||||
subdirectories.append(path)
|
||||
|
||||
return subdirectories
|
||||
|
||||
|
||||
def ListFileExtRcr(pathTrg, strExt):
|
||||
listRet= []
|
||||
|
||||
# pathTrg의 하위 디렉토리 및 파일 목록을 얻음
|
||||
for dirpath, dirnames, filenames in os.walk(pathTrg):
|
||||
for file in filenames:
|
||||
extTmp = GetExtStr(file, False)
|
||||
if extTmp.lower() == strExt and file.startswith('.'):
|
||||
listRet.append(os.path.join(dirpath, file))
|
||||
|
||||
return listRet
|
||||
|
||||
# 입력된 경로가 자식 폴더를 가지고 있는지 판단한다.- 최종 폴더인지 여부
|
||||
# 자식이 없으면 True, 자식이 있으면 False
|
||||
def IsFinalFolder(path):
|
||||
bRet = True
|
||||
|
||||
contents = os.listdir(path)
|
||||
for item in contents:
|
||||
if True == os.path.isdir(item):
|
||||
bRt = False
|
||||
break
|
||||
|
||||
return bRet;
|
||||
|
||||
# 어떤 경로 안에서 특정 확장자의 파일을 뽑아내어 그 리스트를 반환한다.
|
||||
def FindFileFromExt(path, ext):
|
||||
bDot = False
|
||||
if 0 <= ext.find('.'):
|
||||
bDot = True
|
||||
|
||||
listRet = []
|
||||
if False == os.path.exists(path):
|
||||
return listRet
|
||||
|
||||
contents = os.listdir(path)
|
||||
for item in contents:
|
||||
if True == os.path.isdir(item):
|
||||
continue
|
||||
|
||||
extItem = GetExtStr(item, bDot)
|
||||
if extItem.lower() == ext.lower():
|
||||
listRet.append(item)
|
||||
|
||||
return listRet
|
||||
|
||||
# 파일 이름에서 확장자를 뽑아낸다. True : '.' 을 포함한다.
|
||||
def GetExtStr(file_path, bDot = True):
|
||||
retStr = ""
|
||||
# 파일 경로에서 마지막 점을 찾아 확장자를 추출
|
||||
last_dot_index = file_path.rfind('.')
|
||||
if last_dot_index == -1:
|
||||
retStr = "" # 점이 없는 경우 확장자가 없음
|
||||
else:
|
||||
if True == bDot:
|
||||
retStr = file_path[last_dot_index:]
|
||||
else:
|
||||
retStr = file_path[last_dot_index+1:]
|
||||
|
||||
return retStr
|
||||
|
||||
# 문자열에 포함된 단어를 지운다.
|
||||
def RmvSubString(mainString, subString):
|
||||
# 문자열에서 부분 문자열의 인덱스를 찾습니다.
|
||||
strIdx = mainString.find(subString)
|
||||
if strIdx == -1: # 부분 문자열이 존재하지 않으면 그대로 반환합니다.
|
||||
return mainString
|
||||
|
||||
endIdx = strIdx + len(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:
|
||||
for file in files:
|
||||
zf.write(file, os.path.basename(file))
|
||||
|
||||
bRet = False
|
||||
if os.path.exists(output_zip):
|
||||
bRet = True
|
||||
|
||||
return bRet
|
||||
|
||||
# 파일 리스트에 들어있는 파일만 골라서 압축을 합니다. 상대경로를 제거하는게 기본값.
|
||||
def CreateZIPShell(zipName, *files, bRmvRPath = True):
|
||||
command = "zip "
|
||||
|
||||
if True == bRmvRPath:
|
||||
command += "-j "
|
||||
|
||||
command += f"\"{zipName}\" "
|
||||
|
||||
# 이중 리스트인 이유를 모르겠다.
|
||||
for file in files:
|
||||
strTemp = ""
|
||||
if isinstance(file, list):
|
||||
strTemp = ' '.join(file)
|
||||
else:
|
||||
strTemp = f"\"{file}\" "
|
||||
|
||||
command += strTemp
|
||||
|
||||
|
||||
# for item in file:
|
||||
# command += f"\"{item}\" "
|
||||
|
||||
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
||||
|
||||
bRet = False
|
||||
if 0 == result.returncode:
|
||||
bRet = True
|
||||
|
||||
return bRet
|
||||
|
||||
# 특정 확장자만 쉘을 이용해서 압축한다
|
||||
def CreateZIPShExt(zipName, TrgExt):
|
||||
command = f"zip -j {zipName} *.{TrgExt}"
|
||||
|
||||
result = subprocess.run(command, shell=True, capture_output=True, text=True)
|
||||
|
||||
bRet = False
|
||||
if 0 == result.returncode:
|
||||
bRet = True
|
||||
|
||||
return bRet
|
||||
|
||||
# JSON 을 트리 구조로 출력한다.
|
||||
def PrintJSONTree(data, indent=0):
|
||||
if isinstance(data, dict):
|
||||
for key, value in data.items():
|
||||
print(' ' * indent + str(key))
|
||||
PrintJSONTree(value, indent + 1)
|
||||
elif isinstance(data, list):
|
||||
for item in data:
|
||||
PrintJSONTree(item, indent)
|
||||
else:
|
||||
print(' ' * indent + str(data))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user