Exemplo n.º 1
0
class ServerTest():
    '''
    Send image to the local server and check the response
    '''
    def __init__(self):
        self.fileNo = 0     #Keep track of total number of files checked
        self.failed = 0     #Keep track of how many files failed and add the path to a list
        self.failedList = []
        self.obj = ItemCheck()


    def sendFile(self, fileAddress):
        '''
        Get response from server for the input file and check it against given standard
        '''
        resp = requests.post('https://192.168.1.15/image/upload',
                             verify=False,
                             data={'username':'******'},
                             files={ 'uploadedfile':open(fileAddress,'rb') } )
        try:
            responseData = eval(resp.text.replace('null', 'None'))
        
            if responseData != None and responseData.has_key('matches') and len(responseData['matches']) != 0:
                self.fileNo += 1
                #Check each match received for the response
                for matchNumber in range( len(responseData['matches']) ):   
                    if 'images' in responseData['matches'][matchNumber].keys() and len( responseData['matches'][matchNumber]['images'] ) != 0 :
                            self.obj.check(responseData['matches'][matchNumber], fileAddress)
            
            else :
                self.fileNo += 1
                self.failed += 1 
                self.failedList.append('No matches found for fileAddress:' + fileAddress + ';  Data received:' + str(responseData))  
            #print 'fileNo:', fileNo
                # Output the contents of the match found
                #for item in responseData.keys():
                #    print "len(responseData['matches'] =", len(responseData['matches'])
                #    print "%-20s----%-100s" % (item, responseData[item])
                #    for content in item.keys():
                #        print "%-20s----%-100s" % (content, item[content])
        except Exception as err:
#             print '\tServerResponseError: '+ str(err) + ';  While processing file - ' + fileAddress
            module_logger.exception('\tServerResponseError: '+ str(err) + ';  While processing file - ' + fileAddress)


    def out(self):
#         print '\tmatch failed:' + str(self.failed) + ' out of total files:' + str(self.fileNo)
        module_logger.info('\tFailed:' + str(self.failed) + ' out of total files:' + str(self.fileNo)) 
        failedListString = ''
        for i in self.failedList: failedListString = failedListString + i +'\n\t'
        module_logger.error(failedListString)
Exemplo n.º 2
0
 def __init__(self):
     self.fileNo = 0     #Keep track of total number of files checked
     self.failed = 0     #Keep track of how many files failed and add the path to a list
     self.failedList = []
     self.obj = ItemCheck()