one-file-projects/chunksizer.py

76 lines
2.5 KiB
Python
Raw Normal View History

2014-11-04 13:06:32 +01:00
# -*- coding: cp1252 -*-
import Tkinter, tkFileDialog, tkMessageBox, os
def getsize(directory):
total_size = 0
for dirpath, dirnames, filenames in os.walk(directory):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size
def calcChunkCount(chunksizeKB, total_size):
chunksizeB = chunksizeKB * 1024
chunkcount = total_size / chunksizeB
return chunkcount
def chunklabel(size, dirsize, parent):
chunklabel = Tkinter.Label(parent, text=str(size)+"KB: " + str(calcChunkCount(size, dirsize)))
return chunklabel
def choosedir():
path = tkFileDialog.askdirectory()
dirsize = getsize(path)
mainFrame = Tkinter.LabelFrame(window, text=path)
mainFrame.pack()
resultsFrame = Tkinter.Frame(mainFrame)
resultsFrame.pack()
2015-11-01 14:36:52 +01:00
2014-11-04 13:06:32 +01:00
infoFrame = Tkinter.LabelFrame(resultsFrame, text="Infos")
labPath = Tkinter.Label(infoFrame, text="Verzeichnis: " + path )
labSize = Tkinter.Label(infoFrame, text="Groesse: " + str(dirsize/1024) + "KB" )
labPath.pack()
labSize.pack()
infoFrame.pack(side="left")
chunksizeFrame = Tkinter.LabelFrame(resultsFrame, text="Chunk-Counts")
chunk64K = chunklabel(64, dirsize, chunksizeFrame)
chunk64K.pack()
chunk128K = chunklabel(128, dirsize, chunksizeFrame)
chunk128K.pack()
chunk256K = chunklabel(256, dirsize, chunksizeFrame)
chunk256K.pack()
chunk512K = chunklabel(512, dirsize, chunksizeFrame)
chunk512K.pack()
chunk1024K = chunklabel(1024, dirsize, chunksizeFrame)
chunk1024K.pack()
chunk2048K = chunklabel(2048, dirsize, chunksizeFrame)
chunk2048K.pack()
chunk4096K = chunklabel(4096, dirsize, chunksizeFrame)
chunk4096K.pack()
chunk8192K = chunklabel(8192, dirsize, chunksizeFrame)
chunk8192K.pack()
chunksizeFrame.pack(side="right")
buttonFrame2 = Tkinter.Frame(mainFrame)
closeBtn = Tkinter.Button(buttonFrame2, text="schliessen", command=mainFrame.destroy)
closeBtn.pack()
buttonFrame2.pack()
2015-11-01 14:36:52 +01:00
2014-11-04 13:06:32 +01:00
window = Tkinter.Tk()
window.title("Torrent Chunksize Calculator by BSOD")
window.minsize(width=400, height=200)
l = Tkinter.Label(window, text="dieses Tool soll euch beim Torrents erstellen helfen :)")
l.pack()
buttonFrame = Tkinter.Frame()
choosedirBtn = Tkinter.Button(buttonFrame, text="neues Verzeichnis für Berechnung wählen", command=choosedir)
choosedirBtn.pack(side="left")
quitBtn = Tkinter.Button(buttonFrame, text="Beenden", command=window.destroy)
quitBtn.pack(side="right")
buttonFrame.pack()
window.mainloop()