def get(self): firstTimeSwitch = confFile['first_time_run'] #print firstTimeSwitch if (firstTimeSwitch=="YES") : path = "www/firstTime.html" else : if (weioFiles.checkIfFileExists(confFile['user_projects_path'] + confFile['last_opened_project'] + "index.html")): path = "www/userIndex.html" else : path = "www/error404.html" path = "www/userIndex.html" self.render(path, error="")
def sendFileContent(self, rq): print "FILE ASKED", rq data = {} # echo given request data['requested'] = rq['request'] # echo given data data['data'] = rq['data'] path = rq['data'] if (weioFiles.checkIfFileExists(path)): f = {} f['name'] = weioFiles.getFilenameFromPath(path) f['id'] = weioFiles.getStinoFromFile(path) f['type'] = weioFiles.getFileType(path) f['data'] = weioFiles.getRawContentFromFile(path) f['path'] = path data['data'] = f if not (f['type'] is 'other'): if (f['type'] is 'image'): print rq # only images data['requested'] = "getImage" filename = f['name'] tag = { "jpeg": "jpg", "jpg": "jpeg", "png": "png", "tiff": "tif", "tif": "tiff", "bmp": "bmp" } prefix = "" ext = filename.split(".")[1] if (ext in tag): prefix = tag[ext] content = "data:image/" + prefix + ";base64," content += f['data'].encode("base64") f['data'] = content self.broadcast(clients, json.dumps(data)) else: # all regular editable files #print "DATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", data["data"] #s = data["data"] #uCode = urllib2.quote(s["data"].encode("utf8")) #data["data"]["data"] = uCode self.broadcast(clients, json.dumps(data))
def play(self, rq={'request':'play'}): """ This is where all the magic happens. "Play" button will spawn a new subprocess which will execute users program written in the editor. This subprocess will communicate with Tornado wia non-blocking pipes, so that Tornado can simply transfer subprocess's `stdout` and `stderr` to the client via WebSockets. """ # get configuration from file config = weioConfig.getConfiguration() # stop if process is already running self.stop() data = {} lp = config["last_opened_project"] # check if user project exists before launching #if (weioFiles.checkIfFileExists(up+lp+"main.py")): if (weioFiles.checkIfFileExists(lp+"/main.py")): #print("weioMain indipendent process launching...") # Inform client the we run subprocess data['requested'] = rq['request'] data['status'] = "Warming up the engines..." self.send(json.dumps(data)) consoleWelcome = {} consoleWelcome['data'] = "WeIO user program started" consoleWelcome['serverPush'] = "sysConsole" self.lastLaunched = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") consoleWelcome['data'] = 'WeIO user server launched ' + self.lastLaunched if (weioIdeGlobals.CONSOLE != None): #weioIdeGlobals.CONSOLE.send(json.dumps(data)) weioIdeGlobals.CONSOLE.send(json.dumps(consoleWelcome)) self.playing = True # send *start* command to user tornado self.weioPipe.stdin.write("*START*") else : # FILE DON'T EXIST warning = {} warning['requested'] = rq['request'] warning['status'] = "main.py don't exist!" warning['state'] = "error" self.send(json.dumps(warning))
def play(self, rq={'request':'play'}): """ This is where all the magic happens. "Play" button will spawn a new subprocess which will execute users program written in the editor. This subprocess will communicate with Tornado wia non-blocking pipes, so that Tornado can simply transfer subprocess's `stdout` and `stderr` to the client via WebSockets. """ # get configuration from file config = weioConfig.getConfiguration() # stop if process is already running self.stop() data = {} lp = config["last_opened_project"] # check if user project exists before launching #if (weioFiles.checkIfFileExists(up+lp+"main.py")): if (weioFiles.checkIfFileExists(lp+"/main.py")): print("weioMain indipendent process launching...") # Inform client the we run subprocess data['requested'] = rq['request'] data['status'] = "Warming up the engines..." self.send(json.dumps(data)) consoleWelcome = {} consoleWelcome['serverPush'] = "sysConsole" self.lastLaunched = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") consoleWelcome['data'] = 'WeIO user server launched ' + self.lastLaunched if (weioIdeGlobals.CONSOLE != None): weioIdeGlobals.CONSOLE.send(json.dumps(data)) self.playing = True # send *start* command to user tornado self.weioPipe.stdin.write("*START*") #weioIdeGlobals.CONSOLE.send(json.dumps(consoleWelcome)) else : # FILE DON'T EXIST warning = {} warning['requested'] = rq['request'] warning['status'] = "main.py don't exist!" warning['state'] = "error" self.send(json.dumps(warning))
def get(self): firstTimeSwitch = confFile["first_time_run"] # print firstTimeSwitch if firstTimeSwitch == "YES": path = "www/firstTime.html" else: if weioFiles.checkIfFileExists(confFile["last_opened_project"] + "/index.html"): path = "www/userIndex.html" else: path = "www/error404.html" path = "www/userIndex.html" # path = confFile['last_opened_project'] + "index.html" self.render(path, error="")
def sendFileContent(self, rq): print "FILE ASKED", rq data = {} # echo given request data['requested'] = rq['request'] # echo given data data['data'] = rq['data'] path = rq['data'] if (weioFiles.checkIfFileExists(path)): f = {} f['name'] = weioFiles.getFilenameFromPath(path) f['id'] = weioFiles.getStinoFromFile(path) f['type'] = weioFiles.getFileType(path) f['data'] = weioFiles.getRawContentFromFile(path) f['path'] = path data['data'] = f if not(f['type'] is 'other'): if (f['type'] is 'image'): print rq # only images data['requested'] = "getImage" filename = f['name'] tag = {"jpeg":"jpg","jpg":"jpeg", "png":"png", "tiff":"tif", "tif":"tiff", "bmp":"bmp"} prefix = "" ext = filename.split(".")[1] if (ext in tag): prefix = tag[ext] content = "data:image/"+prefix+";base64," content += f['data'].encode("base64") f['data'] = content self.broadcast(clients, json.dumps(data)) else: # all regular editable files #print "DATAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", data["data"] #s = data["data"] #uCode = urllib2.quote(s["data"].encode("utf8")) #data["data"]["data"] = uCode self.broadcast(clients, json.dumps(data))
def get(self): firstTimeSwitch = confFile['first_time_run'] #print firstTimeSwitch if (firstTimeSwitch == "YES"): path = "www/firstTime.html" else: if (weioFiles.checkIfFileExists(confFile['last_opened_project'] + "/index.html")): path = "www/userIndex.html" else: path = "www/error404.html" path = "www/userIndex.html" #path = confFile['last_opened_project'] + "index.html" self.render(path, error="")
def sendFileContent(self, rq): data = {} # echo given request data['requested'] = rq['request'] # echo given data data['data'] = rq['data'] path = rq['data'] if (weioFiles.checkIfFileExists(path)): f = {} f['name'] = weioFiles.getFilenameFromPath(path) f['id'] = weioFiles.getStinoFromFile(path) f['type'] = weioFiles.getFileType(path) f['data'] = weioFiles.getRawContentFromFile(path) f['path'] = path data['data'] = f if not(f['type'] is 'other'): if (f['type'] is 'image'): print rq # only images data['requested'] = "getImage" filename = f['name'] tag = {"jpeg":"jpg","jpg":"jpeg", "png":"png", "tiff":"tif", "tif":"tiff", "bmp":"bmp"} prefix = "" ext = filename.split(".")[1] if (ext in tag): prefix = tag[ext] content = "data:image/"+prefix+";base64," content += f['data'].encode("base64") f['data'] = content self.send(json.dumps(data)) else: # all regular editable files self.send(json.dumps(data))
def launcher(self): #print "======>>> LAUNCHING..." # get configuration from file confFile = weioConfig.getConfiguration() # get location of last opened project lp = confFile["last_opened_project"] # check if main.py exists in current user project if (weioFiles.checkIfFileExists(lp+"/main.py")): # set the location of current project main.py projectModule = lp.replace('/', '.') + ".main" else : # Use the location of default www/defaultMain/main.py projectModule = "www.defaultMain.main" #print "CALL", projectModule # Init GPIO object for uper communication if (weioRunnerGlobals.WEIO_SERIAL_LINKED == False): try : weioIO.gpio = weioGpio.WeioGpio() except: print "LPC coprocessor is not present" weioIO.gpio = None # Import userMain from local module try : self.userMain = __import__(projectModule, fromlist=['']) # Calling user setup() if present if "setup" in vars(self.userMain): self.userMain.setup() except : print "MODULE CAN'T BE LOADED. Maybe you have some errors in modules that you wish to import?" print traceback.format_exc() result = None # Add user events #print "ADDING USER EVENTS" for key in weioUserApi.attach.events: #print weioUserApi.attach.events[key].handler weioParser.addUserEvent(weioUserApi.attach.events[key].event, weioUserApi.attach.events[key].handler) # Launching threads for key in weioUserApi.attach.procs: #print key t = threading.Thread(target=weioUserApi.attach.procs[key].procFnc, args=weioUserApi.attach.procs[key].procArgs) t.daemon = True # Start it t.start() #print "STARTING PROCESS PID", t.pid weioRunnerGlobals.running.value = True while (True): # Get the command from userTornado (blocking) msg = self.qIn.get() #print "*** GOT THE COMMAND: ", msg.req # Execute the command msg.res = None if msg.req in weioParser.weioSpells or msg.req in weioParser.weioUserSpells: if msg.req in weioParser.weioSpells: msg.res = weioParser.weioSpells[msg.req](msg.data) elif msg.req in weioParser.weioUserSpells: msg.res = weioParser.weioUserSpells[msg.req](msg.data) else: msg.res = None # Send back the result self.qOut.put(msg)