def handleFileUpload(): if 'photo' in request.files: photo = request.files['photo'] global PictureName PictureName = make_unique(photo.filename) if PictureName != ' ': if allow_image(PictureName): deleteAllFile() filename = secure_filename(PictureName) global currentImageName currentImageName = PictureName #the place to store image photo.save(os.path.join('./static/client/img', filename)) text = mainfunction(currentImageName) det2run(filename) runTest() extractImage = Image.open("static/client/img/" + currentImageName) imagedraw = ImageDraw.Draw(extractImage) fontsize = 1 img_fraction = 0.50 title_font = ImageFont.truetype('JPFONT.ttf', fontsize) while title_font.getsize(text)[0] < img_fraction * extractImage.size[0]: # iterate until the text size is just larger than the criteria fontsize += 1 title_font = ImageFont.truetype("JPFONT.ttf", fontsize) fontsize -= 1 title_font = ImageFont.truetype("JPFONT.ttf", fontsize) imagedraw.text((10, 25), text, (252, 190, 17), font=title_font) extractImage.save(os.path.join('./static/client/img', currentImageName)) global full_filename full_filename = os.path.join(app.config['CLIENT_IMAGES'], currentImageName) return redirect(url_for('home'))
def onXvmCommand(self, proxy, id, cmd, *args): try: #debug("id=" + str(id) + " cmd=" + str(cmd) + " args=" + json.dumps(args)) if (cmd not in NO_LOG_COMMANDS): debug("cmd=" + str(cmd) + " args=" + json.dumps(args)) res = None if cmd == COMMAND_LOG: log(*args) elif cmd == COMMAND_PING: #return ping(proxy) elif cmd == COMMAND_GETMODS: #return res = self.getMods() elif cmd == COMMAND_GETSCREENSIZE: #return res = json.dumps(list(GUI.screenResolution())) elif cmd == COMMAND_GETGAMEREGION: #return res = region elif cmd == COMMAND_GETLANGUAGE: #return res = language elif cmd == COMMAND_GETVEHICLEINFODATA: #return res = getVehicleInfoData() elif cmd == COMMAND_GETWN8EXPECTEDDATA: res = getWN8ExpectedData() elif cmd == COMMAND_GETXVMSTATTOKENDATA: res = json.dumps(getXvmStatTokenData()) elif cmd == COMMAND_LOADBATTLESTAT: #return getBattleStat(proxy, args) elif cmd == COMMAND_LOADBATTLERESULTSSTAT: getBattleResultsStat(proxy, args) elif cmd == COMMAND_LOADUSERDATA: getUserData(proxy, args) elif cmd == COMMAND_GETDOSSIER: getDossier(proxy, args) elif cmd == COMMAND_OPEN_URL: if len(args[0]) and args[0].lower().startswith( 'http://www.modxvm.com'): BigWorld.wg_openWebBrowser(args[0]) elif cmd == COMMAND_LOAD_SETTINGS: pass # TODO elif cmd == COMMAND_SAVE_SETTINGS: pass # TODO elif cmd == COMMAND_TEST: runTest(args) else: err("unknown command: " + str(cmd)) proxy.movie.invoke(('xvm.respond', [id, res])) except Exception, ex: err(traceback.format_exc())
def onXvmCommand(self, proxy, id, cmd, *args): try: #debug("id=" + str(id) + " cmd=" + str(cmd) + " args=" + json.dumps(args)) if (cmd not in NO_LOG_COMMANDS): debug("cmd=" + str(cmd) + " args=" + json.dumps(args)) res = None if cmd == COMMAND_LOG: log(*args) elif cmd == COMMAND_PING: #return ping(proxy) elif cmd == COMMAND_GETMODS: #return res = self.getMods() elif cmd == COMMAND_GETSCREENSIZE: #return res = json.dumps(list(GUI.screenResolution())) elif cmd == COMMAND_GETGAMEREGION: #return res = region elif cmd == COMMAND_GETLANGUAGE: #return res = language elif cmd == COMMAND_GETVEHICLEINFODATA: #return res = getVehicleInfoData() elif cmd == COMMAND_LOADBATTLESTAT: #return getBattleStat(proxy, args) elif cmd == COMMAND_LOADBATTLERESULTSSTAT: getBattleResultsStat(proxy, args) elif cmd == COMMAND_LOADUSERDATA: getUserData(proxy, args) elif cmd == COMMAND_GETDOSSIER: getDossier(proxy, args) elif cmd == COMMAND_LOAD_SETTINGS: pass # TODO elif cmd == COMMAND_SAVE_SETTINGS: pass # TODO elif cmd == COMMAND_TEST: runTest(args) else: err("unknown command: " + str(cmd)) proxy.movie.invoke(('xvm.respond', [id, res])) except Exception, ex: err(traceback.format_exc(ex))
def run(): try: module = 'test_%s' % sys.argv[1] except IndexError: print 'Usage: testdriver.py <module>' print print ' <module> is the name of the module you want to test, and assumes' print ' a test module of the name test_<module>.py is available in the' print ' test\lib directory.' sys.exit(1) # Squelch the screen print logs so that we can see the unittest # output more easily. import log def squelch(msg): pass log.setCallback( squelch ) import test results = test.runTest( module ) sys.exit( len(results.errors) )
def run(): try: module = 'test_%s' % sys.argv[1] except IndexError: print 'Usage: testdriver.py <module>' print print ' <module> is the name of the module you want to test, and assumes' print ' a test module of the name test_<module>.py is available in the' print ' test\lib directory.' sys.exit(1) # Squelch the screen print logs so that we can see the unittest # output more easily. import log def squelch(msg): pass log.setCallback(squelch) import test results = test.runTest(module) sys.exit(len(results.errors))
def onXvmCommand(self, proxy, id, cmd, *args): try: #debug("id=" + str(id) + " cmd=" + str(cmd) + " args=" + json.dumps(args)) if (cmd not in NO_LOG_COMMANDS): debug("cmd=" + str(cmd) + " args=" + json.dumps(args)) res = None if cmd == COMMAND_LOG: log(*args) elif cmd == COMMAND_LOAD_FILE: fn = os.path.join(XVM_DIR, args[0]) res = load_file(fn) if os.path.exists(fn) else None elif cmd == COMMAND_SET_CONFIG: log('setConfig') self.config_str = args[0] self.config = json.loads(self.config_str) elif cmd == COMMAND_GET_CONFIG: res = self.config_str elif cmd == COMMAND_PING: #return ping(proxy) elif cmd == COMMAND_GETMODS: #return res = self.getMods() elif cmd == COMMAND_GETSCREENSIZE: #return res = json.dumps(list(GUI.screenResolution())) elif cmd == COMMAND_GETGAMEREGION: #return res = region elif cmd == COMMAND_GETLANGUAGE: #return res = language elif cmd == COMMAND_GETVEHICLEINFODATA: #return res = getVehicleInfoData() elif cmd == COMMAND_GETWN8EXPECTEDDATA: res = getWN8ExpectedData() elif cmd == COMMAND_GETXVMSTATTOKENDATA: res = json.dumps(getXvmStatTokenData()) elif cmd == COMMAND_LOADBATTLESTAT: getBattleStat(proxy, args) elif cmd == COMMAND_LOADBATTLERESULTSSTAT: getBattleResultsStat(proxy, args) elif cmd == COMMAND_LOADUSERDATA: getUserData(proxy, args) elif cmd == COMMAND_GETDOSSIER: getDossier(proxy, args) elif cmd == COMMAND_OPEN_URL: if len(args[0]) and args[0].lower().startswith('http://www.modxvm.com'): utils.openWebBrowser(args[0], False) elif cmd == COMMAND_LOAD_SETTINGS: pass # TODO elif cmd == COMMAND_SAVE_SETTINGS: pass # TODO elif cmd == COMMAND_TEST: runTest(args) else: err("unknown command: " + str(cmd)) proxy.movie.invoke(('xvm.respond', [id, res])) except Exception, ex: err(traceback.format_exc())
def main(): global mainConfig,vit loadConfig() if (platform.system() == "Windows"): # in case we're using... winblows mainConfig['path_separator'] = "\\" saveConfig() while True: drawScreen() ans = raw_input("* Select an option: ") if ans == "": break elif (ans == '1'): print "Refreshing all tables from file..." build.refreshAll(mainConfig['learnFile']) vit = viterbi.viterbi(build.startProbs, build.transProbs, build.obsProbs) print "Refreshing complete" wait() elif (ans == '2'): print "Unpickling tables..." build.unpickleTables() vit = viterbi.viterbi(build.startProbs, build.transProbs, build.obsProbs) print "Unpickling complete." wait() elif (ans == '3'): print "Training text file must be in "+mainConfig['path_separator']+"train directory!" f = raw_input("Select a new training file: ") newPath = "train"+mainConfig['path_separator']+f if (not os.path.isfile(newPath)): print "ERROR: Not a valid file" else: mainConfig['learnFile'] = f saveConfig() print "Updated successfully" wait() elif (ans == '4'): build.printStats() wait() elif (ans == '5'): testLoop() elif (ans == '6'): test.runTest(mainConfig["testFile"],mainConfig["rslts"]) wait() elif (ans == '7'): print "Testing text file must be in "+mainConfig['path_separator']+"test directory!" f = raw_input("Select a new training file: ") newPath = "test"+mainConfig['path_separator']+f if (not os.path.isfile(newPath)): print "ERROR: Not a valid file" else: mainConfig['testFile'] = f saveConfig() print "Updated successfully" wait() elif (ans == '8'): r = raw_input("Select desired number of results (1-14): ") if (r.isdigit() and (int(r) in range(1,15))): mainConfig['rslts'] = int(r) saveConfig() print "Updated successfully" else: print "ERROR: Not a valid option. Enter 1-14 only." wait()