forked from joey-kilgore/PyFarm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPyFarm.py
More file actions
111 lines (87 loc) · 2.39 KB
/
PyFarm.py
File metadata and controls
111 lines (87 loc) · 2.39 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
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
import gspread
import time
from oauth2client.service_account import ServiceAccountCredentials
arg = []
outputs = []
sheet1 = None
sheet2 = None
idnum = 0
sheet = None
client = None
rowCount = None
def runScript(path, args):
# Called by user; starts execution of the script
file_content = readFile(path)
makeConnection()
pushArgs(args)
pushScript(file_content)
#processOutput()
def makeConnection():
# Make the connection to the Google Spreadsheet
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
global client
client = gspread.authorize(creds)
global sheet1
global sheet2
sheet1 = client.open('pyfarm-hh').get_worksheet(0)
sheet2 = client.open('pyfarm-hh').get_worksheet(1)
def input(num):
return arg[num]
def setInput(listArgs):
global arg
arg = listArgs
def output(val):
global outputs
outputs.append(val)
print(val)
def sendOutput(argIndex, numArgs):
makeConnection()
for out in outputs:
sheet1.update_cell(argIndex,numArgs, out)
numArgs += 1
def clearOutput():
global outputs
outputs.clear()
def readFile(path):
# read file and store into a string
py_file = open(path)
scanned_text = py_file.read()
py_file.close()
return scanned_text
def getWorkSheetOne():
# Get the worksheet containing progress, args, and output
global sheet
sheet = client.open('pyfarm-hh').get_worksheet(0)
return sheet
def getWorkSheetTwo():
# Get the worksheet containing script, and machine ids
global sheet
sheet = client.open('pyfarm-hh').get_worksheet(1)
return sheet
def pushScript(file_content):
global sheet
sheet = getWorkSheetTwo()
sheet.update_cell(1, 1, file_content)
def pushArgs(args):
global sheet
sheet = getWorkSheetOne()
i = 1
for argument in args:
j = 2
sheet.update_cell(i, 1, "0")
for val in argument:
sheet.update_cell(i, j, val)
j+=1
i+=1
global rowCount
rowCount = i
def processOutput():
# wait for response
print("Waiting for output...")
while outputs.__len__() != rowCount:
time.sleep(5)
print("Processing output...")
for out in outputs:
print(out)