-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemote.py
More file actions
65 lines (58 loc) · 2.19 KB
/
Copy pathRemote.py
File metadata and controls
65 lines (58 loc) · 2.19 KB
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
from utils import *
from dataManipulation import *
from os.path import sep
import paramiko
def runRemoteServer(url, uname, passw, trainStack, trainLabels, configToUse, submissionScriptString, folderToUse, pytorchFolder, submissionCommand):
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(url, username=uname, password=passw)
scp = SCPClient(client.get_transport())
scp.put(trainStack, folderToUse + sep + 'trainImages.tif')
scp.put(trainLabels, folderToUse + sep + 'trainLabels.tif')
scp.put(configToUse, folderToUse + sep + 'config.yaml')
with open('submissionScript.sb','w') as outFile:
outFile.write(submissionScriptString)
scp.put(submissionScript, folderToUse + sep + 'submissionScript.sb')
scp.close()
stdin, stdout, stderr = client.exec_command(submissionCommand)
output = stdout.read().decode().strip()
stdin.close()
stdout.close()
stderr.close()
client.close()
return output
def getRemoteFile(url, uname, passw, filenameToGet, filenameToStore):
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(url, username=uname, password=passw)
scp = SCPClient(client.get_transport())
scp.get(filenameToGet, filenameToStore)
scp.close()
client.close()
def checkStatusRemoteServer(url, name, passw, jobOutputFile):
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(url, username=uname, password=passw)
command = 'cat ' + jobOutputFile
stdin, stdout, stderr = client.exec_command(command)
outputLines = stdout.readlines()
stdin.close()
stdout.close()
stderr.close()
fullOutput = ''
for line in outputLines:
fullOutput += line.strip() + '\n'
client.close()
return fullOutput
def getSubmissionScriptAsString(template, memory, time, config, outputDirectory):
file = open(template,'r')
stringTemplate = file.read()
file.close()
stringTemplate.replace('{memory}',memory)
stringTemplate.replace('{time}',time)
stringTemplate.replace('{config}',config)
stringTemplate.replace('{outputFileDir}',outputDirectory)
return stringTemplate