Skip to content

Commit d0bdb97

Browse files
committed
moving on
1 parent cb5cb55 commit d0bdb97

2 files changed

Lines changed: 63 additions & 85 deletions

File tree

‎v5-unity/js/opt-frontend-common.ts‎

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,52 +29,6 @@ require('./lib/jquery.ba-dotimeout.min.js');
2929
// need to directly import the class for type checking to work
3030
import {ExecutionVisualizer, assert, htmlspecialchars} from './pytutor.ts';
3131

32-
// these settings are all customized for my own server setup,
33-
// so you will need to customize for your server:
34-
const serverRoot = (window.location.protocol === 'https:') ?
35-
'https://cokapi.com:8001/' : // my certificate for https is registered via cokapi.com, so use it for now
36-
'http://104.237.139.253:3000/';
37-
38-
export const JS_JSONP_ENDPOINT = serverRoot + 'exec_js_jsonp'; // TODO: get rid of this dependency in opt-live.ts
39-
40-
// note that we use '2' and '3' instead of 'py2' and 'py3' due to legacy reasons
41-
const langSettingToBackendScript = {
42-
// backend scripts to execute (Python 2 and 3 variants, if available)
43-
// make two copies of ../web_exec.py and give them the following names,
44-
// then change the first line (starting with #!) to the proper version
45-
// of the Python interpreter (i.e., Python 2 or Python 3).
46-
// Note that your hosting provider might have stringent rules for what
47-
// kind of scripts are allowed to execute. For instance, my provider
48-
// (Webfaction) seems to let scripts execute only if permissions are
49-
// something like:
50-
// -rwxr-xr-x 1 pgbovine pgbovine 2.5K Jul 5 22:46 web_exec_py2.py*
51-
// (most notably, only the owner of the file should have write
52-
// permissions)
53-
'2': 'web_exec_py2.py',
54-
'3': 'web_exec_py3.py',
55-
56-
// empty dummy scripts just to do logging on Apache server
57-
'js': 'web_exec_js.py',
58-
'ts': 'web_exec_ts.py',
59-
'java': 'web_exec_java.py',
60-
'ruby': 'web_exec_ruby.py',
61-
'c': 'web_exec_c.py',
62-
'cpp': 'web_exec_cpp.py',
63-
};
64-
65-
// see ../../v4-cokapi/cokapi.js for details
66-
const langSettingToJsonpEndpoint = {
67-
'2': null,
68-
'3': null,
69-
'js': serverRoot + 'exec_js_jsonp',
70-
'ts': serverRoot + 'exec_ts_jsonp',
71-
'java': serverRoot + 'exec_java_jsonp',
72-
'ruby': serverRoot + 'exec_ruby_jsonp',
73-
'c': serverRoot + 'exec_c_jsonp',
74-
'cpp': serverRoot + 'exec_cpp_jsonp',
75-
};
76-
77-
7832
// for shared sessions ... put back in later
7933
//var executeCodeSignalFromRemote = false;
8034
//var togetherjsSyncRequested = false;
@@ -107,6 +61,49 @@ export abstract class AbstractBaseFrontend {
10761

10862
num414Tries = 0;
10963

64+
// note that we use '2' and '3' instead of 'py2' and 'py3' due to legacy reasons
65+
langSettingToBackendScript = {
66+
// backend scripts to execute (Python 2 and 3 variants, if available)
67+
// make two copies of ../web_exec.py and give them the following names,
68+
// then change the first line (starting with #!) to the proper version
69+
// of the Python interpreter (i.e., Python 2 or Python 3).
70+
// Note that your hosting provider might have stringent rules for what
71+
// kind of scripts are allowed to execute. For instance, my provider
72+
// (Webfaction) seems to let scripts execute only if permissions are
73+
// something like:
74+
// -rwxr-xr-x 1 pgbovine pgbovine 2.5K Jul 5 22:46 web_exec_py2.py*
75+
// (most notably, only the owner of the file should have write
76+
// permissions)
77+
'2': 'web_exec_py2.py',
78+
'3': 'web_exec_py3.py',
79+
80+
// empty dummy scripts just to do logging on Apache server
81+
'js': 'web_exec_js.py',
82+
'ts': 'web_exec_ts.py',
83+
'java': 'web_exec_java.py',
84+
'ruby': 'web_exec_ruby.py',
85+
'c': 'web_exec_c.py',
86+
'cpp': 'web_exec_cpp.py',
87+
};
88+
89+
// these settings are all customized for my own server setup,
90+
// so you will need to customize for your server:
91+
serverRoot = (window.location.protocol === 'https:') ?
92+
'https://cokapi.com:8001/' : // my certificate for https is registered via cokapi.com, so use it for now
93+
'http://104.237.139.253:3000/';
94+
95+
// see ../../v4-cokapi/cokapi.js for details
96+
langSettingToJsonpEndpoint = {
97+
'2': null,
98+
'3': null,
99+
'js': this.serverRoot + 'exec_js_jsonp',
100+
'ts': this.serverRoot + 'exec_ts_jsonp',
101+
'java': this.serverRoot + 'exec_java_jsonp',
102+
'ruby': this.serverRoot + 'exec_ruby_jsonp',
103+
'c': this.serverRoot + 'exec_c_jsonp',
104+
'cpp': this.serverRoot + 'exec_cpp_jsonp',
105+
};
106+
110107
abstract executeCode(forceStartingInstr?: number, forceRawInputLst?: string[]) : any;
111108
abstract finishSuccessfulExecution() : any; // called by executeCodeAndCreateViz
112109
abstract handleUncaughtException(trace: any[]) : any; // called by executeCodeAndCreateViz
@@ -378,9 +375,9 @@ export abstract class AbstractBaseFrontend {
378375
this.num414Tries = 0;
379376
};
380377

381-
var backendScript = langSettingToBackendScript[pyState];
378+
var backendScript = this.langSettingToBackendScript[pyState];
382379
assert(backendScript);
383-
var jsonp_endpoint = langSettingToJsonpEndpoint[pyState]; // maybe null
380+
var jsonp_endpoint = this.langSettingToJsonpEndpoint[pyState]; // maybe null
384381

385382
if (!backendScript) {
386383
this.setFronendError(

‎v5-unity/js/opt-live.ts‎

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -63,47 +63,28 @@ export class OptLiveFrontend extends AbstractBaseFrontend {
6363
originFrontendJsFile: string = 'opt-live.js';
6464
pyInputAceEditor; // Ace editor object that contains the user's code
6565

66+
prevVisualizer = null; // the visualizer object from the previous execution
67+
aceEditorWidth = '550px';
68+
disableRowScrolling = false; // really hacky global, ugh
69+
hasSyntaxError = false;
70+
71+
// override
72+
langSettingToBackendScript = {
73+
'2': 'LIVE_exec_py2.py',
74+
'3': 'LIVE_exec_py3.py',
75+
// empty dummy scripts just to do logging on Apache server
76+
'js': 'LIVE_exec_js.py',
77+
'ts': 'LIVE_exec_ts.py',
78+
'java': 'LIVE_exec_java.py',
79+
'ruby': 'LIVE_exec_ruby.py',
80+
'c': 'LIVE_exec_c.py',
81+
'cpp': 'LIVE_exec_cpp.py',
82+
};
6683

67-
}
68-
69-
70-
// TODO: refactor me below
71-
72-
// TODO: overriding backend_script from opt-frontend-common.js is also dicey, ergh
73-
// so it currently doesn't work for JavaScript. also it logs the WRONG
74-
// SCRIPT for Python since it uses the script names from
75-
// opt-frontend-common.js
76-
77-
// these scripts override the versions defined in opt-frontend-common.js
78-
79-
// backend scripts to execute (Python 2 and 3 variants, if available)
80-
// make two copies of ../web_exec.py and give them the following names,
81-
// then change the first line (starting with #!) to the proper version
82-
// of the Python interpreter (i.e., Python 2 or Python 3).
83-
// Note that your hosting provider might have stringent rules for what
84-
// kind of scripts are allowed to execute. For instance, my provider
85-
// (Webfaction) seems to let scripts execute only if permissions are
86-
// something like:
87-
// -rwxr-xr-x 1 pgbovine pgbovine 2.5K Jul 5 22:46 web_exec_py2.py*
88-
// (most notably, only the owner of the file should have write
89-
// permissions)
90-
var python2_backend_script = 'LIVE_exec_py2.py';
91-
var python3_backend_script = 'LIVE_exec_py3.py';
92-
93-
// empty dummy just to do logging on the Apache's server
94-
var js_backend_script = 'LIVE_exec_js.py';
95-
var ts_backend_script = 'LIVE_exec_ts.py';
96-
var java_backend_script = 'LIVE_exec_java.py';
97-
var ruby_backend_script = 'LIVE_exec_ruby.py';
98-
var c_backend_script = 'LIVE_exec_c.py';
99-
var cpp_backend_script = 'LIVE_exec_cpp.py';
10084

101-
var prevVisualizer = null; // the visualizer object from the previous execution
85+
}
10286

103-
var aceEditorWidth = '550px';
104-
var disableRowScrolling = false; // really hacky global, ugh
10587

106-
var hasSyntaxError = false;
10788
function toggleSyntaxError(x) {
10889
if (x) {
10990
hasSyntaxError = true;

0 commit comments

Comments
 (0)