1. Unzip with Ionic.Zip and zipfile
# -*- coding: utf-8 -*- import clr #clr.AddReferenceToFileAndPath("DotNetZip") clr.AddReferenceToFileAndPath("Ionic.Zip") import Ionic.Zip #import Ionic.Zip.ZipFile from Ionic.Zip import * import zipfile class UnZip(): def __init__(self,filename): self.zf = Ionic.Zip.ZipFile.Read(filename) def print_list(self): for z in self.zf: print(z.FileName.encode('cp437').decode('cp949')) def extract_all(self,folder): self.zf.ExtractAll(folder,ExtractExistingFileAction.OverwriteSilently) def extract(self,folder,filename): self.zf.ExtractSelectedEntries(filename.encode('cp949').decode('cp437'),"",folder,ExtractExistingFileAction.OverwriteSilently) #entry file, entry folder, out folder, flag def extract2(self,folder,filename): for z in self.zf: if z.FileName == filename: z.Extract(folder,ExtractExistingFileAction.OverwriteSilently) class PyUnZip(): def __init__(self,filename): self.zf = zipfile.ZipFile(filename) def print_list(self): for z in self.zf.infolist(): print(z.filename.decode('cp949')) def namelist(self): return self.zf.namelist() def list(self): #zp_info.filename) #zp_info.file_size) #zp_info.date_time) #zp_info.compress_size) #zp_info.comment) f = [] for z in self.zf.infolist(): f.append(z.filename.decode('cp949')) return f def read(self,filename): with self.zf.open(filename.encode("cp949")) as f: return f.read() if __name__ == "__main__": uz = UnZip("D:/image.zip") uz.print_list() uz.extract_all("D:/Temp") #uz.extract("D:/Temp","데스크 탑.png") #uz.extract2("D:/Temp","Lenna.png") pz = PyUnZip("D:/image.zip") pz.print_list() with open("D:/bbbb.png","wb") as w: w.write(pz.read("데스크 탑.png"))
import clr clr.AddReference('StdLib') import os import zipfile import ezPyWpfLib as ez def refreshTree(basedir="webtoon"): tree = ez.GetControl('tree') dirs = os.listdir(basedir) for d in dirs: dpath = os.path.join(basedir,d) if os.path.isdir(dpath): item = tree.AddRootItem(d) files = os.listdir(dpath) for f in files: fpath = os.path.join(dpath,f) if os.path.isfile(fpath): tree.AddItem(f,item) elif zipfile.is_zipfile(dpath): item = tree.AddRootItem(d) with zipfile.ZipFile(dpath) as zf: for info in zf.infolist(): if not info.filename.endswith('/'): #tree.AddItem(f,item) tree.AddItem(info.filename.decode("cp949"),item) def onTreeView(event): tree = ez.GetControl('tree') if tree.IsRootItem(tree.GetSelectedItem()): return path = tree.GetItemPath(tree.GetParentItem(tree.GetSelectedItem())) if path and zipfile.is_zipfile(path): with zipfile.ZipFile(path) as zf: with zf.open(tree.GetSelectedItemText().encode("cp949")) as f: web = ez.GetControl('web') web.Load(f.read()) else: path = tree.GetSelectedItemPath() if os.path.isfile(path) and path.endswith("html"): with open(path) as f: web = ez.GetControl('web') web.Load(f.read()) def onCreated(): ez.DumpControlTable() refreshTree() def onClosing(event): if not ez.YesNoDialog("Do you want to quie ?","Quit"): event.args.Cancel = True split1 = [[ { "name" : "TreeView", "label" : "WebToon", "key" : "tree", 'handler' : onTreeView, 'fontsize':14, "expand" : True }, { "expand" : True }, ]] split2 = [[ { "name" : "WebView", "key" : "web", "expand" : True, "toolbar" : False, "uri" : "http://google.co.kr" }, { "expand" : True }, ]] app_content = [ # vbox [ # hbox { "name" : "HSplit", "items" : [ split1, split2 ] , "first" : 0.4, "expand" : True, 'border' : False}, { "expand" : True, 'border' : True }, ], ] def MakeWindow(): win = ez.Window() win.SetTitle("WebToon Viewer") win.SetSize(640,400) win.SetContent(app_content) win.SetCreatedHandler(onCreated) win.SetCloseHandler(onClosing) return win if __name__ == "__main__": global appWin appWin = MakeWindow() appWin.Run()
댓글 없음:
댓글 쓰기