Example #1
0
 def _run_script(self,data_detail={}):
     """function:run script"""
     (script_name,store_path)=self.convert_str_2_file(data_detail)
     
     result=exec_cmd("chmod +x "+store_path+script_name)
     log("\n".join(result))
     result = exec_cmd(store_path+script_name)
     str_result = "\n".join(result)
     log(str_result)
     return str_result
 def inner_process_ret(self,data):
     """"""
     (result,header_info,body_info)=self.check_params(data)
     if isinstance(body_info["data"]["detail"],list):
         detail = body_info["data"]["detail"][0]
     elif isinstance(body_info["data"]["detail"],dict):
         detail = body_info["data"]["detail"]
     else:
         log("request content:param[detail] type need be list or dict")
         return "request content format error"
     (script_name,store_path)=self.convert_str_2_file(detail)
     
     result=exec_cmd("chmod +x "+store_path+script_name)
     log("\n".join(result))
     result = exec_cmd(store_path+script_name)
     str_result = "\n".join(result)
     log(str_result)
     return str_result
Example #3
0
 def calc_md5_info(self,file_info=[]):
     #calculate
     md5_info=[]
     for index,item in enumerate(file_info):
         for file_item in item["fileList"]:
             result_info= exec_cmd('md5sum '+item["dirPath"]+'/'+file_item)
             if result_info:
                 info = result_info[0].split()
                 md5_info.append({"storePath":item["dirPath"],"fileName":file_item,"md5Info":info[0]})
     
     return md5_info
Example #4
0
 def __rename_file(self,str_cmd=""):
     """"""
     try:
         if str_cmd:
             ret_info =exec_cmd(str_cmd)
             if ret_info:
                 str_info = "\n".join(ret_info)
             else:
                 str_info="command already execute,but not return info."
         else:
             str_info="command content is null,please check"
     except Exception,e:
         log(str(e))
 def _make_task_dir(self,dir):
     """function:"""
     if os.path.exists(dir):
         log("[ProcessAgentTask] /var/agent/task dir exist.continue...")
         
     else:
         shell_cmd = "mkdir -p %s"%dir
         ret_info = exec_cmd(shell_cmd)
         if ret_info:
             str_info = "\n".join(ret_info)
             log(str_info)
         if os.path.exists(dir):
             pass
         else:
             #error occur
             log("[ProcessAgentTask]mkdir /var/agent/task/ error")
             return False
     return True
 def get_disk_usage(self):
     """"""
     ret_list=[]
     disk_usage_list = exec_cmd("/bin/df -PTh")
     for index,item in enumerate(disk_usage_list):
         if item.startswith("Filesystem"):
             #filter start header
             continue
         try:
             (device,fstype,total,used,available,percentage,mount)=item.split(None)
             ret_list.append({
                          "device":device,
                          "fstyp":fstype,
                          "total":total,
                          "used":used,
                          "available":available,
                          "percentage":percentage,
                          "mount":mount
                          })
         except Exception,e:
             log(str(e))