예제 #1
0
class LepDRequestor(threading.Thread):
    def __init__(self, lepdCommand, server='www.linuxep.com', port=12307):
        threading.Thread.__init__(self)

        self.timeUsed = 0

        self.command = lepdCommand
        self.lepDClient = LepDClient(server, port)

        self.response = ''

    def run(self):
        timeStarts = datetime.utcnow().replace(tzinfo=utc)

        self.response = self.lepDClient.sendRequest(self.command)

        timeEnds = datetime.utcnow().replace(tzinfo=utc)
        duration = timeEnds - timeStarts
        self.timeUsed = int(duration.total_seconds())

    def report(self):
        print("")
        print("Command: " + self.command)
        print("Duration: " + str(self.timeUsed) + " seconds")
        print("Result:")
        print(self.response)

    def runAndReport(self):
        self.run()
        self.report()
예제 #2
0
class LepDRequestor(threading.Thread):

    def __init__(self, lepdCommand, server, port=12307):
        threading.Thread.__init__(self, name=lepdCommand)
        
        self.timeUsed = 0
        self.succeeded = False
        
        self.command = lepdCommand
        self.lepDClient = LepDClient(server, port)
        
        self.response = ''


    def run(self):
        timeStarts = datetime.utcnow().replace()
        
        self.response = self.lepDClient.sendRequest(self.command)
        if ("{'result': 'Hello!'}" != self.response):
            self.succeeded = True
    
        timeEnds = datetime.utcnow().replace()
        duration = timeEnds - timeStarts
        
        durationInSeconds = duration.seconds + duration.microseconds / 1000000
        self.timeUsed = "{:.3f}".format(durationInSeconds)

    
    def report(self):
        
        reportMessage = self.command
        # assume the longest command name is of 30 chars
        maxLength = 30
        reportMessage += ' ' * (maxLength - len(self.command)) + ' '
        
        if (self.succeeded):
            reportMessage += "succeeded in "
        else:
            reportMessage += "failed in "
        
        reportMessage += str(self.timeUsed) + " seconds"
        
        print(reportMessage)
        # print("Command: " + self.command)
        # if (self.succeeded):
        #     print("Status: Succeeded")
        # else:
        #     print("Status: Failed!!!")
        #     print(self.response)
        #     
        # print("Duration: " + str(self.timeUsed) + " seconds")
        
    
    def runAndReport(self):
        self.run()
        self.report()
예제 #3
0
def runCommand(request, server, command):
    if (request.method != 'GET'):
        return

    try:
        if (server == ''):
            print("LEPD serer is not specified!")
            return

        print("LEPD address: " + server)
        client = LepDClient(server=server, config='debug')

        return JSONResponse(client.sendRequest(command))
    except Exception as ex:
        # print(ex)
        return HttpResponse(status=404)