def GSserverIsRunning(): try: requests.get('http://localhost:8080') msg('okGS)') except Exception as e: msg('newGS') startGlowScript()
def createTestPy(timestamp=''): msg('creating test.py') with open('test.py', 'w') as f: f.write(f""" import DICT box() print('this is test.py') def f(): print('this is a function') f() print("{timestamp}") """)
def GSserverIsRunning(): try: requests.get('http://localhost:8080') msg('okGS)') return 1 except Exception as e: msg('newGS') startGlowScript() try: requests.get('http://localhost:8080') return 1 except Exception as e: print(e) print('FAILED TO START GLOWSCRIPT SERVER') return 0
def createTestPy(timestamp=''): msg('creating test.py') with open('test.py', 'w') as f: f.write(f""" print(interval) # to prove that imports.js got through box() print('this is test.py') def f(): print('this is a function') f() blurt('this works thanks to imports.js') print("{timestamp}") """)
def vpy_to_html(targetName = 'test.py', headless=True): global B #headless= True msg('(GS:localhost:8080?') if GSserverIsRunning(): msg('OK') msg(f'Chrome') B = BrowserFromService(headless = headless) if headless: print('headless', end='...') msg(f'logging in') login() msg('IN') #targetName='test.py' msg(f'{targetName}-->') goToWorkspace() pasteToBrowser( srcFromFileName( targetName ) ) createHTML(targetName ) if headless: B.quit() else: B.get('http://localhost:8080/#/user/jschull/folder/Public/program/workspace') ActionChains(B).send_keys(Keys.ESCAPE).perform() #get rid of the magic context menu?
def vpy_to_html(targetName='test.py', headless=True, openBrowser=False): global B #headless= True msg('(GS:localhost:8080?') if GSserverIsRunning(): msg('OK') msg(f'Chrome') B = BrowserFromService(headless=headless) if headless: print('headless', end='...') msg(f'logging in') login(B) msg('IN') msg(f'{targetName}-->') goToWorkspace(B) pasteToBrowser(srcFromFileName(targetName), B) #indexHTML = createHTML(targetName, B, importsJS=make_importsJS()) B.get(f'{GSpath}program/workspace') ActionChains(B).send_keys( Keys.ESCAPE).perform() #get rid of the magic context menu? sleep(2) try: errorTB = B.find_elements_by_class_name('error-traceback')[1].text errorMsg = B.find_elements_by_class_name('error-details')[1].text print(f"""GLOWSCRIPT ERROR {errorTB} {errorMsg}""") return 'GLOWSCRIPT ERROR' except: #alerts cause UnexpectedAlertPresentException import sys print(sys.exc_info()[0]) if openBrowser: webServer(targetName) return 'SUCCESS'
def webServer(targetName): from plumbum import local, NOHUP, BG python3 = local['python3'] dirName = targetName.replace('.py', '') python3['-m', 'http.server', '8081'] & NOHUP(stdout='/dev/null') msg('server at 8081')
def vpy_to_html(targetName='test.py', headless=True): global B #headless= True msg('(GS:localhost:8080?') if GSserverIsRunning(): msg('OK') msg(f'Chrome') B = BrowserFromService(headless=headless) if headless: print('headless', end='...') msg(f'logging in') login() msg('IN') #targetName='test.py' msg(f'{targetName}-->') goToWorkspace() pasteToBrowser(srcFromFileName(targetName)) createHTML(targetName) B.get( 'http://localhost:8080/#/user/jschull/folder/Public/program/workspace') ActionChains(B).send_keys( Keys.ESCAPE).perform() #get rid of the magic context menu? sleep(2) try: errorTB = B.find_elements_by_class_name('error-traceback')[1].text errorMsg = B.find_elements_by_class_name('error-details')[1].text print(f"""GLOWSCRIPT ERROR {errorTB} {errorMsg}""") except IndexError: pass