|
import hashlib
|
|
import os
|
|
import socket
|
|
|
|
def getMD5Hash(file, block_size=2**20):
|
|
f = open(file)
|
|
md5 = hashlib.md5()
|
|
while True:
|
|
data = f.read(block_size)
|
|
if not data:
|
|
break
|
|
md5.update(data)
|
|
md5Hash = md5.hexdigest()
|
|
return md5Hash
|
|
|
|
|
|
def getFileName(file):
|
|
basename = os.path.basename(file)
|
|
filename = os.path.splitext(basename)
|
|
return filename[0]
|
|
|
|
|
|
def getMimeType(path):
|
|
if path.endswith(".iso"):
|
|
return "application/x-iso9660-image"
|
|
elif path.endswith(".md5"):
|
|
return "text/plain"
|
|
|
|
def getClassroomName():
|
|
name = socket.gethostname()
|
|
classname="noclassroomname"
|
|
hostname=name.strip().split('.')[0].replace('_','-')
|
|
items=hostname.split('-')
|
|
|
|
if len(items)==2:
|
|
if len(items[1])==3 and (items[1].upper()=='PRO' or items[1][:1].upper()=='O'):
|
|
classname= items[0]
|
|
|
|
return classname
|