示例#1
0
 def __init__(self, filePath, fileHash, folder):
     self.fileHash = fileHash
     self.folder = folder
     self.filePath = filePath
     self.dataBase = lu.getAddrOf("delta") + ":" + str(
         lu.getPort("delta")) + "/"
     self.executeSetup = threading.Thread(target=self._executeSetup).start()
示例#2
0
    def do_POST(self):
        lu.log("Post Request - " + self.path)
        pathroot=self.path.split("/")
        while "" in pathroot:
            pathroot.remove("")
        if(pathroot[0] == lu.paths["alpha_scripts"]): # TEST THIS : This may be broken : file upload
            lu.log("Uploading Script - " + self.path)
            fp=self.rfile
            filePath=re.sub("^/",os.getcwd()+"/",self.path)
            filePath=re.sub("%20"," ",filePath)
            length = int(self.headers.get_all('content-length')[0])
            self.setHeaders(200)
            if(length > 0):
                f = open(filePath, 'wb')
                f.write(fp.read(length))
                f.close()
        elif(self.path == lu.paths["alpha_postScript"]): # post to master
            masterAddr = lu.getAddrOf("Lambda-M")
            if not masterAddr:
                lu.log("Could not get Master Addr.")
                self.setHeaders(500)
            length = int(self.headers.get_all('content-length')[0])
            if(length > 0):
                # send json to master http post
                data = json.loads(self.rfile.read(length).decode("UTF-8"))
                data["FileLoc"]=lu.paths["alpha_scripts"] + "/" + data["script"]
                data["Hash"] = lu.getHash(data["FileLoc"])
                lu.log("Hashed Program : " + data["Hash"])
                lu.postHTTP(json.dumps(data),masterAddr,lu.getPort("Master_JSONpost"),lu.paths["master_postScript"])

                # send binary data to socket
                lu.sendFile(data["FileLoc"],(masterAddr,int(lu.getPort("Master_programRec"))))
                # self.send(data["Hash"])
                self.setHeaders(200)
                self.wfile.write(data["Hash"].encode("UTF-8"))
            else:
                lu.log("Nothing to send to master")
                self.setHeaders(500)
        else:
            lu.log("Could not post " + self.path)
 def __init__(self, filePath,fileHash, folder):
     self.fileHash=fileHash
     self.folder=folder
     self.filePath=filePath
     self.dataBase=lu.getAddrOf("delta") + ":" + str(lu.getPort("delta")) + "/"
     self.executeSetup = threading.Thread(target=self._executeSetup).start()