def upload_file(name, folder_id, f): root = MEDIA_ROOT folder = Folder.objects.get(id=folder_id) # create a file with open(folder.path + "/" + name, 'w') as destination: for chunk in f.chunks(): destination.write(chunk) file = File() file.name = name file.folder = folder file.active = True file.save() return file.id
def create_file(name, folder_id): root = MEDIA_ROOT folder = Folder.objects.get(id=folder_id) # Open a file f = open(folder.path + "/" + name, "w") # Close opend file f.close() file = File() file.name = name file.folder = folder file.active = True file.save() return file.id
def compile_java(file_id): #first traslate traslate_java(file_id) file = File.objects.get(id=file_id) folder = file.folder user = folder.user galatea_code = GALATEA + "galatea.jar " code = "javac -cp "+ galatea_code + folder.path + "/*.java" #print code value = subprocess.check_output([code], shell=True) #print value #get all the file in this folder for root, dirs, files in os.walk(folder.path): root_folder = Folder.objects.get(path=root, name = os.path.basename(root)) for dir in dirs: folders = Folder.objects.filter(father=root_folder.id) esta = False for folder in folders: if folder.name == dir: esta = True if not esta: folder = Folder() folder.name = dir folder.path = root_folder.path + "/" + dir folder.user = user folder.father = root_folder.id folder.active = True folder.save() #print dirs for file in files: files_folder = File.objects.filter(folder = root_folder.id) esta = False for f in files_folder: if f.name == file: esta = True if not esta: if (os.path.splitext(file)[1] != ".class"): f = File() f.name = file f.folder = root_folder f.active = True f.save() return value