exit(-1) if len(xmlfilemap) == 0: p.input_fw = old_xmlfilemap.output_fw p.output_fw = xmlfilemap.output_fw params.append(p) else: # print "QR codes already extracted from input set: %s"%(xmlfilemap.output_fw) pass xmlfilemap_list.append(xmlfilemap) if len(params) > 0: sys.stdout.write("\nExtracting QR codes from %d input set(s)... "%(len(params))) sys.stdout.flush() multihandler = MultiHandler.Manager(WorkerType.process, Extract.QRExtractor()) multihandler.run(params) print "%f seconds!"%(multihandler.getDuration()) ################################################################################################################# # DECODE QR CODES (sequentially, not multi-threaded) old_xmlfilemap_list = xmlfilemap_list for old_xmlfilemap in old_xmlfilemap_list: curr_decode_count = len(decodeout_fw.getSortedDirContents(True)) if curr_decode_count == target_qr_count: # All QR codes decoded; no need to proceed with further decoding break
def run(self): ############################# for target in self.srcmanager.targetsets: i = target.get(Settings.index_attrib) srcset = "%s%s" % (Settings.matrix_set, i) input_fw = self.srcmanager.output_fw.getExtended("%s" % (srcset)) output_fw = self.output_fw.getExtended("%s/%s" % (Settings.session, srcset)) # FIXME: can't we get the workers to do this? if not output_fw.createDir(): raise OSError("Error: could not create directory: %s" % (output_fw.getPath())) extract_params = Extract.Parameters(Settings.x_tolerance, Settings.y_tolerance, Settings.region_tolerance, Settings.first_dimension) test = Extract.QRExtractor(input_fw, output_fw) extractcount = test.run(extract_params) print "%d QRs extracted" % (extractcount) decode_params = Decode.Parameters( Settings.maxpayloadsize, Settings.minpayloadsize, Settings.minimum_resize_dimension, Settings.maximum_resize_dimension, Settings.resize_increment) test2 = Decode.QRDecoder( output_fw, FilePathWrapper.FilePathWrapper("/tmp/jeremy")) test2.run(decode_params) exit(-1) ############################ # Get merged sessions (if available): xmlmerged = XmlUtils.getOrAddChild(self.xml, Settings.merged_tag) # Get hash over the decode args (the "session" hash): hasher = FileHasher.FileHasher(Settings.hashing_algorithm) Settings.getHash(hasher, Settings.hashlist1, 0) hashval = hasher.getHash() # Get a previous existing session or create a new one. # NOTE: getting a previous existing session is OK, because we might have new source sets with which to attempt decoding. xmlsession = XmlUtils.getOrAddChild(self.xml, Settings.session_tag, {Settings.hash_attrib: hashval}) index = xmlsession.get(Settings.index_attrib) if index is None: index = len(self.xml) - 2 xmlsession.set(Settings.index_attrib, str(index)) else: index = int(index) #print "Found previous session..." s = "" s += "\nPREVIOUS SESSION\n" s += "----------------\n" s += "QR count: %d\n" % (Utils.getQRCount(xmlmerged)) s += "Decoded total: %d\n" % (Utils.getDecodedCount(xmlmerged)) s += "Decoded remaining: %d" % (Utils.getQRCount(xmlmerged) - Utils.getDecodedCount(xmlmerged)) print s i2 = 0 # FIXME: also need a way to get ALL available sets, not just the targets (Settings option) # For each target source set: for target in self.srcmanager.targetsets: i = target.get(Settings.index_attrib) # Have we already attempted to decode this source set? xmlset = xmlsession.find( "%s[@%s='%s']" % (Settings.set_tag, Settings.index_attrib, i)) if xmlset is not None: # Yes. Skip it. i2 += 1 continue else: # No. Schedule it. xmlset = XmlUtils.getOrAddChild(xmlsession, Settings.set_tag, {Settings.index_attrib: i}) srcset = "%s%s" % (Settings.matrix_set, i) input_fw = self.srcmanager.output_fw.getExtended("%s" % (srcset)) output_fw = self.output_fw.getExtended( "%s%s/%s" % (Settings.session, index, srcset)) # FIXME: can't we get the workers to do this? if not output_fw.createDir(): raise OSError("Error: could not create directory: %s" % (output_fw.getPath())) prevDecodeCount = Utils.getDecodedCount(xmlmerged) # Create a setmanager instance: setManager = SetManager(input_fw, output_fw, xmlmerged, xmlset) setManager.run() currDecodeCount = Utils.getDecodedCount(xmlmerged) qrCount = Utils.getQRCount(xmlmerged) s = "" s += "\nPASS %d\n" % (i2 + 1) s += "---------\n" s += "QR count: %d\n" % (qrCount) s += "Decoded now: %d\n" % (currDecodeCount - prevDecodeCount) s += "Decoded total: %d\n" % (currDecodeCount) s += "Decoded remaining: %d" % (qrCount - currDecodeCount) print s i2 += 1