Update error output for python and dotnet scripts, and update makefile to requir…
…e dotnet framework 3.5
Showing
4 changed files
with
149 additions
and
150 deletions
... | @@ -13,7 +13,7 @@ selftest: | ... | @@ -13,7 +13,7 @@ selftest: |
13 | bin/casperjs selftest | 13 | bin/casperjs selftest |
14 | 14 | ||
15 | compile-dotNET: | 15 | compile-dotNET: |
16 | mcs -out:bin/casperjs.exe src/casperjs.cs | 16 | mcs -langversion:3 -out:bin/casperjs.exe src/casperjs.cs |
17 | 17 | ||
18 | selftest-dotNET: | 18 | selftest-dotNET: |
19 | bin/casperjs.exe selftest | 19 | bin/casperjs.exe selftest | ... | ... |
... | @@ -128,5 +128,5 @@ CASPER_COMMAND.extend(CASPER_ARGS) | ... | @@ -128,5 +128,5 @@ CASPER_COMMAND.extend(CASPER_ARGS) |
128 | try: | 128 | try: |
129 | os.execvp(CASPER_COMMAND[0], CASPER_COMMAND) | 129 | os.execvp(CASPER_COMMAND[0], CASPER_COMMAND) |
130 | except OSError as err: | 130 | except OSError as err: |
131 | print('Fatal: %s; did you install phantomjs?' % err) | 131 | print('Fatal: %s; did you install %s?' % (err, ENGINE)) |
132 | sys.exit(1) | 132 | sys.exit(1) | ... | ... |
No preview for this file type
... | @@ -5,171 +5,170 @@ using System.Diagnostics; | ... | @@ -5,171 +5,170 @@ using System.Diagnostics; |
5 | using System.IO; | 5 | using System.IO; |
6 | 6 | ||
7 | interface engine { | 7 | interface engine { |
8 | string env_varname(); | 8 | string env_varname(); |
9 | string default_exec(); | 9 | string default_exec(); |
10 | string[] native_args(); | 10 | string[] native_args(); |
11 | } | 11 | } |
12 | 12 | ||
13 | class phantomjs : engine { | 13 | class phantomjs : engine { |
14 | public string env_varname() { | 14 | public string env_varname() { |
15 | return "PHANTOMJS_EXECUTABLE"; | 15 | return "PHANTOMJS_EXECUTABLE"; |
16 | } | 16 | } |
17 | public string default_exec() { | 17 | public string default_exec() { |
18 | return "phantomjs"; | 18 | return "phantomjs"; |
19 | } | 19 | } |
20 | public string[] native_args() { | 20 | public string[] native_args() { |
21 | return new [] { | 21 | return new [] { |
22 | "cookies-file", | 22 | "cookies-file", |
23 | "config", | 23 | "config", |
24 | "debug", | 24 | "debug", |
25 | "disk-cache", | 25 | "disk-cache", |
26 | "ignore-ssl-errors", | 26 | "ignore-ssl-errors", |
27 | "load-images", | 27 | "load-images", |
28 | "load-plugins", | 28 | "load-plugins", |
29 | "local-storage-path", | 29 | "local-storage-path", |
30 | "local-storage-quota", | 30 | "local-storage-quota", |
31 | "local-to-remote-url-access", | 31 | "local-to-remote-url-access", |
32 | "max-disk-cache-size", | 32 | "max-disk-cache-size", |
33 | "output-encoding", | 33 | "output-encoding", |
34 | "proxy", | 34 | "proxy", |
35 | "proxy-auth", | 35 | "proxy-auth", |
36 | "proxy-type", | 36 | "proxy-type", |
37 | "remote-debugger-port", | 37 | "remote-debugger-port", |
38 | "remote-debugger-autorun", | 38 | "remote-debugger-autorun", |
39 | "script-encoding", | 39 | "script-encoding", |
40 | "ssl-protocol", | 40 | "ssl-protocol", |
41 | "ssl-certificates-path", | 41 | "ssl-certificates-path", |
42 | "web-security", | 42 | "web-security", |
43 | "webdriver", | 43 | "webdriver", |
44 | "webdriver-logfile", | 44 | "webdriver-logfile", |
45 | "webdriver-loglevel", | 45 | "webdriver-loglevel", |
46 | "webdriver-selenium-grid-hub", | 46 | "webdriver-selenium-grid-hub", |
47 | "wd", | 47 | "wd", |
48 | "w", | 48 | "w", |
49 | }; | 49 | }; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | class slimerjs : engine { | 53 | class slimerjs : engine { |
54 | public string env_varname() { | 54 | public string env_varname() { |
55 | return "SLIMERJS_EXECUTABLE"; | 55 | return "SLIMERJS_EXECUTABLE"; |
56 | } | 56 | } |
57 | public string default_exec() { | 57 | public string default_exec() { |
58 | return "slimerjs"; | 58 | return "slimerjs"; |
59 | } | 59 | } |
60 | public string[] native_args() { | 60 | public string[] native_args() { |
61 | return new [] { | 61 | return new [] { |
62 | "P", | 62 | "P", |
63 | "jsconsole", | 63 | "jsconsole", |
64 | "CreateProfile", | 64 | "CreateProfile", |
65 | "profile", | 65 | "profile", |
66 | //phantomjs options | 66 | //phantomjs options |
67 | "cookies-file", | 67 | "cookies-file", |
68 | "config", | 68 | "config", |
69 | "debug", | 69 | "debug", |
70 | "disk-cache", | 70 | "disk-cache", |
71 | "ignore-ssl-errors", | 71 | "ignore-ssl-errors", |
72 | "load-images", | 72 | "load-images", |
73 | "load-plugins", | 73 | "load-plugins", |
74 | "local-storage-path", | 74 | "local-storage-path", |
75 | "local-storage-quota", | 75 | "local-storage-quota", |
76 | "local-to-remote-url-access", | 76 | "local-to-remote-url-access", |
77 | "max-disk-cache-size", | 77 | "max-disk-cache-size", |
78 | "output-encoding", | 78 | "output-encoding", |
79 | "proxy", | 79 | "proxy", |
80 | "proxy-auth", | 80 | "proxy-auth", |
81 | "proxy-type", | 81 | "proxy-type", |
82 | "remote-debugger-port", | 82 | "remote-debugger-port", |
83 | "remote-debugger-autorun", | 83 | "remote-debugger-autorun", |
84 | "script-encoding", | 84 | "script-encoding", |
85 | "ssl-protocol", | 85 | "ssl-protocol", |
86 | "ssl-certificates-path", | 86 | "ssl-certificates-path", |
87 | "web-security", | 87 | "web-security", |
88 | "webdriver", | 88 | "webdriver", |
89 | "webdriver-logfile", | 89 | "webdriver-logfile", |
90 | "webdriver-loglevel", | 90 | "webdriver-loglevel", |
91 | "webdriver-selenium-grid-hub", | 91 | "webdriver-selenium-grid-hub", |
92 | "wd", | 92 | "wd", |
93 | "w", | 93 | "w", |
94 | }; | 94 | }; |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | class casperjs { | 98 | class casperjs { |
99 | static void Main(string[] args) { | 99 | static void Main(string[] args) { |
100 | var SUPPORTED_ENGINES = new Dictionary<string, engine> { | 100 | var SUPPORTED_ENGINES = new Dictionary<string, engine> { |
101 | {"phantomjs", new phantomjs()}, | 101 | {"phantomjs", new phantomjs()}, |
102 | {"slimerjs", new slimerjs()} | 102 | {"slimerjs", new slimerjs()} |
103 | }; | 103 | }; |
104 | 104 | ||
105 | string ENGINE = "phantomjs"; | 105 | string ENGINE = "phantomjs"; |
106 | var ENGINE_ARGS = new List<string>(); | 106 | var ENGINE_ARGS = new List<string>(); |
107 | string[] ENGINE_NATIVE_ARGS = {}; | 107 | string[] ENGINE_NATIVE_ARGS = {}; |
108 | string ENGINE_EXECUTABLE = ""; | 108 | string ENGINE_EXECUTABLE = ""; |
109 | 109 | ||
110 | string EXE_FILE = System.Reflection.Assembly.GetCallingAssembly().Location; | 110 | string EXE_FILE = System.Reflection.Assembly.GetCallingAssembly().Location; |
111 | var CASPER_ARGS = new List<string>(); | 111 | var CASPER_ARGS = new List<string>(); |
112 | string CASPER_PATH = Path.GetFullPath(Path.Combine(Path.Combine(EXE_FILE, ".."), "..")); | 112 | string CASPER_PATH = Path.GetFullPath(Path.Combine(Path.Combine(EXE_FILE, ".."), "..")); |
113 | 113 | ||
114 | foreach(string arg in args) { | 114 | foreach(string arg in args) { |
115 | if(arg.StartsWith("--engine")) { | 115 | if(arg.StartsWith("--engine")) { |
116 | ENGINE = arg.Substring(9); | 116 | ENGINE = arg.Substring(9); |
117 | break; | 117 | break; |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | if(SUPPORTED_ENGINES.ContainsKey(ENGINE)) { | 121 | if(SUPPORTED_ENGINES.ContainsKey(ENGINE)) { |
122 | ENGINE_NATIVE_ARGS = SUPPORTED_ENGINES[ENGINE].native_args(); | 122 | ENGINE_NATIVE_ARGS = SUPPORTED_ENGINES[ENGINE].native_args(); |
123 | ENGINE_EXECUTABLE = Environment.GetEnvironmentVariable(SUPPORTED_ENGINES[ENGINE].env_varname()) | 123 | ENGINE_EXECUTABLE = Environment.GetEnvironmentVariable(SUPPORTED_ENGINES[ENGINE].env_varname()) |
124 | ?? SUPPORTED_ENGINES[ENGINE].default_exec(); | 124 | ?? SUPPORTED_ENGINES[ENGINE].default_exec(); |
125 | } else { | 125 | } else { |
126 | Console.WriteLine("Bad engine name. Only phantomjs and slimerjs are supported"); | 126 | Console.WriteLine("Bad engine name. Only phantomjs and slimerjs are supported"); |
127 | Environment.Exit(1); | 127 | Environment.Exit(1); |
128 | } | 128 | } |
129 | 129 | ||
130 | foreach(string arg in args) { | ||
131 | bool found = false; | ||
132 | foreach(string native in ENGINE_NATIVE_ARGS) { | ||
133 | if(arg.StartsWith("--" + native)) { | ||
134 | ENGINE_ARGS.Add(arg); | ||
135 | found = true; | ||
136 | } | ||
137 | } | ||
130 | 138 | ||
131 | foreach(string arg in args) { | 139 | if(!found) |
132 | bool found = false; | 140 | if(!arg.StartsWith("--engine=")) |
133 | foreach(string native in ENGINE_NATIVE_ARGS) { | 141 | CASPER_ARGS.Add(arg); |
134 | if(arg.StartsWith("--" + native)) { | 142 | } |
135 | ENGINE_ARGS.Add(arg); | ||
136 | found = true; | ||
137 | } | ||
138 | } | ||
139 | 143 | ||
140 | if(!found) | 144 | var ENGINE_EXEC = new List<string>(ENGINE_EXECUTABLE.Split(' ')); |
141 | if(!arg.StartsWith("--engine=")) | 145 | var ENGINE_FILE = ENGINE_EXEC[0]; |
142 | CASPER_ARGS.Add(arg); | 146 | ENGINE_EXEC.RemoveAt(0); |
143 | } | ||
144 | 147 | ||
145 | var ENGINE_EXEC = new List<string>(ENGINE_EXECUTABLE.Split(' ')); | 148 | var CASPER_COMMAND = new List<string>(ENGINE_EXEC); |
146 | var ENGINE_FILE = ENGINE_EXEC[0]; | 149 | CASPER_COMMAND.AddRange(ENGINE_ARGS); |
147 | ENGINE_EXEC.RemoveAt(0); | 150 | CASPER_COMMAND.AddRange(new [] { |
151 | Path.Combine(Path.Combine(CASPER_PATH, "bin"), "bootstrap.js"), | ||
152 | "--casper-path=" + CASPER_PATH, | ||
153 | "--cli" | ||
154 | }); | ||
155 | CASPER_COMMAND.AddRange(CASPER_ARGS); | ||
148 | 156 | ||
149 | var CASPER_COMMAND = new List<string>(ENGINE_EXEC); | 157 | ProcessStartInfo psi = new ProcessStartInfo(); |
150 | CASPER_COMMAND.AddRange(ENGINE_ARGS); | 158 | psi.FileName = ENGINE_FILE; |
151 | CASPER_COMMAND.AddRange(new [] { | 159 | psi.UseShellExecute = false; |
152 | Path.Combine(Path.Combine(CASPER_PATH, "bin"), "bootstrap.js"), | 160 | psi.RedirectStandardOutput = true; |
153 | "--casper-path=" + CASPER_PATH, | 161 | psi.Arguments = String.Join(" ", CASPER_COMMAND.ToArray()); |
154 | "--cli" | ||
155 | }); | ||
156 | CASPER_COMMAND.AddRange(CASPER_ARGS); | ||
157 | 162 | ||
158 | ProcessStartInfo psi = new ProcessStartInfo(); | 163 | try { |
159 | psi.FileName = ENGINE_FILE; | 164 | Process p = Process.Start(psi); |
160 | psi.UseShellExecute = false; | 165 | while (!p.StandardOutput.EndOfStream) { |
161 | psi.RedirectStandardOutput = true; | 166 | string line = p.StandardOutput.ReadLine(); |
162 | psi.Arguments = String.Join(" ", CASPER_COMMAND.ToArray()); | 167 | Console.WriteLine(line); |
163 | 168 | } | |
164 | try { | 169 | } catch(Win32Exception e) { |
165 | Process p = Process.Start(psi); | 170 | Console.WriteLine("Fatal: " + e.Message + "; did you install " + ENGINE + "?"); |
166 | while (!p.StandardOutput.EndOfStream) { | 171 | Environment.Exit(1); |
167 | string line = p.StandardOutput.ReadLine(); | 172 | } |
168 | Console.WriteLine(line); | 173 | } |
169 | } | ||
170 | } catch(Win32Exception e) { | ||
171 | Console.WriteLine(e.Message); | ||
172 | Environment.Exit(1); | ||
173 | } | ||
174 | } | ||
175 | } | 174 | } | ... | ... |
-
Please register or sign in to post a comment