Esempio n. 1
0
 def UpdateFile(self, request, context):
     container_id = request.container_id
     path = request.path
     file_name = request.file_name
     old_version = request.old_version
     exit_code, old_file_stat = ContainerUtils.ExecCommand(\
         container_id=container_id,
         exec_cmd = ["stat", "-c", "%Y", path+"/"+file_name]
     )
     if exit_code == 0:
         if old_version == old_file_stat or request.force:
             # generate_data = GenerateData(request)
             if not ContainerUtils.PutArchive(container_id, path,
                                              request.data):
                 return Manager.UpdateFile_Response(
                     exit_code=Manager.UpdateFile_Response.ExitCode.
                     UNKNOWN_ERROR)
             else:
                 exit_code, new_version = ContainerUtils.ExecCommand(\
                     container_id=container_id,
                     exec_cmd = ["stat", "-c", "%Y", path]
                 )
                 return Manager.UpdateFile_Response(\
                         exit_code = Manager.UpdateFile_Response.ExitCode.SUCCESS,
                         new_version = new_version
                     )
         else:
             return Manager.UpdateFile_Response(\
                 exit_code=Manager.UpdateFile_Response.ExitCode.MTIME_SYNC_ERROR)
     elif exit_code == 1:
         return Manager.UpdateFile_Response(\
             exit_code=Manager.UpdateFile_Response.ExitCode.FILE_IS_NOT_EXIST)
Esempio n. 2
0
 def ListFile(self, request, context):
     cmd = ["ls", "-Al", request.path]
     exit_code, output = ContainerUtils.ExecCommand(request.container_id,
                                                    cmd)
     response = Manager.ListFile_Response()
     if exit_code == 0:
         response.exit_code = Manager.ListFile_Response.ExitCode.SUCCESS
         List = output.strip().split('\n')[1:]
         for file in List:
             temp = file.split(' ')
             stat = temp[0]
             filename = temp[-1]
             temp = response.files.add()
             temp.file_name = filename
             if stat[0] == '-':
                 temp.file_type = Manager.FileStat.FileType.FILE
             elif stat[0] == 'd':
                 temp.file_type = Manager.FileStat.FileType.FOLDER
             elif stat[0] == 'i':
                 temp.file_type = Manager.FileStat.FileType.LINK
     elif exit_code == 1:
         response.exit_code = Manager.ListFile_Response.ExitCode.MINOR_PROBLEMS
     elif exit_code == 2:
         response.exit_code = Manager.ListFile_Response.ExitCode.SERIOUS_TROUBLE
     return response