def store_cached_file(cached_file_keys, project_id, parent, user): result = list() keys = cached_file_keys for key in keys: if key != "": temp_file = TempFileMongoFile.objects.get(key) if temp_file != None: mongo_id = ProjectDocumentMongoFile.objects.copy_bucket( temp_file) valid_data = dict() if str(parent) == "": valid_data['Parent'] = None else: valid_data['Parent'] = parent valid_data['ProjectID'] = project_id valid_data['Type'] = 3 valid_data['FileName'] = temp_file.metadata[ 'file_real_name'] print(1) file_id = FileInfoService.add_file( 0, mongo_id, temp_file.metadata['file_real_name'], 1, 0, temp_file.length) print(file_id) document = DocumentService.create_document( valid_data, user, False) document.FileID = file_id document.save() TempFileMongoFile.objects.delete_file(key) result.append(document.id) return result
def attachments_upload_handler(file): message = "" mongo_file_id = UploadFileService.save_to_mongo(file) file_id = FileInfoService.add_file(0, mongo_file_id, file.name, 1, 0, file.size) if file_id != 0: message = str(file_id) return message
def attachments_upload_handler(file): message = [] mongo_file_id = ForTestingService.save_to_mongo(file) file_id = FileInfoService.add_file(0, mongo_file_id, file.name, 1, 0, file.size) if file_id != 0: message.append(file_id) message.append(str(mongo_file_id)) return message
def attachments_upload_handler(file): message = [] mongo_message = IssueService.save_to_mongo(file, IssueMongoFile) if mongo_message[0] != "0": file_id = FileInfoService.add_file(0, mongo_message[0], file.name, 1, 0, file.size) message.append(file_id) message.append(mongo_message[0]) else: message[0] = "0" message[1] = "长传文件失败," + mongo_message[1] return message
def upload_package(request): result=0 tq_id=request.POST.get('tq_id','') file_type=request.POST.get('file_type','') upload_file=request.FILES['upload_file'] max_file_size=SystemConfigService.get_upload_file_maxsize() file_wihte_list=SystemConfigService.get_file_type_white_list() if CITaskService.validate_upload_file(upload_file,max_file_size,file_wihte_list): mongo_fileid=MongoDBService.save_file(upload_file,PackgeMongoFile) result=FileInfoService.add_file(0,mongo_fileid, upload_file.name,1,0,upload_file.size) CITaskService.update_ci_taskhistory(tq_id,result,file_type) return result
def save_build_log(tq_id): file_name = "ci_build_log" + tq_id + ".log" build_log = RedisService.get_value("ci_build_log" + tq_id) result = MongoDBService.save_content_asfile(file_name, build_log, BuildLogMongoFile) file_id = FileInfoService.add_file(0, result, file_name, 1, 0, len(build_log)) task_history = CITaskHistory.objects.get_by_tqid(int(tq_id)) if file_id: task_history.BuildLogID = file_id else: task_history.BuildLogID = 0 task_history.save()
def create_document(validate_data,user): document = ProjectDocument() document.Owner = user.id document.Parent = validate_data.get("Parent",None) document.ProjectID = validate_data.get("ProjectID",0) document.ReadOnly = False document.Type = validate_data.get("Type",0) document_name = validate_data.get("FileName",'新建文件') file_id = FileInfoService.add_file(document.Parent,'',document_name,document.Type,user.id,0) document.FileID = file_id document.save() DocumentService.log_create_activity(user,document,document_name) return document
def upload_package(request): result = None upload_file = request.FILES['upload_file'] max_file_size = SystemConfigService.get_upload_file_maxsize() file_wihte_list = SystemConfigService.get_file_type_white_list() if CITaskHistoryService.validate_upload_file(upload_file, max_file_size, file_wihte_list): mongo_fileid = MongoDBService.save_file(upload_file, PackgeMongoFile) file_id = FileInfoService.add_file(0, mongo_fileid, upload_file.name, 1, 0, upload_file.size) temp_output = CITaskStepOutput() temp_output = CITaskHistoryService.init_step_output(temp_output,request.data) temp_output.ProductID = file_id temp_output.save() result = temp_output return result
def store_cached_file(cached_file_keys): result = list() keys = cached_file_keys for key in keys: if key != "": temp_file = TempFileMongoFile.objects.get(key) if temp_file is not None: mongo_id = UCenterMongoFile.objects.copy_bucket(temp_file) file_id = FileInfoService.add_file( 0, mongo_id, temp_file.metadata['file_real_name'], 1, 0, temp_file.length) TempFileMongoFile.objects.delete_file(key) if file_id != 0: result.append(file_id) return result
def store_cached_file(cached_file_keys): result = "" keys = cached_file_keys for key in keys: if key != "": temp_file = TempFileMongoFile.objects.get(key) print(temp_file.metadata) print(temp_file.content_type) print(temp_file.length) if temp_file != None: mongo_id = IssueMongoFile.objects.copy_bucket(temp_file) file_id = FileInfoService.add_file(0, mongo_id, temp_file.metadata['file_real_name'], 1, 0, temp_file.length) if file_id != 0: result = result + str(file_id) + "," return result
def store_cached_file(cached_file_keys): result = "" keys = cached_file_keys.split(',') for key in keys: if key != "": temp_file = RedisService.get_object(key) if temp_file != None: RedisService.delete_value(key) mongo_id = MongoDBService.save_file( temp_file, IssueMongoFile) file_id = FileInfoService.add_file(0, mongo_id, temp_file.name, 1, 0, temp_file.size) if file_id != 0: result = result + str(file_id) + "," return result
def save_build_log(tq_id,tq_done=False): file_name="ci_build_log"+tq_id+".log" build_log=RedisService.get_value("ci_build_log"+tq_id) result=MongoDBService.save_content_asfile(file_name, build_log,BuildLogMongoFile) file_id=FileInfoService.add_file(0,result,file_name,1,0,len(build_log)) RedisService.delete_value("ci_build_log" + tq_id) if tq_done: temp_output = CITaskStepOutput() temp_output.ProductType = 1 temp_output.ProductID = file_id task_queue = TaskQueue.objects.get(int(tq_id)) task_history = CITaskHistory.objects.get_history_by_uuid(task_queue.TaskUUID) temp_output.TaskHistoryID = task_history.id temp_output.TaskID = task_history.CITaskID temp_output.StepID = "" temp_output.StageHistoryID = 0 temp_output.save() else: RedisService.set_value("ci_build_log"+tq_id,"") return file_id