This repository has been archived by the owner on Nov 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh-graph-plotter-component.html
executable file
·444 lines (344 loc) · 33.1 KB
/
ssh-graph-plotter-component.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>SSH Graph Plotter Component – Livestock3D</title>
<!-- Meta -->
<meta name="description" content="Livestock3D – ">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Social -->
<meta property="article:author" content="Christian Kongsgaard" />
<meta property="article:section" content="posts" />
<meta property="article:published_time" content="2018-03-25" />
<meta property="og:type" content="article"/>
<meta property="og:title" content="SSH Graph Plotter Component"/>
<meta property="og:description" content="Welcome to the third tutorial! This tutorial will demonstrate how to create a SSH connection to a remote calculation machine. The reason behind this, is that if you have very heavy computations, then you should be able to send them to a remote machine, such as a high-end desktop, server …"/>
<meta property="og:site_name" content="Livestock3D" />
<meta property="og:url" content="https://livestock3d.github.io/ssh-graph-plotter-component.html"/>
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="SSH Graph Plotter Component">
<meta name="twitter:description" content="Welcome to the third tutorial! This tutorial will demonstrate how to create a SSH connection to a remote calculation machine. The reason behind this, is that if you have very heavy computations, then you should be able to send them to a remote machine, such as a high-end desktop, server …">
<meta name="twitter:url" content="https://livestock3d.github.io/ssh-graph-plotter-component.html">
<!-- Feed -->
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Open+Sans:regular,bold">
<link rel="stylesheet" type="text/css" href="https://livestock3d.github.io/theme/css/w3.css">
<link rel="stylesheet" type="text/css" href="https://livestock3d.github.io/theme/css/style.css">
<link rel="stylesheet" type="text/css" href="https://livestock3d.github.io/theme/css/jqcloud.css">
<link rel="stylesheet" type="text/css" href="https://livestock3d.github.io/theme/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="https://livestock3d.github.io/theme/css/pygments-highlight-github.css">
<link rel="stylesheet" type="text/css" href="https://livestock3d.github.io/static/custom.css">
<!-- Icon -->
<link rel="shortcut icon" type="image/x-icon" href="https://livestock3d.github.io/favicon.ico">
<!-- JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://livestock3d.github.io/theme/js/jqcloud.min.js"></script>
</head>
<body>
<div class="w3-row w3-card w3-white">
<header id="header">
<a href="https://livestock3d.github.io" id="header-logo" title="Home">CK</a>
<nav id="header-menu">
<ul>
<li><a href="https://livestock3d.github.io/pages/contributing-to-livestock.html">Contributing to Livestock</a></li>
<li><a href="https://livestock3d.github.io/pages/how-is-it-working.html">How is it Working?</a></li>
<li><a href="https://livestock3d.github.io/pages/welcome-to-livestock3d.html">Welcome to Livestock3D</a></li>
<li class="w3-bottombar w3-border-white w3-hover-border-green" style="font-weight: bold;"><a href="https://livestock3d.github.io/category/posts.html">posts</a></li>
</ul>
</nav>
</header>
</div>
<br><br><br>
<article>
<header class="w3-container col-main">
<h1>SSH Graph Plotter Component</h1>
<div class="post-info">
<div class="w3-opacity w3-margin-right w3-margin-bottom" style="flex-grow: 1;">
<span><time datetime="2018-03-25T00:00:00+01:00">sø 25 marts 2018</time> in <a href="https://livestock3d.github.io/category/posts.html" title="All articles in category posts">posts</a></span>
</div>
<div>
<span class="w3-tag w3-light-grey w3-text-green w3-hover-green">
<a href="https://livestock3d.github.io/tag/python.html" title="All articles with Python tag">#python</a>
</span>
<span class="w3-tag w3-light-grey w3-text-green w3-hover-green">
<a href="https://livestock3d.github.io/tag/grasshopper.html" title="All articles with Grasshopper tag">#grasshopper</a>
</span>
<span class="w3-tag w3-light-grey w3-text-green w3-hover-green">
<a href="https://livestock3d.github.io/tag/tutorial.html" title="All articles with Tutorial tag">#tutorial</a>
</span>
<span class="w3-tag w3-light-grey w3-text-green w3-hover-green">
<a href="https://livestock3d.github.io/tag/ssh.html" title="All articles with Ssh tag">#ssh</a>
</span>
</div>
</div>
</header>
<br>
<div class="col-main w3-container">
<section id="content">
<p>Welcome to the third tutorial! This tutorial will demonstrate how to create a SSH connection to a remote calculation machine.
The reason behind this, is that if you have very heavy computations, then you should be able to send them to a remote machine,
such as a high-end desktop, server or cloud service. Currently the Livestock SSH Method only support remote machines with
Linux/Ubuntu as OS. If you do not have remote machine, then do not worry, you can still follow, this tutorial will work with
<a href="https://docs.microsoft.com/en-us/windows/wsl/about">Bash for Windows</a>. We will modify the second
<a href="https://livestock3d.github.io/graph-plotter-component.html">tutorial</a> so it does it processing on the remote machine instead of the local one.</p>
<h2>Installation</h2>
<p>First you need to install Bash, follow this <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">guide</a>.
Configure your SSH connection:</p>
<div class="highlight"><pre><span></span>sudo apt-get remove openssh-server
sudo apt-get install openssh-server
sudo nano /etc/ssh/sshd_config
</pre></div>
<p>Set the following:
- PermitRootLogin no
- Then add a line beneath it that says: AllowUsers USER (or whatever your username is for the linux subsystem)
- PasswordAuthentication yes
- UsePrivilegeSeparation no
- PubkeyAuthentication no
- RSAAuthentication no</p>
<div class="highlight"><pre><span></span>sudo service ssh --full-restart
</pre></div>
<p>In some cases you have to modify Windows Firewall settings and add a new Rule for allowing incoming connections on Port 22.
Connect to your Linux subsystem from Windows using a ssh client like <a href="https://www.putty.org/">PuTTY</a>.
Connect with PuTTY to make sure that the connection works.</p>
<p>We will use <a href="http://www.paramiko.org/">Paramiko</a> to make the SSH connection. So let's go ahead and install it to our Conda
environment. Open the command promt or Anaconda promt:</p>
<div class="highlight"><pre><span></span>activate livestock_env
conda install paramiko
</pre></div>
<h2>Grasshopper Script</h2>
<p>Open "3 - SSH Graph Plotter.gh". In it you will find the Python Executor, the plotter component from before, the image viewer
and a SSH Connection component.
<img alt="alt text" src="https://livestock3d.github.io/images/ssh_1.png">
SSH Connection works similar to Python Executor it that it just collects and holds the information
concerning the SSH connection. You need to give it the IP, port, username and password for the SSH connection to work.
When you have done that, we can modify the plotter component.</p>
<p>We need to write a function, that can configure the files for the SSH connection: write_ssh_file():</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">write_ssh_files</span><span class="p">():</span>
<span class="c1"># Clean SSH folder</span>
<span class="n">livestock3d</span><span class="o">.</span><span class="n">clean_ssh_folder</span><span class="p">()</span>
<span class="c1"># SSH commands</span>
<span class="n">ssh_command</span> <span class="o">=</span> <span class="n">livestock3d</span><span class="o">.</span><span class="n">get_ssh</span><span class="p">()</span>
<span class="n">file_transfer</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'in_data.txt'</span><span class="p">,</span> <span class="s1">'plot_graph_template.py'</span><span class="p">,</span> <span class="s1">'data_file.txt'</span><span class="p">]</span>
<span class="n">ssh_command</span><span class="p">[</span><span class="s1">'file_transfer'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">','</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">file_transfer</span><span class="p">)</span>
<span class="n">ssh_command</span><span class="p">[</span><span class="s1">'file_run'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'plot_graph_template.py'</span>
<span class="n">ssh_command</span><span class="p">[</span><span class="s1">'file_return'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'plot.png'</span>
<span class="n">ssh_command</span><span class="p">[</span><span class="s1">'template'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'plot_graph'</span>
<span class="n">livestock3d</span><span class="o">.</span><span class="n">write_ssh_commands</span><span class="p">(</span><span class="n">ssh_command</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ssh_command</span>
</pre></div>
<p>It first cleans up the ssh folder, to make sure there is not files from a previous run.
Then we collect the information from the SSH Connection component with get_ssh(). file_transfer is the files we want to
transfer to the remote machine. We want to transfer the plot_graph template and the data_file it needs. Besides that we
need to transfer in_data.txt, which is the configuration file for the ssh connection. We add that to the ssh_command variable.
ssh_command needs to know, which file should be run on the remote machine. We specify that in 'file_run'. The files we want
to return is given in 'file_return', this is typically the result files from the template, so in this case: 'plot.png'.
Lastly we set the template we use. Then write_ssh_commands is called. You can delete write_template(), we will not need that
as write_ssh_commands() writes the template for us.</p>
<p>clean_ssh_folder(), get_ssh() and write_ssh_commands() are located in the "ssh.py", which you should have gotten it
with the initial download of Livestock3D. Make sure they are in the McNeel\Rhinoceros\5.0\scripts\livestock3d folder.
We also need to make a slight change to the execution part of the component:</p>
<div class="highlight"><pre><span></span><span class="c1"># Get CPython path from the other component</span>
<span class="n">py</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">sc</span><span class="o">.</span><span class="n">sticky</span><span class="p">[</span><span class="s2">"PythonExe"</span><span class="p">])</span>
<span class="c1"># Make folder</span>
<span class="n">folder</span> <span class="o">=</span> <span class="s1">'C:/livestock3d/ssh'</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">folder</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">folder</span><span class="p">)</span>
<span class="c1"># Specify paths </span>
<span class="n">txt_file</span> <span class="o">=</span> <span class="n">folder</span> <span class="o">+</span> <span class="s1">'/data_file.txt'</span>
<span class="n">template_file</span> <span class="o">=</span> <span class="n">folder</span> <span class="o">+</span> <span class="s1">'/ssh_template.py'</span>
<span class="n">result_file</span> <span class="o">=</span> <span class="n">folder</span> <span class="o">+</span> <span class="s1">'/plot.png'</span>
<span class="c1"># Run functions</span>
<span class="k">if</span> <span class="n">run</span><span class="p">:</span>
<span class="c1">#write_ssh_files()</span>
<span class="c1">#write_file(txt_file, x)</span>
<span class="n">run_template</span><span class="p">(</span><span class="n">py</span><span class="p">,</span> <span class="n">template_file</span><span class="p">)</span>
</pre></div>
<ul>
<li>We change the folder to "C:\livestock3d\ssh"</li>
<li>The template file should now be the ssh_template instead of the plot_graph.</li>
<li>In the run statement we just need:<ul>
<li>write_ssh_files()</li>
<li>write_file()</li>
<li>run_template()</li>
</ul>
</li>
</ul>
<p>The whole script in the component should look something like this:</p>
<div class="highlight"><pre><span></span><span class="n">__author__</span> <span class="o">=</span> <span class="s2">"Christian Kongsgaard"</span>
<span class="n">__license__</span> <span class="o">=</span> <span class="s2">"MIT"</span>
<span class="c1">#------------------------------------------------------------------------------#</span>
<span class="c1"># Imports</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">scriptcontext</span> <span class="kn">as</span> <span class="nn">sc</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">import</span> <span class="nn">livestock3d</span>
<span class="c1">#------------------------------------------------------------------------------#</span>
<span class="c1"># Functions</span>
<span class="k">def</span> <span class="nf">write_file</span><span class="p">(</span><span class="n">file_path</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
<span class="nb">file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">file_path</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">)</span>
<span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">x</span><span class="p">:</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="o">+</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">write_ssh_files</span><span class="p">():</span>
<span class="c1"># Clean SSH folder</span>
<span class="n">livestock3d</span><span class="o">.</span><span class="n">clean_ssh_folder</span><span class="p">()</span>
<span class="c1"># SSH commands</span>
<span class="n">ssh_command</span> <span class="o">=</span> <span class="n">livestock3d</span><span class="o">.</span><span class="n">get_ssh</span><span class="p">()</span>
<span class="n">file_transfer</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'in_data.txt'</span><span class="p">,</span> <span class="s1">'plot_graph_template.py'</span><span class="p">,</span> <span class="s1">'data_file.txt'</span><span class="p">]</span>
<span class="n">ssh_command</span><span class="p">[</span><span class="s1">'file_transfer'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">','</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">file_transfer</span><span class="p">)</span>
<span class="n">ssh_command</span><span class="p">[</span><span class="s1">'file_run'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'plot_graph_template.py'</span>
<span class="n">ssh_command</span><span class="p">[</span><span class="s1">'file_return'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'plot.png'</span>
<span class="n">ssh_command</span><span class="p">[</span><span class="s1">'template'</span><span class="p">]</span> <span class="o">=</span> <span class="s1">'plot_graph'</span>
<span class="n">livestock3d</span><span class="o">.</span><span class="n">write_ssh_commands</span><span class="p">(</span><span class="n">ssh_command</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ssh_command</span>
<span class="k">def</span> <span class="nf">run_template</span><span class="p">(</span><span class="n">py_exe</span><span class="p">,</span> <span class="n">template_to_run</span><span class="p">):</span>
<span class="n">thread</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">([</span><span class="n">py_exe</span><span class="p">,</span> <span class="n">template_to_run</span><span class="p">])</span>
<span class="n">thread</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
<span class="n">thread</span><span class="o">.</span><span class="n">kill</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">load_file</span><span class="p">(</span><span class="nb">file</span><span class="p">):</span>
<span class="nb">file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="nb">file</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">)</span>
<span class="n">lines</span> <span class="o">=</span> <span class="nb">file</span><span class="o">.</span><span class="n">readlines</span><span class="p">()</span>
<span class="nb">file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">return</span> <span class="n">lines</span>
<span class="k">def</span> <span class="nf">print_lines</span><span class="p">(</span><span class="n">lines</span><span class="p">):</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
<span class="c1">#------------------------------------------------------------------------------#</span>
<span class="c1"># Execution</span>
<span class="c1"># Get CPython path from the other component</span>
<span class="n">py</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">sc</span><span class="o">.</span><span class="n">sticky</span><span class="p">[</span><span class="s2">"PythonExe"</span><span class="p">])</span>
<span class="c1"># Make folder</span>
<span class="n">folder</span> <span class="o">=</span> <span class="s1">'C:/livestock3d/ssh'</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">folder</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">folder</span><span class="p">)</span>
<span class="c1"># Specify paths </span>
<span class="n">txt_file</span> <span class="o">=</span> <span class="n">folder</span> <span class="o">+</span> <span class="s1">'/data_file.txt'</span>
<span class="n">template_file</span> <span class="o">=</span> <span class="n">folder</span> <span class="o">+</span> <span class="s1">'/ssh_template.py'</span>
<span class="n">result_file</span> <span class="o">=</span> <span class="n">folder</span> <span class="o">+</span> <span class="s1">'/plot.png'</span>
<span class="c1"># Run functions</span>
<span class="k">if</span> <span class="n">run</span><span class="p">:</span>
<span class="c1">#write_ssh_files()</span>
<span class="c1">#write_file(txt_file, x)</span>
<span class="n">run_template</span><span class="p">(</span><span class="n">py</span><span class="p">,</span> <span class="n">template_file</span><span class="p">)</span>
</pre></div>
<h2>Template</h2>
<p>Let us take a look at the SSH template in McNeel\Rhinoceros\5.0\scripts\livestock3d\templates.py</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">ssh_template</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Writes the ssh template.</span>
<span class="sd"> :param path: Path to write it to.</span>
<span class="sd"> """</span>
<span class="n">file_name</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">'/ssh_template.py'</span>
<span class="nb">file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span> <span class="o">+</span> <span class="n">file_name</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"# Imports</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"import sys</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"sys.path.insert(0, r'C:\livestock3d')</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"import ssh as ssh</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"# Run function</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"ssh.ssh_connection()</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">return</span> <span class="bp">True</span>
</pre></div>
<p>It is similar to the two other templates, in that it imports a module (here ssh) and then calls a single
function: ssh_connection(). ssh_connection() is the function that does all the SSH magic and it is there Paramiko comes into
play. You can go study it, if you want. It is located in "C:\livestock3d\ssh.py". Besides the SSH template, we also need
to modify the plot_graph template. When we are on the remote Ubuntu machine, the livestock3d folder is not located the same
place as on your on Windows one. Therefore we need to place a check to see if we are on Windows or Linux. We does this check
so you can still use the original plot_graph template on your Windows machine. We also need to add two lines after the template is finished.
The two lines creates an empty file called "out.txt". ssh_connection() will first start copying files back to the local machine
when it detects that "out.txt" is created. </p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">plot_graph</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="sd">"""</span>
<span class="sd"> Writes a template.</span>
<span class="sd"> :param path: Path to write it to.</span>
<span class="sd"> :type path: str</span>
<span class="sd"> :return: The file name</span>
<span class="sd"> """</span>
<span class="n">file_name</span> <span class="o">=</span> <span class="sa">r</span><span class="s1">'/plot_graph_template.py'</span>
<span class="nb">file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span> <span class="o">+</span> <span class="n">file_name</span><span class="p">,</span> <span class="s1">'w'</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"# Imports</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"import sys</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"import platform</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"from pathlib import Path</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"system = platform.system()</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"if system == 'Windows':</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">" sys.path.insert(0, r'C:\livestock3d')</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"elif system == 'Linux':</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">" sys.path.insert(0, str(Path.home()) + '/livestock3d' )</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"import livestock3d as ls</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"# Run function</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"ls.plot_graph()</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"# Announce that template finished and create out file</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"print('Finished with template')</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"file = open('out.txt', 'w')</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"file.close()</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">return</span> <span class="n">file_name</span>
</pre></div>
<h2>On the Remote Machine</h2>
<p>So far we have not installed Conda on the remote machine yet. You can do that by, in the terminal, typing in: </p>
<div class="highlight"><pre><span></span>wget -c http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh
</pre></div>
<p>We also need a livestock_env environment. After the installation of Miniconda type in:</p>
<div class="highlight"><pre><span></span>conda create -n livestock_env python=3.6 numpy matplotlib
</pre></div>
<p>We also need to copy the files from "C:\livestock3d". If you are on Bash, you can do that by writing in the terminal:</p>
<div class="highlight"><pre><span></span>cd ~/
cp -r /mnt/c/livestock3d ~/
</pre></div>
<p>Now the files are copied. Go into the livestock3d folder in Bash and check if all the files are there:</p>
<div class="highlight"><pre><span></span>cd livestock3d
dir
</pre></div>
<p>It should return:</p>
<div class="highlight"><pre><span></span>data __init__.py livestock3d.py __pycache__ ssh ssh.py
</pre></div>
<p>You should now be ready to run the component.</p>
<h2>Run Grasshopper</h2>
<p>Remember to restart Rhino if you changed something in McNeel\Rhinoceros\5.0\scripts\livestock3d.
Make sure the Python Executor, SSH Connection is correctly sat up and then you can run the plotter component.</p>
</section>
<br><br><br>
<footer>
<div class="adjust-width">
<div id="author-block" class="w3-light-grey w3-border">
<div id="author-info">
<a href="http://ocni-dtu.github.io"><img style="width: 60px; height: 60px;" src="https://github.com/livestock3d/livestock3d.github.io/blob/master/images/profil.jpg" onerror="this.src='theme/images/avatar.png'" alt="Avatar"></a>
<div style="margin-left: 20px; margin-top: 15px;">
<a href="http://ocni-dtu.github.io"><span id="author-name" class="w3-hover-text-dark-grey">Christian Kongsgaard</span></a>
<p id="author-story">I'm a former Master Student of the Technical University of Denmark (DTU).
I'm developed Livestock for my thesis.</p>
</div>
</div>
</div>
</div>
<br><br><br>
<p style="font-size:10pt; font-style: italic;">Did you like this article? Share it with your friends!</p>
<div id="share" class="share">
<a href="http://www.facebook.com/sharer.php?u=https%3A//livestock3d.github.io/ssh-graph-plotter-component.html&t=Livestock3D%3A%20SSH%20Graph%20Plotter%20Component" target="_blank" class="w3-btn w3-indigo">
<i class="fa fa-facebook"></i> <span>Facebook</span>
</a>
<a href="http://twitter.com/share?url=https%3A//livestock3d.github.io/ssh-graph-plotter-component.html&text=Livestock3D%3A%20SSH%20Graph%20Plotter%20Component" target="_blank" class="w3-btn w3-blue">
<i class="fa fa-twitter"></i> <span>Twitter</span>
</a>
<a href="https://plus.google.com/share?url=https%3A//livestock3d.github.io/ssh-graph-plotter-component.html" onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;" class="w3-btn w3-red">
<i class="fa fa-google-plus"></i> <span>Google</span>
</a>
</div>
<br><br><br>
</footer>
</div>
</article>
<footer id="footer">
<div id="footer-copyright" class="w3-center w3-small w3-text-grey w3-padding-48">
<span>
©
2018 Christian Kongsgaard
</span>
</div>
</footer>
</body>
</html>